Today in this post, we will see how to check for open port in Linux using telnet and curl commands.
I. Using Telnet command
Telnet command is very common, and mostly used to quickly check if a port is open or not on a server.
The syntax is also simple, just mention server-name and then port number separated by a space.
[root@ngelinux-prd ~]# telnet ngelinux-pxy 9000 Trying 10.134.208.41... Connected to ngelinux-pxy. Escape character is '^]'. ^] telnet> quit Connection closed. [root@ngelinux-prd ~]#
II. Using Curl command
People are less aware of curl command.
However this is useful many of the times when telnet is not available on the server.
To check 9000 port status on the host ngelinux-pxy.
[root@ngelinux-prd ~]# curl -v ngelinux-pxy:9000 * About to connect() to ngelinux-pxy port 9000 (#0) * Trying 10.134.208.41... * Connected to ngelinux-pxy (10.134.208.41) port 9000 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: ngelinux-pxy:9000 > Accept: */* > * Connection #0 to host ngelinux-pxy left intact ### Similarly lets check 443 port. [root@ngelinux-prd ~]# curl -v ngelinux-pxy:443 * About to connect() to ngelinux-pxy port 443 (#0) * Trying 10.134.208.41... * Connection refused * Failed connect to ngelinux-pxy:443; Connection refused * Closing connection 0 curl: (7) Failed connect to ngelinux-pxy:443; Connection refused [root@ngelinux-prd ~]#
Similar to these we have nc command also to check the port open in linux.
Lets check this command also.
III. Using nc command
### Checking 9000 port [root@ngelinux-prd ~]# nc -zv ngelinux-pxy 9000 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connected to 10.134.208.41:9000. Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds. ### As we can see above 9000 port is listening, ### Lets check 900 port [root@ngelinux-prd ~]# nc -zv ngelinux-pxy 900 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connection refused. [root@ngelinux-prd ~]#
Here the connection is refused on 900 port which means this is not open, and only 9000 port is open or listening on the server.