How to check opened ports on Linux?
To check opened ports on Linux, you can run the following command:
netstat -tuplen
Here is an example of the output:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 0 67118001 5658/php-fpm: pool
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 27 22089 1445/mysqld
tcp 0 0 0.0.0.0:3722 0.0.0.0:* LISTEN 0 20390 983/sshd
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 997 20235 982/memcached
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 0 15156 573/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 67154597 2491/nginx: master
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 0 21695 1302/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 0 20366 981/cupsd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 0 67154599 2491/nginx: master
tcp6 0 0 :::3722 :::* LISTEN 0 20399 983/sshd
tcp6 0 0 :::11211 :::* LISTEN 997 20236 982/memcached
tcp6 0 0 :::111 :::* LISTEN 0 15159 573/rpcbind
tcp6 0 0 :::80 :::* LISTEN 0 67154598 2491/nginx: master
tcp6 0 0 ::1:631 :::* LISTEN 0 20365 981/cupsd
udp 0 0 0.0.0.0:11211 0.0.0.0:* 997 20239 982/memcached
udp 0 0 0.0.0.0:52730 0.0.0.0:* 70 15267 568/avahi-daemon: r
udp 0 0 192.168.122.1:53 0.0.0.0:* 0 21694 1302/dnsmasq
udp 0 0 0.0.0.0:67 0.0.0.0:* 0 21691 1302/dnsmasq
udp 0 0 0.0.0.0:68 0.0.0.0:* 0 18123 777/dhclient
In addition, you can run this command to show active internet connections (both servers and established):
netstat -natp
Here’s an example of the output:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 5658/php-fpm: pool
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1445/mysqld
tcp 0 0 0.0.0.0:3722 0.0.0.0:* LISTEN 983/sshd
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 982/memcached
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 573/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2491/nginx: master
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1302/dnsmasq
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 981/cupsd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 2491/nginx: master
tcp 0 0 35.89.147.126:3722 124.201.19.98:56354 ESTABLISHED 25115/sshd: root@pt
tcp 0 0 35.89.147.126:443 124.201.19.98:52026 ESTABLISHED 2492/nginx: worker
tcp 0 0 127.0.0.1:9000 127.0.0.1:37064 TIME_WAIT -
tcp 0 0 127.0.0.1:9000 127.0.0.1:37056 TIME_WAIT -
tcp 0 0 127.0.0.1:9000 127.0.0.1:37058 TIME_WAIT -
tcp 0 36 35.89.147.126:3722 124.201.19.98:52224 ESTABLISHED 28223/sshd: root@pt