Iptables

Iptables is a very handy program to arrange the incoming and outgoing traffic in a linux computer system. The advantages are wide. To allow some program/port, or block the connection from client in server environment. Or just block any incoming traffic in your computer.

Examples :

Sharing internet connection between nic

Let’s say nic 1 is eth0 which is connected to the router/ internet/ modem. Nic 2 is connected to the switch which is set as a router for the internal network. So the pc/ computer act as a router server.

Nic 1 is 192.168.1.1 connected to modem 192.168.1.2.
Nic 2 is 192.168.0.1 act as a dhcp server to local lan.

Then the iptables will be :

iptables -A FORWARD -i nic2 -o nic1 -j ACCEPT
iptables -A FORWARD -i nic1 -o nic2 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o nic1 -j MASQUERADE

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.