Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux nat/iptables configuration for this setup [closed]

I have an experimental setup, of 4 linux (CentOS) machines:

enter image description here

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??

like image 764
Space Rocker Avatar asked Feb 14 '13 16:02

Space Rocker


People also ask

What does iptables NAT mean?

NAT is the process of forwarding/modifiying IP packets through a router that connects two IP networks and at least one of them is a private network.

What command is used to set up NAT rules on a Linux machine?

Linux and Netfilter We will use the command utility 'iptables' to create complex rules for modification and filtering of packets. The important rules regarding NAT are - not very surprising - found in the 'nat'-table.


1 Answers

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
like image 65
Satish Avatar answered Oct 28 '22 19:10

Satish