Skip to contentSkip to conversation

New netfilter match module

RFC In review Alex Davis 3 participants 5 messages May 31, 2006 – Jun 2, 2006 netfilter

lore
Share & tools
lore

Alex Davis

author
#0 lore raw

cover New netfilter match module

The scenario:

A box is functioning as a NATting firewall with a public and a private network interface, hereafter referred to as pub0 and priv0. Connected to priv0 are several boxes, one of which is a web server. The public IP address is dynamic. Running an internal DNS server is not an option. A dynamic DNS provider is used to keep the public host name of the firewall sync'ed with its public IP address, which is assigned to pub0.

The problem:

There is no reliable way to direct network traffic from the private network hosts for the public IP address of the firewall to the web server, and still have traffic not destined for the public address go to the correct destination. For example, one could create the following rule:

    iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <webserver address>

but this directs _all_ port 80 traffic to the web server. The rule

    iptables -t nat -A PREROUTING -p tcp -d <public address> --dport 80 \
                 -j DNAT --to-destination <webserver address>

works fine, until the public address changes.

The solution:

I have created a match called 'ipisforif' (IP address IS FOR network InterFace), which checks to see if the destination or source IP address of the packet matches the IP address of a network interface.

The syntax is:

ipisforif < --srcip | --dstip > <interface name>

Example:

To always route HTTP traffic from the private network hosts for the public IP address (and _only_ the public IP address) to the web server, use the following rule:

    iptables -t nat -A PREROUTING -i priv0 -p tcp --dport 80 -m ipisforif \
                 --dstip pub0 -j DNAT --to-destination <webserver address>

Two emails containing one patch each will follow.

This code is currently being used on a 2.6.16.17 kernel.

I code, therefore I am

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#1 lore raw

This is generally useful for DHCP setups. A distribution can much easier make a default firewall setup that simply matches input traffic on "ip of interface", so the user does not need to configure it, and it works even with dynamically changing DHCP adresses.

The reverse match ("interface of ip") could also be interesting to detect martian traffic very easily.

I would rename it, fx to "ipof" or "ipat", like:
iptables -m ipat --dst --iface eth0

Separation of --dst and --iface so it can later be extended to match "ip at network" and "ip at vlan".

Simon

Quoted 60 lines · Alex Davis

The scenario:

A box is functioning as a NATting firewall with a public and a private network interface, hereafter referred to as pub0 and priv0. Connected to priv0 are several boxes, one of which is a web server. The public IP address is dynamic. Running an internal DNS server is not an option. A dynamic DNS provider is used to keep the public host name of the firewall sync'ed with its public IP address, which is assigned to pub0.

The problem:

There is no reliable way to direct network traffic from the private network hosts for the public IP address of the firewall to the web server, and still have traffic not destined for the public address go to the correct destination. For example, one could create the following rule:

    iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT

--to-destination <webserver address>

but this directs _all_ port 80 traffic to the web server. The rule

    iptables -t nat -A PREROUTING -p tcp -d <public address> --dport 80 \
                 -j DNAT --to-destination <webserver address>

works fine, until the public address changes.

The solution:

I have created a match called 'ipisforif' (IP address IS FOR network InterFace), which checks to see if the destination or source IP address of the packet matches the IP address of a network interface.

The syntax is:

ipisforif < --srcip | --dstip > <interface name>

Example:

To always route HTTP traffic from the private network hosts for the public IP address (and _only_ the public IP address) to the web server, use the following rule:

    iptables -t nat -A PREROUTING -i priv0 -p tcp --dport 80 -m ipisforif \
                 --dstip pub0 -j DNAT --to-destination <webserver address>

Two emails containing one patch each will follow.

This code is currently being used on a 2.6.16.17 kernel.

I code, therefore I am

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

author
#2 lore raw
Quoted 1 line

This is generally useful for DHCP setups.

Agreed.

Quoted 2 lines

The reverse match ("interface of ip") could also be interesting to detect martian traffic very easily.

What is "martian traffic"?

I code, therefore I am

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#3 lore raw
Quoted 5 lines
Quoted 3 lines

The reverse match ("interface of ip") could also be interesting to detect martian traffic very easily.

What is "martian traffic"?

Traffic coming in on a wrong interface, ie. another interface than the host would route a reply to.

Simon

#4 lore raw
In reply to Alex Davis
Quoted 16 lines · Alex Davis

The scenario:

A box is functioning as a NATting firewall with a public and a private network interface, hereafter referred to as pub0 and priv0. Connected to priv0 are several boxes, one of which is a web server. The public IP address is dynamic. Running an internal DNS server is not an option. A dynamic DNS provider is used to keep the public host name of the firewall sync'ed with its public IP address, which is assigned to pub0.

The problem:

There is no reliable way to direct network traffic from the private network hosts for the public IP address of the firewall to the web server, and still have traffic not destined for the public address go to the correct destination. For example, one could create the following rule:

Quoted 8 lines
    iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <webserver address>

but this directs _all_ port 80 traffic to the web server. The rule

    iptables -t nat -A PREROUTING -p tcp -d <public address> --dport 80 \
                 -j DNAT --to-destination <webserver address>

works fine, until the public address changes.

I think a general solution like this is good.
Specially, however, could you not solve it using ! with a rule like:

iptables -t nat -A PREROUTING -p tcp -s ! 10.18.0.0/24 --dport 80 \
         -j DNAT --to-destination <webserver address>

i.e. for non locally originating traffic to port 80, use the webserver Of course if you had multiple local subnets you might need

iptables -t nat -A PREROUTING -j try_80
iptables -t nat -A try_80 -p tcp -s 10.18.0.0/24 -j RETURN iptables -t nat -A try_80 -p tcp -s 10.18.20.0/24 -j RETURN iptables -t nat -A try_80 -p tcp --dport 80 -j DNAT --to-destination <webserver address>

Sam