To configure Network Address Translation (NAT) on a Linux system, you will need to follow these steps:
/etc/sysctl.conf
file and set the net.ipv4.ip_forward
parameter to 1
. For example:net.ipv4.ip_forward = 1
After you have edited the sysctl.conf
file, you will need to apply the changes by running the following command:
sysctl -p
This will enable packet forwarding on the Linux system.
eth0
that is connected to the internal network, and an interface named eth1
that is connected to the internet, you can use the following iptables commands:# Enable NAT on eth0 iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE # Enable traffic from the internal network to reach the internet iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT # Enable traffic from the internet to reach the internal network iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
These iptables rules will enable NAT on the Linux system, allowing devices on the internal network to access the internet through the Linux system.
iptables-save
command like this:iptables-save > /etc/iptables.rules
This will save the iptables rules to the /etc/iptables.rules
file.
192.168.1.1
, you can set the default gateway on the internal network devices to 192.168.1.1
.