In Linux, we use the iptabes to manage different firewall rules.
1. List all the rules.
- iptables -L
2. Allow incoming tcp port 8888 only from 188.8.131.52.
- iptables -A INPUT -i eth0 -p tcp –dport 8888 -s 184.108.40.206 -j ACCEPT -m comment –comment “001 Testing rule comment”
4. To delete the rule you can use the following command.
- iptables -D INPUT -i eth0 -p tcp –dport 8888 -s 220.127.116.11 -j ACCEPT -m comment –comment “001 Testing rule comment”
5. Alternatively, you can first list the firewall rules in line numbers.
- iptables -L INPUT –line-numbers
6. And then delete a specific rule by providing the line number, in my case which is 11.
- iptables -D INPUT 11
7. Finally, make sure you have save the changes to the server iptables confif file. (Thanks Philip =D)
For Ubuntu Lucid:
- iptables-save > /etc/iptables.firewall.rules
- iptables-save > /etc/sysconfig/iptables
5 thoughts on “Linux – Add and delete firewall rules in iptables”
Remember to run iptable save otherwise all will be gone after reboot!
O yes~ let me update the post~
No problem. This is a critical part in linux admin exam. 😉
haha~ you now look like more a server admin more than a developer~ XD
yes, I’m… I’m script developer at most now…