In debian I use following commands due to distro haven't startup script by default for restoring firewall rules:
iptables-save > /etc/iptables.rules
echo "#\!/bin/sh" >> /etc/network/if-pre-up.d/i
echo "/sbin/iptables-restore /etc/iptables.rules" >> /etc/network/if-pre-up.d/i
chmod a+x /etc/network/if-pre-up.d/i
first line will save your iptables rules to file, other 3 will create starttup script for autorestoring rules on boot.
Main Topics
Browse All Topics





by: koffuPosted on 2009-08-25 at 14:42:48ID: 25182593
first of all you must read iptables tutorial at http://iptables-tutorial.f rozentux.n et/iptable s- tutorial .html .
in base you may setup limited access from incoming side, but full access to outgoing side. You should run this commands from root or via sudo without quotes " " !
first of all allow traffic through loopback:
"iptables -A INCOMING -i lo -j ACCEPT"
allow ip AAA.BBB.CCC.DDD to make connections to your 3306 port (mysql):
"iptables -A INCOMING -s AAA.BBB.CCC.DDD -p tcp --dport 3306 -j ACCEPT"
you must repeat this command for all your trusted IPs.
allow webmin (as I remember it run on 10000 port):
"iptables -A INCOMING -p tcp --dport 10000 -j ACCEPT"
allow incoming DNS traffic from your DNS servers which defined in /etc/resolv.conf after nameserver
"cat /etc/resolv.conf | grep nameserver"
"iptables -A INCOMING -s AAA.BBB.CCC.DDD -p udp --sport 53"
you should run this command for all DNS nameservers in /etc/resolv.conf.
after this make final steps to drop all undefined traffic:
"iptables -P INCOMING DROP"
This settings will kept until reboot. You can view or modify your rules with following commands:
view: iptables -L -n -v --line-numbers
delete one rule: iptables -D INCOMING XX -XX will be rule position with previous command
delete all rules: iptables -F -after this you should add new rules or change default policy to allow traffic (are you not forget we maked this in last? ) with iptables -P INCOMING ACCEPT.
Which linux distro you using? I will help you to save your work through reboots.