netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息
输出结果可以分为两个部分,一个是Active Internet connections,另一个是Active UNIX domain sockets.
[root@DBSVR02 conf]# netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 168.168.80.9:ssh 168.168.80.1:22332 ESTABLISHED
tcp 0 0 168.168.80.9:ssh 168.168.80.1:22864 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 12 [ ] DGRAM 11595 /dev/log
unix 2 [ ] DGRAM 8807 @/org/kernel/udev/udevd
unix 2 [ ] DGRAM 12403 @/org/freedesktop/hal/udev_event
unix 3 [ ] STREAM CONNECTED 15684 /var/lib/mysql/mysql.sock
unix 3 [ ] STREAM CONNECTED 15683
unix 2 [ ] DGRAM 14977
unix 2 [ ] DGRAM 14485
unix 2 [ ] DGRAM 13976
unix 3 [ ] STREAM CONNECTED 13438 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 13437
unix 2 [ ] DGRAM 13276
unix 2 [ ] DGRAM 13138
unix 2 [ ] DGRAM 13067
unix 3 [ ] STREAM CONNECTED 13051
unix 3 [ ] STREAM CONNECTED 13050
unix 3 [ ] STREAM CONNECTED 13047
unix 3 [ ] STREAM CONNECTED 13046
netstat 的常用参数: -t、-u、-w和 -x分别表示TCP、UDP、RAW和UNIX套接字连接。
-a标记,还会显示出等待连接(也就是说处于监听模式)的套接字。
-l 显示正在被监听(listen)的端口。
-n表示直接显示端口数字而不是通过察看/etc/service来转换为端口名。
-p选项表示列出监听的程序
[root@DBSVR02 conf]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:50790 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 168.168.80.9:22 168.168.80.1:22332 ESTABLISHED
tcp 0 0 168.168.80.9:22 168.168.80.1:22864 ESTABLISHED
tcp 0 0 :::42855 :::* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::80 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
[root@DBSVR02 conf]#
- 查看当前tcp监听端口
[root@DBSVR02 conf]# netstat -tl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:50790 *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 localhost:smtp *:* LISTEN
tcp 0 0 *:42855 *:* LISTEN
tcp 0 0 *:sunrpc *:* LISTEN
tcp 0 0 *:http *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost:ipp *:* LISTEN
tcp 0 0 localhost:smtp *:* LISTEN
[root@DBSVR02 conf]#
- 查看当前tcp监听端口, 需要显示监听的程序名,当不清楚mysql的监听端口时比较好用
[root@DBSVR02 conf]# netstat -tlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 *:50790 *:* LISTEN 1216/rpc.statd
tcp 0 0 *:sunrpc *:* LISTEN 1197/rpcbind
tcp 0 0 *:ssh *:* LISTEN 1474/sshd
tcp 0 0 localhost:ipp *:* LISTEN 1360/cupsd
tcp 0 0 localhost:smtp *:* LISTEN 1550/master
tcp 0 0 *:42855 *:* LISTEN 1216/rpc.statd
tcp 0 0 *:sunrpc *:* LISTEN 1197/rpcbind
tcp 0 0 *:http *:* LISTEN 1590/httpd
tcp 0 0 *:ssh *:* LISTEN 1474/sshd
tcp 0 0 localhost:ipp *:* LISTEN 1360/cupsd
tcp 0 0 localhost:smtp *:* LISTEN 1550/master
[root@DBSVR02 conf]#