LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   NAT with MASQUERADE only for eth2 ? (http://www.linuxquestions.org/questions/linux-networking-3/nat-with-masquerade-only-for-eth2-814340/)

czezz 06-15-2010 03:46 PM

NAT with MASQUERADE only for eth2 ?
 
This is my Linux box with NAT (Slackware 12):

eth0: [public IP]
eth1: 192.168.1.1
eth2: 172.16.1.1

iptables configuration:
Code:

modprobe iptable_nat
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

So, above config refers to both eth1 and eth2.
Is this possible make NAT with MASQUERADE only for eth2 ?

jp413 06-16-2010 11:08 AM

Yeah, specify an input interface (-i) and/or source IP range (-s) in the iptables rule.

e.g.

Code:

iptables -t nat -A POSTROUTING -i eth2 -o eth0 -j MASQUERADE
or
Code:

iptables -t nat -A POSTROUTING -s 172.16.1.1/<netmask> -o eth0 -j MASQUERADE
where <netmask> is the interface's netmask, seeable with
Code:

ip addr show dev eth2


All times are GMT -5. The time now is 04:00 PM.