Test Iptables Script Remotely

Posted on in Categories , , , , , , last updated June 26, 2009

How do I test iptables based script remotely over ssh session? How do I avoid lock outs?

iptables do not have pf like testing option. However, you can use a shell script and cron combo or just use the following syntax:
# /sbin/service iptables restart; sleep 20; /sbin/service iptables stop &
This way you can recover from bad syntax error. If you have your own script:
# /path/to/your.script.sh; sleep 20; /sbin/service iptables stop &
Above will allow you to test changes for a while and then turn off firewall completely. You will be able to login again using ssh after 20 seconds if locked out.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment