Q & A
-
-
0
Nota -
0
Optiuni -
488
Accesari -
- CritiC
How configure NAT in Linux box using IPTABLES?
- 2 years ago
- GNULinux
- 2 years ago
NAT-Network Address Translation is used to communicate from one network to other network with different sub-net.So your Linux box will act as a gateway and will allow to communicate between two different networks.
Hardware Requirements
For setting up NAT in Linux box, it requires two network interface cards,One for private network and one Public IP for external network connection.
Note:All commands must be executed as root
Let’s consider the following IP s for configuring NAT
eth0: 10.0.0.1
eth1: 192.168.180.1
So we need to configure NAT between these two networks
Before proceeding to iptables configurations,we need to enable ipforwarding in Linux Kernel.
# echo 1 > /proc/sys/net/ipv4/ip_forward
This will enable ip forwarding in this particular session.If we reboot the box then the forwarding wont work.So we need to enable forwarding permanently.For that we need to /etc/sysctl.conf file and change value of net.ipv4.ip_forward to 1 from 0.And save.
Now we need to add route for two networks.
#route add -net 192.168.180.0 netmask 255.255.255.0 gw 10.0.0.1
Gateway IP should be the IP of eth0
So we created route between these two networks.
let’s start creating IPTABLES rule.
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE #service iptables save
So that’s it.We configured NAT between these two networks
- Comenteaza
- powered by Verysign