Iptables is the network traffic system offered by Linux, it is a complex system but here we will indicate the basic configuration steps for a workstation, no advanced operation will be performed, only incoming and outgoing traffic will be filtered on the local computer.
This is a basic introduction to iptables from the point of view of a server/workstation.
I delete all entries:
By default, I don’t accept anything:
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
I accept all established and related connections so that services like ftp work correctly:
iptables -A INPUT -m state –state RELATED -j ACCEPT
iptables -A OUTPUT -m state –state ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state –state RELATED -j ACCEPT
iptables -A FORWARD -m state –state ESTABLISHED -j ACCEPT
iptables -A FORWARD -m state –state RELATED -j ACCEPT
I accept anything from loopback:
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A FORWARD -o lo -j ACCEPT
I define the rules:
iptables -A OUTPUT -p tcp –dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 443 -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p tcp –dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 5222 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 1863 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 6667 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 20 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 3389 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 139 -j ACCEPT
iptables -A OUTPUT -p tcp –dport 445 -j ACCEPT
The allowed services are:
- DNS
- HTTP
- HTTPS
- ICMP
- SSH
- GTalk
- AMSN
- IRC
- FTP-DATA
- FTP
- Terminal Server (Windows Remote Desktop)
- Samba
To save the rules, execute the following command:
To restore them:
To delete a rule, use the following command:
To insert rules at a specific position, use the following command:
You can view the entries with the following command:
Save the rules:
Add iptables to the startup:
Remember to load the necessary modules unless everything has been compiled into the kernel itself.