I have an experimental setup, of 4 linux (CentOS) machines:
All 4 machines are internally connected using different networks and can ping eachother directly connected interfaces. However only PC4 has access to internet.
I am trying to setup iptable rules that can allow PC1 to be able to access internet via PC4, but i have no idea how to do this.
I tried to add NAT at outgoing interface on PC2, PC3 and PC4:
iptables -t nat -F POSTROUTING
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
However, this does not work, can you give me some idea how in such a setup i can make PC1 access 10.0.0.1 network??
Enable IP forwarding.
echo 1 > /proc/sys/net/ipv4/ip_forward
Permanent setting edit /etc/sysctl.conf
and set 0
to 1
net.ipv4.ip_forward = 1
To enable the changes made in sysctl.conf you will need to run the command
sysctl -p /etc/sysctl.conf
Iptables Rules for NAT
# /sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# /sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
# /sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT