Tuesday, June 11, 2013

iptables

iptables is a Linux utility for managing firewall rules. Some people will directly edit the iptables file (/etc/sysconfig/iptables in CentOS). This can be a bit dangerous, so it often suggested that the command line version of iptables be used. For example, to open port 8080:

iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

This will open port 8080, but only until the next start of the iptables service or reboot of the server which restarts the service. To manually restart the service:

service iptables restart

Any changes to iptables entries that were not saved or configured by editing the iptables file will be lost at restart. To save the current configuration:

service iptables save

Another useful command is to turn off all of the iptables rules without losing those rules. This can be accomplished by flushing iptables:

iptables -F

This will effectively turn off the firewall until the next restart of iptables. This can be very useful for debugging connectivity issues.