netstat命令
netstat命令用來打印Linux中網絡系統的狀態信息,可讓你得知整個Linux系統的網絡情況。
netstat(選項)
-a或--all:顯示所有連線中的Socket;
-A<網絡類型>或--<網絡類型>:列出該網絡類型連線中的相關地址;
-c或--continuous:持續列出網絡狀態;
-C或--cache:顯示路由器配置的快取信息;
-e或--extend:顯示網絡其他相關信息;
-F或--fib:顯示FIB;
-g或--groups:顯示多重廣播功能群組組員名單;
-h或--help:在線幫助;
-i或--interfaces:顯示網絡界面信息表單;
-l或--listening:顯示監控中的服務器的Socket;
-M或--masquerade:顯示偽裝的網絡連線;
-n或--numeric:直接使用ip地址,而不通過域名服務器;
-N或--netlink或--symbolic:顯示網絡硬件外圍設備的符號連接名稱;
-o或--timers:顯示計時器;
-p或--programs:顯示正在使用Socket的程序識別碼和程序名稱;
-r或--route:顯示Routing Table;
-s或--statistice:顯示網絡工作信息統計表;
-t或--tcp:顯示TCP傳輸協議的連線狀況;
-u或--udp:顯示UDP傳輸協議的連線狀況;
-v或--verbose:顯示指令執行過程;
-V或--version:顯示版本信息;
-w或--raw:顯示RAW傳輸協議的連線狀況;
-x或--unix:此參數的效果和指定"-A unix"參數相同;
--ip或--inet:此參數的效果和指定"-A inet"參數相同。
列出所有端口
[root@smsplatform01 ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 localhost:smtp *:* LISTEN
tcp 0 0 *:40904 *:* LISTEN
tcp 0 0 localhost:memcache *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 smsplatform01:ncube-lm *:* LISTEN
tcp 0 0 *:ssh *:*
列出所有已經再監聽端口
[root@smsplatform01 ~]# netstat -al
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 localhost:smtp *:* LISTEN
tcp 0 0 *:40904 *:* LISTEN
tcp 0 0 localhost:memcache *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 smsplatform01:ncube-lm *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
列出所有的tcp端口
[root@smsplatform01 ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 localhost:smtp *:* LISTEN
tcp 0 0 *:40904 *:* LISTEN
tcp 0 0 localhost:memcache *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 smsplatform01:ncube-lm *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 smsplatform01:61004 smsplatform02:ncube-lm ESTABLISHED
tcp 0 0 smsplatform01:61006 smsplatform02:ncube-lm ESTABLISHED
tcp 0 0 smsplatform01:61007 smsplatform02:ncube-lm ESTABLISHED
tcp 0 0 smsplatform01:61005 smsplatform02:ncube-lm ESTABLISHED
tcp 0 0 smsplatform01:ssh 172.20.1.31:13120 ESTABLISHED
tcp 0 0 smsplatform01:ncube-lm smsplatform01:59954 ESTABLISHED
tcp 0 0 smsplatform01:ssh 172.20.1.31:http-wmap ESTABLISHED
tcp 0 0 smsplatform01:59954 smsplatform01:ncube-lm ESTABLISHED
列出所有的udp端口
[root@smsplatform01 ~]# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 *:sunrpc *:*
udp 0 0 *:ipp *:*
udp 0 0 *:rushd *:*
udp 0 0 localhost:745 *:*
udp 0 0 *:17343 *:*
udp 0 0 *:11648 *:*
顯示正在使用Socket的程序識別碼和程序名稱
[root@smsplatform01 ~]# netstat -p
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 smsplatform01:61004 smsplatform02:ncube-lm ESTABLISHED 6569/ora_arc0_oracl
tcp 0 0 smsplatform01:61006 smsplatform02:ncube-lm ESTABLISHED 6577/ora_nsa2_oracl
tcp 0 0 smsplatform01:61007 smsplatform02:ncube-lm ESTABLISHED 6573/ora_arc2_oracl
tcp 0 0 smsplatform01:61005 smsplatform02:ncube-lm ESTABLISHED 6575/ora_arc3_oracl
tcp 0 0 smsplatform01:ssh 172.20.1.31:13120 ESTABLISHED 37508/sshd
tcp 0 0 smsplatform01:ncube-lm smsplatform01:59954 ESTABLISHED 6155/tnslsnr
tcp 0 0 smsplatform01:ssh 172.20.1.31:http-wmap ESTABLISHED 37197/sshd
tcp 0 0 smsplatform01:59954 smsplatform01:ncube-lm ESTABLISHED 6313/ora_pmon_oracl
直接使用ip地址,而不通過域名服務器;
[root@smsplatform01 ~]# netstat -n
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 172.20.1.34:61004 172.20.1.35:1521 ESTABLISHED
tcp 0 0 172.20.1.34:61006 172.20.1.35:1521 ESTABLISHED
tcp 0 0 172.20.1.34:61007 172.20.1.35:1521 ESTABLISHED
tcp 0 0 172.20.1.34:61005 172.20.1.35:1521 ESTABLISHED
tcp 0 224 172.20.1.34:22 172.20.1.31:13120 ESTABLISHED
tcp 0 0 172.20.1.34:1521 172.20.1.34:59954 ESTABLISHED
tcp 0 0 172.20.1.34:22 172.20.1.31:8990 ESTABLISHED
tcp 0 0 172.20.1.34:59954 172.20.1.34:1521 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 18 [ ] DGRAM 20061 /dev/log
unix 2 [ ] DGRAM 17931 @/org/kernel/udev/udevd
unix 2 [ ] DGRAM 20251 @/org/freedesktop/hal/udev_event
unix 3 [ ] STREAM CONNECTED 20465
unix 3 [ ] STREAM CONNECTED 8890 @/tmp/.X11-unix/X0
unix 3 [ ] STREAM CONNECTED 17266
unix 3 [ ] STREAM CONNECTED 11029 /tmp/orbit-gdm/linc-1a88-0-7b17782b4443e
unix 3 [ ] STREAM CONNECTED 20121
unix 3 [ ] STREAM CONNECTED 20455
顯示所有在用端口tcp程序名
[root@smsplatform01 ~]# netstat -antp
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:631 0.0.0.0:* LISTEN 5731/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 5993/master
tcp 0 0 0.0.0.0:40904 0.0.0.0:* LISTEN 5657/rpc.statd
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN 37557/memcached
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 5609/rpcbind
tcp 0 0 172.20.1.34:1521 0.0.0.0:* LISTEN 6155/tnslsnr
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 5881/sshd
tcp 0 0 172.20.1.34:61004 172.20.1.35:1521 ESTABLISHED 6569/ora_arc0_oracl
tcp 0 0 172.20.1.34:61006 172.20.1.35:1521 ESTABLISHED 6577/ora_nsa2_oracl
tcp 0 0 172.20.1.34:61007 172.20.1.35:1521 ESTABLISHED 6573/ora_arc2_oracl
tcp 0 0 172.20.1.34:61005 172.20.1.35:1521 ESTABLISHED 6575/ora_arc3_oracl
tcp 0 672 172.20.1.34:22 172.20.1.31:13120 ESTABLISHED 37508/sshd
tcp 0 0 172.20.1.34:1521 172.20.1.34:59954 ESTABLISHED 6155/tnslsnr
tcp 0 0 172.20.1.34:22 172.20.1.31:8990 ESTABLISHED 37197/sshd
tcp 0 0 172.20.1.34:59954 172.20.1.34:1521 ESTABLISHED 6313/ora_pmon_oracl
tcp 0 0 ::1:631 :::* LISTEN 5731/cupsd
tcp 0 0 :::11614 :::* LISTEN 6347/ora_d000_oracl
tcp 0 0 :::25449 :::* LISTEN 5657/rpc.statd
tcp 0 0 :::111 :::* LISTEN 5609/rpcbind
tcp 0 0 :::22 :::* LISTEN 5881/sshd
總結:用這個命令可以看出那個端口被占用,開啟那些端口很好用命令
Linux netstat命令詳解 http://www.linuxidc.com/Linux/2012-12/75667.htm
使用netstat檢測及監測網絡連接 http://www.linuxidc.com/Linux/2014-09/106497.htm
Netstat 的10個基本用法 http://www.linuxidc.com/Linux/2014-01/94644.htm
Linux netstat命令 http://www.linuxidc.com/Linux/2013-06/85528.htm
Linux命令:service & netstat http://www.linuxidc.com/Linux/2011-12/48395.htm
Linux下用netstat命令查看網絡負載狀況的一條語句 http://www.linuxidc.com/Linux/2011-08/41429.htm
LPI認證考試學習之Linux netstat 命令詳解 http://www.linuxidc.com/Linux/2009-12/23197.htm