OSETC TECH

Linux: How to Test a Specific Port

This post will guide you how to test if a specific port of your Linux server is open or not. How to use the nmap or nc utility to check if remove port is open or not in your remote Linux server.

Text a Specific Port with Telnet/NC/NMAP Tools


You can use the nc or nmap comand to check whether a specific port is open on your remote server. or you can also use the TELNET tool to achieve the result.

For example, you want to check if port 80 is open or not in the remote server osetc.com, you can execute the following command:

# telnet osetc.com 80

or

# nc -vz www.osetc.com 80

Or

#nmap -p 80 osetc.com

Outputs:

[root@osetc_test ~]# telnet osetc.com 80
Trying 149.28.87.206...
Connected to osetc.com.
Escape character is '^]'.

[root@osetc_test ~]# nc -vz www.osetc.com 80
Connection to www.osetc.com 80 port [tcp/http] succeeded!

[root@osetc_test ~]# nmap -p 80 osetc.com

Starting Nmap 5.51 ( http://nmap.org ) at 2018-11-26 07:14 UTC
Nmap scan report for osetc.com (149.28.87.206)
Host is up (0.011s latency).
rDNS record for 149.28.87.206: 149.28.87.206.vultr.com
PORT STATE SERVICE
80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 0.18 seconds

The nmap tool is not installed by default, so you need to install it firstly, just use the yum install command to install it, type:

# yum install nmap -y

Outputs:

[root@osetc_test ~]# yum install nmap
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
epel/metalink | 14 kB 00:00
* base: mirror.keystealth.org
* epel: mirror.sfo12.us.leaseweb.net
* extras: mirror.sfo12.us.leaseweb.net
* updates: mirror.sfo12.us.leaseweb.net
base | 3.7 kB 00:00
epel | 3.2 kB 00:00
epel/primary | 3.2 MB 00:00
epel 12500/12500
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 1.9 MB 00:00
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
--> Running transaction check
---> Package nmap.x86_64 2:5.51-6.el6 will be installed
--> Processing Dependency: libpcap.so.1()(64bit) for package: 2:nmap-5.51-6.el6.x86_64
--> Running transaction check
---> Package libpcap.x86_64 14:1.4.0-4.20130826git2dbcaa1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================
Package Arch Version Repository Size
==========================================================================================================================================================================
Installing:
nmap x86_64 2:5.51-6.el6 base 2.8 M
Installing for dependencies:
libpcap x86_64 14:1.4.0-4.20130826git2dbcaa1.el6 base 131 k

Transaction Summary
==========================================================================================================================================================================
Install 2 Package(s)

Total download size: 2.9 M
Installed size: 10 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64.rpm | 131 kB 00:00
(2/2): nmap-5.51-6.el6.x86_64.rpm | 2.8 MB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.6 MB/s | 2.9 MB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 14:libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64 1/2
Installing : 2:nmap-5.51-6.el6.x86_64 2/2
Verifying : 14:libpcap-1.4.0-4.20130826git2dbcaa1.el6.x86_64 1/2
Verifying : 2:nmap-5.51-6.el6.x86_64 2/2

Installed:
nmap.x86_64 2:5.51-6.el6

Dependency Installed:
libpcap.x86_64 14:1.4.0-4.20130826git2dbcaa1.el6

Complete!

If you want to test whether a port 443 is open or not on remote Linux server osetc.com, you can type the following command:

# telnet osetc.com 443

Outputs:

[root@osetc_test ~]# telnet osetc.com 443
Trying 149.28.87.206...
Connected to osetc.com.
Escape character is '^]'.

Test a Specific Port Using NPING Tool


You can also use another tool called nping to test a specific port of remote server, just type the following command:

#nping --tcmp -p 80 osetc.com

Outputs:

[root@osetc_test ~]# nping --tcp -p 80 osetc.com

Starting Nping 0.5.51 ( http://nmap.org/nping ) at 2018-11-26 07:18 UTC
SENT (0.0126s) TCP 45.77.7.246:40704 > 149.28.87.206:80 S ttl=64 id=63485 iplen=40 seq=4209990603 win=1480
RCVD (0.0213s) TCP 149.28.87.206:80 > 45.77.7.246:40704 SA ttl=51 id=0 iplen=44 seq=1731123884 win=29200 <mss 1460>
SENT (1.0149s) TCP 45.77.7.246:40704 > 149.28.87.206:80 S ttl=64 id=63485 iplen=40 seq=4209990603 win=1480
RCVD (1.0238s) TCP 149.28.87.206:80 > 45.77.7.246:40704 SA ttl=51 id=0 iplen=44 seq=1746784853 win=29200 <mss 1460>
SENT (2.0179s) TCP 45.77.7.246:40704 > 149.28.87.206:80 S ttl=64 id=63485 iplen=40 seq=4209990603 win=1480
RCVD (2.0264s) TCP 149.28.87.206:80 > 45.77.7.246:40704 SA ttl=51 id=0 iplen=44 seq=1762453471 win=29200 <mss 1460>
SENT (3.0205s) TCP 45.77.7.246:40704 > 149.28.87.206:80 S ttl=64 id=63485 iplen=40 seq=4209990603 win=1480
RCVD (3.0291s) TCP 149.28.87.206:80 > 45.77.7.246:40704 SA ttl=51 id=0 iplen=44 seq=1778119341 win=29200 <mss 1460>
SENT (4.0231s) TCP 45.77.7.246:40704 > 149.28.87.206:80 S ttl=64 id=63485 iplen=40 seq=4209990603 win=1480
RCVD (4.0317s) TCP 149.28.87.206:80 > 45.77.7.246:40704 SA ttl=51 id=0 iplen=44 seq=1793786228 win=29200 <mss 1460>

Max rtt: 8.797ms | Min rtt: 8.462ms | Avg rtt: 8.582ms
Raw packets sent: 5 (200B) | Rcvd: 5 (220B) | Lost: 0 (0.00%)
Tx time: 4.01071s | Tx bytes/s: 49.87 | Tx pkts/s: 1.25
Rx time: 5.01331s | Rx bytes/s: 43.88 | Rx pkts/s: 1.00
Nping done: 1 IP address pinged in 5.03 seconds

Note: Nping is an open-source tool for network packet generation, response analysis and response time measurement. Nping allows users to generate network packets of a wide range of protocols, letting them tune virtually any field of the protocol headers. While Nping can be used as a simple ping utility to detect active hosts, it can also be used as a raw packet generator for network stack stress tests, ARP poisoning, Denial of Service attacks, route tracing, and other purposes.