Linux Open Port 80 (HTTP Web Server Port)

I am new CentOS/RHEL 5.x/6.x user. How do I open port 80 (Apache Web Server) under Red Hat / CentOS / Fedora Linux?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 2m
[/donotprint]The default configuration file for iptables based firewall on RHEL / CentOS / Fedora Linux is /etc/sysconfig/iptables for IPv4 based firewall. For IPv6 based firewall you need to edit /etc/sysconfig/ip6tablesfile.

Open this file using a text editor such as vi/vim or emacs:

Linux Open Port 80 (http)

# vi /etc/sysconfig/iptables
Append rule as follows rules on RHEL/CentOS version 5.x or older:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
## Open 443 port i.e. HTTPS
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

IF you are using RHEL/Centoa version 6.x or above, try:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
## Open 443 port i.e. HTTPS
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Save and close the file. Restart iptables service, enter:
# /etc/init.d/iptables restart

See “CentOS / Redhat Iptables Firewall Configuration Tutorial” for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 20 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
20 comments… add one
  • gabriel Jul 18, 2009 @ 18:34

    I tried this and restarted the ipchains with service iptables restart

    but it will still not work.

    any ideas?

  • james stewart Jul 20, 2009 @ 9:10

    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.

  • Lance Olsen Sep 10, 2010 @ 19:01

    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

    • sanjay Feb 17, 2011 @ 6:22

      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

  • milniki za sanitarije Oct 13, 2010 @ 12:58

    Thank you for this one, I really needrf this for my Apache config :)

  • PHP Guru Apr 27, 2011 @ 6:29

    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

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT 
    service iptables save

    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.

  • Soj Aug 26, 2011 @ 3:23

    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

  • Amani Musomba Feb 8, 2012 @ 5:48

    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.

    • Pizzaroo Feb 22, 2012 @ 10:49

      thanks a lot buddy

  • David Kendall Mar 2, 2012 @ 16:08

    Thank you. This worked perfectly for me.

  • Daniel S. Mar 21, 2012 @ 3:10

    Yeah make sure you don’t put that line at the very bottom. Thanks for the great suggestion!

  • Herznad Apr 17, 2012 @ 18:52

    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 ???

  • Herznad Apr 17, 2012 @ 18:53

    I Want to know step by step every words please 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

  • rafael Jul 13, 2012 @ 8:09

    Thank you!
    Don’t forget to save the rules!
    # service iptables save

  • John RK Jul 18, 2012 @ 8:33

    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

  • WallTearer Sep 14, 2012 @ 13:02

    Thanks a lot!
    The following worked for me:
    add line:
    -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
    in the file:
    and then restart iptables by:
    /etc/init.d/iptables restart

  • srihari Oct 31, 2012 @ 3:21

    thank you all. it helped me.

  • Shamsul Haque Feb 19, 2013 @ 17:27

    Thanks a lot buddy. Its really a nice post.

  • Jared Chiddix Feb 15, 2014 @ 11:49

    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

  • dxman Feb 18, 2014 @ 6:19

    m one Hundred Ten % Sure that this website will make me complete System Administrator

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum