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.linuxdiyf.com/linux/8851.html
Linux下用netstat命令查看网络负载状况的一条语句:http://www.linuxdiyf.com/linux/6180.html
Linux命令:service & netstat:http://www.linuxdiyf.com/linux/5392.html
使用netstat检测及监测网络连接:http://www.linuxdiyf.com/linux/2527.html
解析Linux中netstat命令的用法:http://www.linuxdiyf.com/linux/418.html