Linux Open Port 80 (http) on RHEL/CentOS
Type the following:
# 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 the iptables service using the service command:
# /etc/init.d/iptables restart
See “CentOS / Redhat Iptables Firewall Configuration Tutorial” and “How to save iptables firewall rules permanently on Linux” for more information.
How to open TCP port 80 and 443 using firewalld
Modern version of CentOS/RHEL 7.x/8.x/9.x (now Rocky and Alma Linux) uses the firewalld instead of older iptables config files. So, ppen the terminal and then type the following commands:
$ sudo firewall-cmd --zone=public --add-service=http --permanent
$ sudo firewall-cmd --zone=public --add-service=https --permanent
$ sudo firewall-cmd --reload
Make sure you consult the following tutorials about firewalld:
How to set up a firewall using FirewallD on CentOS 8, RHEL 8, or OpenSUSE/SUSE Linux.
Opening TCP port 80 on Ubuntu or Debian Linux using the ufw
Let us open ports and allow IP address with ufw. The syntax is as follows to open TCP port 80 and 443:
sudo ufw allow 80/tcp comment 'accept HTTP connections'
sudo ufw allow 443/tcp comment 'accept HTTPS connections'
See How To Configure Firewall with UFW on Ubuntu 20.04 LTS for more info.
A note about Alpine Linux for opeing up TCP port 80
You need to create a new policy file called apache.json as follows:
# cat /etc/awall/optional/apache.json
{ "description": "Allow incoming Apache HTTP/HTTPS (TCP/80 and 443) ports", "filter": [ { "in": "internet", "out": "_fw", "service": [ "http", "https"], "action": "accept" } ] }
Then, activate new firewall policy rule:
# awall enable apache
# awall activate
See “How To Set Up a Firewall with Awall on Alpine Linux” for detailed tutorials.
Summing up
You learned about opening up TCP port 80 and 443 using iptables, ufw, firewalld and awall as per your Linux distro version. Please consult the following man pages using the man command:
man iptables man ip6tables man firewall-cmd man awall man ufw