# netstat -a | more Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 00 localhost:30037 *:* LISTEN udp 00 *:bootpc *:* Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 6135 /tmp/.X11-unix/X0 unix 2 [ ACC ] STREAM LISTENING 5140 /var/run/acpid.socket
列出所有 tcp 端口 netstat -at
# netstat -at Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 00 localhost:30037 *:* LISTEN tcp 00 localhost:ipp *:* LISTEN tcp 00 *:smtp *:* LISTEN tcp6 00 localhost:ipp [::]:* LISTEN
列出所有 udp 端口 netstat -au
# netstat -au Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 00 *:bootpc *:* udp 00 *:49119 *:* udp 00 *:mdns *:*
2. 列出所有处于监听状态的 Sockets
只显示监听端口 netstat -l
# netstat -l Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 00 localhost:ipp *:* LISTEN tcp6 00 localhost:ipp [::]:* LISTEN udp 00 *:49119 *:*
只列出所有监听 tcp 端口 netstat -lt
# netstat -lt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 00 localhost:30037 *:* LISTEN tcp 00 *:smtp *:* LISTEN tcp6 00 localhost:ipp [::]:* LISTEN
只列出所有监听 udp 端口 netstat -lu
# netstat -lu Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State udp 00 *:49119 *:* udp 00 *:mdns *:*
# netstat -pt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 10 ramesh-laptop.loc:47212192.168.185.75:www CLOSE_WAIT 2109/firefox tcp 00 ramesh-laptop.loc:52750 lax:www ESTABLISHED 2109/firefox
5. 在 netstat 输出中不显示主机,端口和用户名 (host, port or user)
当你不想让主机,端口和用户名显示,使用 netstat -n。将会使用数字代替那些名称。
同样可以加速输出,因为不用进行比对查询。
# netstat -an
如果只是不想让这三个名称中的一个被显示,使用以下命令
# netsat -a --numeric-ports# netsat -a --numeric-hosts# netsat -a --numeric-users
6. 持续输出 netstat 信息
netstat 将每隔一秒输出网络信息。
# netstat -c Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 00 ramesh-laptop.loc:36130101-101-181-225.ama:www ESTABLISHED tcp 11 ramesh-laptop.loc:52564101.11.169.230:www CLOSING tcp 00 ramesh-laptop.loc:43758 server-101-101-43-2:www ESTABLISHED tcp 1 1 ramesh-laptop.loc:42367 101.101.34.101:www CLOSING ^C
7. 显示系统不支持的地址族 (Address Families)
netstat --verbose
在输出的末尾,会有如下的信息
netstat: no support for `AF IPX' on this system.netstat: no support for `AF AX25' on this system.netstat: no support for `AF X25' on this system.netstat: no support for `AF NETROM' on this system.
8. 显示核心路由信息 netstat -r
# netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 * 255.255.255.0 U 00 0 eth2 link-local * 255.255.0.0 U 00 0 eth2 default 192.168.1.1 0.0.0.0 UG 000 eth2