Showing posts with label tcp. Show all posts
Showing posts with label tcp. Show all posts

Monday, June 5, 2017

Trying to find what process is using a certain port

If you run into the situation where you quickly want to know which process is using a certain (TCP) port, use the following command:

pi@server:~ $ sudo ss -lptn 'sport = :443'
State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port 
LISTEN     0      128                       *:443                      *:*      users:(("nginx",pid=29909,fd=8),("nginx",pid=29908,fd=8),("nginx",pid=29907,fd=8),("nginx",pid=29906,fd=8),("nginx",pid=29905,fd=8))
LISTEN     0      128                      :::443                     :::*      users:(("nginx",pid=29909,fd=9),("nginx",pid=29908,fd=9),("nginx",pid=29907,fd=9),("nginx",pid=29906,fd=9),("nginx",pid=29905,fd=9))

Thursday, January 12, 2017

Alternative way to be testing command line if port is open or closed

Trying to find out on a Linux server or under Busybox (Synology) if a TCP port is open or closed? Use this handy command:

exec 6<>/dev/tcp/127.0.0.1/443 || echo "Port is not open"
exec 6>&- # close output connection
exec 6<&- # close input connection

6 is used as the file descriptor. 0,1,2 are stdin, stdout, and stderr. 5 is sometimes used by Bash for child processes, so 3,4,6,7,8, and 9 should be safe.

Alternatively, if the port you're probing is serving the HTTP(S) protocol:

exec 6<>/dev/tcp/127.0.0.1/443
echo -e "GET / HTTP/1.0\n" >&6
cat <&6

Alternative ways are listed here.