iptables allow port 80 centos 7 – How to open port in iptables firewall

This article will cover detailed steps by step guide on iptables allow port 80 centos 7 / How to open port in iptables firewall

How to check and open PORT in the server?

First, we need to check if the port is open, if the port is not open then we need to open the port. This page will cover the below details:

  • How to check if port 80 is open?
  • How to open a port 80?
  • How to check if a port 80 is open?

Step 1: Log in to Server using the root login creds:

Syntax: ssh root@<ip address>

Example:

$ ssh root@IP Address
root@ipaddress password:

Please provide the root password, cheers you are in

Step 2: Say for example you are trying to open port 80 in a server. We need to check and verify if port 80 is already open in the server.

Use the below command for checking if port 80 is running in the server:

Syntax : iptables -nL | grep <port number>

Example :

[root@server ~]# iptables -nL | grep 80
[root@server ~]#

If the port is not opened then you won’t see any output. in such a case, we need to open the port

Step3: Take a backup of iptables before making any changes in iptables (Good Practice)

[root@server ~]# iptables-save > /root/iptables.txt

The backup of rules will be saved in the file “/root/iptables.txt”

Step 4: Below mentioned is the command to open a port:

Syntax :

iptables -A INPUT -p tcp –dport <port> -j ACCEPT

Example:

[root@server ~]# iptables -A INPUT -p tcp –dport 80 -j ACCEPT
[root@server ~]#

Step 5: Now save the iptables

[root@server ~]# iptables-save

Step 6: Check and verify if the port is open in the server

[root@server ~]# iptables -nL | grep 80
ACCEPT tcp — 0.0.0.0/0 0.0.0.0/0 tcp dpt:80

This shows that the port is opened in the server

Also read : Cloud computing concepts technology & architecture

IMP Note: Once the port is opened please make sure to run the service in the port. If the service is running then only we will be able to telnet to the port.

You can run the below command to check if the service is running on port 80 or not.

Type the following command

# netstat -tulpn | grep :80

Or 

lsof command find out what is using port 80

Type the following command

# lsof -i :80 | grep LISTEN

Sample outputs:

apache2 1607 root 3u IPv4 6472 0t0 TCP *:www (LISTEN)
apache2 1616 www-data 3u IPv4 6472 0t0 TCP *:www (LISTEN)
apache2 1617 www-data 3u IPv4 6472 0t0 TCP *:www (LISTEN)

Leave a Comment