Open TCP Ports and Verify

TCP ports in AlmaLinux/Red Hat 8 can be blocked either using the IPTABLES service or using the firewall service. The following is an example of how to use the IPTABLES service to open a TCP port and then test it using the netcat utility.

  1. Check if a port is blocked. In this example, we can check if port 80 is accepting traffic by entering the iptables command with grep: $ iptables -nL | grep 80

If the iptables command returns no data, the port needs to be opened.

  1. To open TCP Port 80, enter the iptables command as follows: $ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
  2. Re-enter the iptables -nL command to see if the port is now open. $ iptables -nL | grep 80 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
  3. Install the netcat utility. $ yum install nc
  4. Run netcat as a server listing on port 80. $ nc -l -p 80
  5. From another server, install the netcat utility. $ yum install nc
  6. Run netcat to the server you are running iperf3 to verify that port 80 is accepting commands.
Bash
Copy

Open TCP Port Example

Open TCP Port 80:

Bash
Copy

Closed TCP Port Example

Closed TCP Port 80:

Bash
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard