Q. How do I open port 80 (Apache Web Server) under Red Hat / CentOS / Fedora Linux?
A. The default configuration file for iptables based firewall under RHEL / CentOS / Fedora Linux is /etc/sysconfig/iptables. Open this file using a text editor such as vi:
Linux Open Port 80 (http)
# vi /etc/sysconfig/iptables
Append rule as follows:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Save and close the file. Restart iptables:
# /etc/init.d/iptables restart
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop















{ 17 comments… read them below or add one }
I tried this and restarted the ipchains with service iptables restart
but it will still not work.
any ideas?
Thanks for this. Being used to debian/ubuntu I’d forgotten where to go when setting up a CentOS box.
@gabriel – you might want to try moving the rule further up in the file. I put it as the last rule but that didn’t work. Moving it further up (in particular before “-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited”) seemed to do the trick.
This almost worked for me. Using -A was a problem however, because the rule needed to be insterted at the top because of other rules I had in place. If the above doesn’t work for you, use the following at the command line:
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
Firstly Many thank you to you all…
Awesome…and Great community on earth and heartily thank you again for all your time and expertise.
I have used below and it works…
iptables -I RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
Thank you for this one, I really needrf this for my Apache config :)
This is great and worked perfectly! Thank you for posting this. I was wondering if you know the way to do the same thing from the command line (without vi) so that it can be scripted. I found on some other blog
but when I tried that it didn’t work and when I checked /etc/sysconfig/iptables there’s no rule for port 80 like I expected.
I have used the following to open port 80 via iptables:
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED -j ACCEPT –dport 80
I used the below commands to open port 443 via iptables from the command line.
/sbin/iptables -A INPUT -m state –state NEW -p tcp –dport 443 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
and it worked for me.
thanks a lot buddy
Thank you. This worked perfectly for me.
Yeah make sure you don’t put that line at the very bottom. Thanks for the great suggestion!
Hello i connect to my server feddora
1. vi /etc/sysconfig/iptables
2. -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 27015 -j ACCEPT
3. how to close them and how to save also i can’t how to back like cd what happening
i dont know give mee a screen please how to save and exit from log beacuse i dont know how to exit i try everything exit he dosent do close ctrl + c nothing only x logout ???
I Want to know step by step every words please
1.2.3.4.5.6 steps please replay sir soon as you can step by step
first user and pass to connect to my root server second what to do 3th 4th etc… i want to know :S:S:S
Thank you!
Don’t forget to save the rules!
# service iptables save
The following is working fine…execute all 6 command line scripts.
ENV: Red Hat Enterprise Linux Server release 5.3 (Tikanga)
Opening ports 80 & 443
=====================================
1. iptables -A INPUT -p tcp –dport 80 -j ACCEPT
2. iptables -A INPUT -p tcp –dport 443 -j ACCEPT
3. service iptables save
4. /etc/init.d/iptables restart
5. service ip6tables stop
6. chkconfig ip6tables off
Thanks a lot!
The following worked for me:
add line:
-A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
in the file:
/etc/sysconfig/iptables
and then restart iptables by:
/etc/init.d/iptables restart
thank you all. it helped me.