Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.