Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make the following rules in iptables:

  1. Open port 80, 5432 and 22 to all IP addresses

  2. Open port 27017 only to these IP addresses x.x.x.0/24

In all the cases I want both tcp and udp access.

Can you please tell what the config should be in iptables for this setup to work?

share|improve this question
"open port" is not really technically correct. Sometimes it does matter which part (you or the remote host) initiates a connection. This will result in different firewall rules. – vtest Sep 20 '10 at 22:18

Do a quick Google search for an iptables tutorial. On a Fedora system, your firewall rules are kept in /etc/sysconfig/iptables. You might want rules that look similar to:

-A INPUT -i eth0 -p 22 -j ACCEPT
-A INPUT -i eth0 -p 80 -j ACCEPT
-A INPUT -i eth0 -p 5432 -j ACCEPT
-A INPUT -i eth0 -p 27017 -s x.x.x.0/24 -j ACCEPT

Although, I would not recommend opening ports 22 and 5432 to the world. The SSH connections should be locked down to as few sources as possible, and even then you might want to consider additional restrictions. The database connections should be restricted to the web server and those machines that you use to manage the database.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .