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.
- 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.
- To open TCP Port 80, enter the iptables command as follows:
$ iptables -I INPUT -p tcp --dport 80 -j ACCEPT
- 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
- Install the netcat utility.
$ yum install nc
- Run netcat as a server listing on port 80.
$ nc -l -p 80
- From another server, install the netcat utility.
$ yum install nc
- Run netcat to the server you are running iperf3 to verify that port 80 is accepting commands.
$ nc -z -v 192.168.16.7 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.16.7:80.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
nc
Open TCP Port Example
Open TCP Port 80:
# nc -z -v 192.168.40.41 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.40.41:80.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.
Closed TCP Port Example
Closed TCP Port 80:
# nc -z -v 192.168.40.31 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connection refused.
Was this page helpful?