Iptables is THE firewall for Linux.Its pretty strong and once you get a hang of how to use it, it can be very powerful.The number of commands to configure linux iptables are huge.There are plenty of them to configure every single detail.So it would be difficult to cover all the commands.But here are a few basic commands which can help you configure iptables

Step 1 : Firstly, go to the terminal(Applications->Accessories->Terminal) and type sudo -i and enter the sudo password
Step 2 : Now you are ready to enter the iptables commands according to your need

Some common iptables commands

1) iptables -A INPUT -p tcp --dport 21 -j REJECT

This command blocks input traffic from port 21 .

2) iptables -A OUTPUT -p tcp --dport 21 -j REJECT

This command blocks output traffic from port 21 .

3) iptables -D OUTPUT -p tcp --dport 21 -j REJECT

This command deletes the entry from the tables.Note the -D

4) iptables -A INPUT -p tcp --dport 21 -j ACCEPT

This command allows input traffic from port 21 .

5) iptables -A INPUT -p tcp -s 192.168.0.0/15 --dport 21 -j ACCEPT

This command allows input traffic from port 21 only by pc's having ipaddress between 192.168.0.0 - 192.168.0.15

NOTE:In the above commands i think its understood that you could change ACCEPT with REJECT and INPUT with OUTPUT based on what you like.You could also replace 21 with any other port you want.

Hope this gives you a basic idea on how to configure iptables in Linux.I love doing this via the command line, its fun!!!

0 comments

Post a Comment