How to Open ports in iptables firewall

FREQUENTLY ASKED QUESTIONS (Firewall/iptables)
Q: How to open a port in Firewall or iptables in Linux ?

The default iptables rules in a freshly installed linux OS (Fedora, Redhat, CentOS, etc) will allow only incomming SSH (Secure Shell) connections on port 22 TCP. And not allowing any FORWARD connections and allowing all OUTPUT connections. Check the below iptables example screenshot of a freshly installed Linux(CentOS 6)


[root@server ~]# cat /etc/sysconfig/iptables
Click on image to enlarge

To open port 80 TCP in linux iptables 

After installing a web server in linux using Apache, you need to open port 80/TCP to listening to web requests. Run the commands below as root user. 
[root@server ~]# iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT


[root@server ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]


[root@server ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

Check the screenshot below: Here the port 80 TCP is opened in server and listen to all requests from all clients.
[root@server ~]# cat /etc/sysconfig/iptables
Click on image to enlarge 
Check Related Posts:

Was this helpfull ?

0 comments:

Related Posts Plugin for WordPress, Blogger...

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons