ubuntu 查看进程,查看服务
jiqing@Ubuntu:~$ sudo netstat -anpl | grep :3306
tcp6 0 0 :::3306 :::* LISTEN 1532/mysqld
jiqing@Ubuntu:~$ sudo netstat -anpl | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2994/nginx: master
jiqing@Ubuntu:~$ ps -ef | grep nginx
root 2994 1833 0 11:28 ? 00:00:00 nginx: master process nginx
www 2995 2994 0 11:28 ? 00:00:00 nginx: worker process
www 2996 2994 0 11:28 ? 00:00:00 nginx: worker process
www 2997 2994 0 11:28 ? 00:00:00 nginx: worker process
www 2998 2994 0 11:28 ? 00:00:00 nginx: worker process
jiqing 3049 2515 0 11:31 pts/11 00:00:00 grep --color=auto nginx
jiqing@Ubuntu:~$ ps -ef | grep mysql
root 1016 1 0 11:25 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var --pid-file=/usr/local/mysql/var/Ubuntu.pid
mysql 1532 1016 0 11:25 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/var/Ubuntu.err --open-files-limit=65535 --pid-file=/usr/local/mysql/var/Ubuntu.pid --socket=/tmp/mysql.sock --port=3306
jiqing 3051 2515 0 11:31 pts/11 00:00:00 grep --color=auto mysql
列出所有的tcp端口
# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 22473/redis-server
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4293/nginx: master
tcp 0 0 0.0.0.0:8211 0.0.0.0:* LISTEN 4293/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1164/sshd
tcp 0 0 127.0.0.1:8383 0.0.0.0:* LISTEN 23301/xs-indexd: se
tcp 0 0 127.0.0.1:8384 0.0.0.0:* LISTEN 23305/xs-searchd: m
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 8064/mysqld
列出所有的udp端口
# netstat -nulp
激活Internet连接 (仅服务器)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 52224 0 0.0.0.0:68 0.0.0.0:* 2563/dhclient
udp 0 0 0.0.0.0:631 0.0.0.0:* 1238/cups-browsed
udp 0 0 0.0.0.0:58025 0.0.0.0:* 1064/avahi-daemon:
udp 0 0 127.0.0.1:1080 0.0.0.0:* 1739/python
udp 28736 0 0.0.0.0:5353 0.0.0.0:* 6921/nw
udp 9280 0 0.0.0.0:5353 0.0.0.0:* 4243/chrome
udp 31872 0 0.0.0.0:5353 0.0.0.0:* 1064/avahi-daemon:
udp6 0 0 :::35139 :::* 1064/avahi-daemon:
udp6 14656 0 :::5353 :::* 6921/nw
udp6 20672 0 :::5353 :::* 4243/chrome
udp6 20672 0 :::5353 :::* 1064/avahi-daemon:
查看外部的tcp
# netstat -ntlpa
激活Internet连接 (服务器和已建立连接的)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:22624 0.0.0.0:* LISTEN 7042/exe
tcp 0 0 127.0.0.1:36395 0.0.0.0:* LISTEN 7042/exe
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1183/redis-server 1
tcp 0 0 127.0.0.1:25613 0.0.0.0:* LISTEN 6999/exe
tcp 0 0 127.0.0.1:63342 0.0.0.0:* LISTEN 26309/java
tcp 0 0 127.0.0.1:19471 0.0.0.0:* LISTEN 6999/exe
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1519/nginx.conf
tcp 0 0 0.0.0.0:8211 0.0.0.0:* LISTEN 1519/nginx.conf
tcp 0 0 0.0.0.0:8212 0.0.0.0:* LISTEN 1519/nginx.conf
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 11230/cupsd
tcp 0 0 127.0.0.1:1080 0.0.0.0:* LISTEN 1739/python
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1519/nginx.conf
tcp 0 0 127.0.0.1:6942 0.0.0.0:* LISTEN 26309/java
tcp 0 0 127.0.0.1:40104 127.0.0.1:6379 TIME_WAIT -
tcp 0 0 192.168.1.128:42862 101.132.169.194:22 ESTABLISHED 15204/ssh
tcp 0 0 192.168.1.128:53712 47.75.180.205:2000 ESTABLISHED 4243/chrome
tcp 0 0 127.0.0.1:34122 127.0.0.1:26483 ESTABLISHED 6921/nw
tcp 0 0 127.0.0.1:47234 127.0.0.1:3306 TIME_WAIT -
tcp 0 0 127.0.0.1:40106 127.0.0.1:6379 TIME_WAIT -
tcp 0 0 192.168.1.128:46428 101.226.76.164:443 ESTABLISHED 4243/chrome
tcp 0 0 192.168.1.128:44532 59.111.160.197:80 ESTABLISHED 1317/netease-cloud-
tcp 0 0 127.0.0.1:47238 127.0.0.1:3306 TIME_WAIT -
tcp 0 0 127.0.0.1:36214 127.0.0.1:80 ESTABLISHED 4243/chrome
tcp 0 0 192.168.1.128:60894 223.252.199.69:6003 ESTABLISHED 1317/netease-cloud-
tcp 0 0 127.0.0.1:47144 127.0.0.1:3306 TIME_WAIT -
tcp 0 0 127.0.0.1:55902 127.0.0.1:6379 ESTABLISHED 24062/rdm
tcp 0 0 127.0.0.1:47230 127.0.0.1:3306 TIME_WAIT -
tcp 0 0 192.168.1.128:47122 101.132.169.194:22 ESTABLISHED 16503/ssh
tcp 0 0 192.168.1.128:58480 54.86.169.116:443 ESTABLISHED 27254/Postman
tcp 0 0 127.0.0.1:6379 127.0.0.1:55902 ESTABLISHED 1183/redis-server 1
tcp 0 0 127.0.0.1:40122 127.0.0.1:6379 TIME_WAIT -
tcp 0 0 192.168.1.128:52482 38.143.1.170:2020 ESTABLISHED 4243/chrome
tcp 0 0 127.0.0.1:47232 127.0.0.1:3306 TIME_WAIT -
tcp 0 0 127.0.0.1:80 127.0.0.1:36214 ESTABLISHED 29553/nginx: worker
tcp 0 0 127.0.0.1:47222 127.0.0.1:3306 TIME_WAIT -
tcp 0 0 127.0.0.1:35508 127.0.0.1:26483 ESTABLISHED 6921/nw
tcp 1 0 192.168.1.128:35168 106.15.95.197:80 CLOSE_WAIT 4243/chrome
tcp6 0 0 :::3306 :::* LISTEN 2353/mysqld
tcp6 0 0 :::26483 :::* LISTEN 7042/exe
tcp6 0 0 :::54484 :::* LISTEN 6999/exe
tcp6 0 0 :::21 :::* LISTEN 1560/vsftpd
tcp6 0 0 ::1:631 :::* LISTEN 11230/cupsd
tcp6 0 0 127.0.0.1:26483 127.0.0.1:34122 ESTABLISHED 7042/exe
tcp6 0 0 127.0.0.1:3306 127.0.0.1:47228 TIME_WAIT -
tcp6 0 0 127.0.0.1:3306 127.0.0.1:47224 TIME_WAIT -
tcp6 0 0 127.0.0.1:3306 127.0.0.1:47226 TIME_WAIT -
tcp6 0 0 127.0.0.1:26483 127.0.0.1:35508 ESTABLISHED 7042/exe