25 ago 2011

Configuring iptables to allow access to tcp ports

Configuring iptables to allow access to tcp ports

When Tomcat or WebSphere are installed in a Linux System (like RHEL or Ubuntu) you will find that you cannot access the web applications from a different computer.
Most of the time the "problem" comes from the iptables configuration, as only few ports are opened.

What should I do to allow access to the port "9043" by example

Pre-req:
  • You must be able to edit the iptables configuration.
Steps:

1.
sudo iptables -L
This will show you the list of rules, locate the latest ACCEPT, like
33 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:xxxxx
34 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpts:xxxxx:xxxxxx
35 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpts:xxxxxx:xxxxx

2.
sudo iptables -I INPUT  -p tcp --dport 9043 -j ACCEPT

You will be accepting Input messages for the tcp protocol in the port 9043, the value is going to be the next number after the last ACCEPT that you get, or it can be any other as long as it is not after one like this:

51 DROP all -- 0.0.0.0/0 0.0.0.0/0
in my case
sudo iptables -I INPUT 35 -p tcp --dport 9043 -j ACCEPT
Follow the steps in this page to save the iptables
http://www.cyberciti.biz/faq/how-do-i-save-iptables-rules-or-settings/



References:
https://help.ubuntu.com/community/IptablesHowTo
http://www.cyberciti.biz/faq/how-do-i-save-iptables-rules-or-settings/