这里写自定义目录标题
- 一 netstat的作用以及安装命令
- 1.1 作用
- 1.2 安装命令
- 二 基本语法
- 1.1 netstat -a
- 1.2 netstat -e
- 1.3 netstat -anp
- 三 查看指定端口的使用状况
一 netstat的作用以及安装命令
1.1 作用
主要用于显示IP和TCP、UDP与ICMP相关的统计数据,一般用于检验本机各端口的网络连接情况
1.2 安装命令
[root@localhost ~]# yum install net-tools
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bfsu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
软件包 net-tools-2.0-0.25.20131004git.el7.x86_64 已安装并且是最新版本
无须任何处理
二 基本语法
1.1 netstat -a
显示一些网络协议,比方说一些端口号
[root@localhost ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 36 localhost.localdoma:ssh 192.168.80.1:50926 ESTABLISHED
tcp6 0 0 [::]:mysql [::]:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 [::]:33060 [::]:* LISTEN
raw6 0 0 [::]:ipv6-icmp [::]:* 7
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 4 [ ] DGRAM 9022 /run/systemd/notify
unix 2 [ ] DGRAM 9024 /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 9032 /run/systemd/journal/stdout
unix 5 [ ] DGRAM 9035 /run/systemd/journal/socket
unix 9 [ ] DGRAM 9037 /dev/log
unix 2 [ ACC ] STREAM LISTENING 20053 /var/run/mysqld/mysqlx.sock
1.2 netstat -e
显示关于以太网的统计数据
[root@localhost ~]# netstat -e
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode
tcp 0 36 localhost.localdoma:ssh 192.168.80.1:50926 ESTABLISHED root 22342
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 4 [ ] DGRAM 9022 /run/systemd/notify
unix 2 [ ] DGRAM 9024 /run/systemd/cgroups-agent
unix 5 [ ] DGRAM 9035 /run/systemd/journal/socket
unix 9 [ ] DGRAM 9037 /dev/log
unix 2 [ ] DGRAM 13737 /run/systemd/shutdownd
unix 3 [ ] STREAM CONNECTED 19480
unix 3 [ ] STREAM CONNECTED 16788
unix 2 [ ] DGRAM 18388
unix 3 [ ] STREAM CONNECTED 17007 /run/systemd/journal/stdout
1.3 netstat -anp
组合的查看一些网络信息
[root@localhost ~]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 876/sshd
tcp 0 36 192.168.80.121:22 192.168.80.1:50926 ESTABLISHED 1677/sshd: root@pts
tcp6 0 0 :::3306 :::* LISTEN 927/mysqld
tcp6 0 0 :::22 :::* LISTEN 876/sshd
tcp6 0 0 :::33060 :::* LISTEN 927/mysqld
raw6 0 0 :::58 :::* 7 643/NetworkManager
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 4 [ ] DGRAM 9022 1/systemd /run/systemd/notify
unix 2 [ ] DGRAM 9024 1/systemd /run/systemd/cgroups-agent
unix 2 [ ACC ] STREAM LISTENING 9032 1/systemd /run/systemd/journal/stdout
unix 5 [ ] DGRAM 9035 1/systemd /run/systemd/journal/socket
unix 9 [ ] DGRAM 9037 1/systemd /dev/log
unix 2 [ ACC ] STREAM LISTENING 20053 927/mysqld /var/run/mysqld/mysqlx.sock
unix 2 [ ACC ] STREAM LISTENING 16733 1/systemd /run/dbus/system_bus_socket
三 查看指定端口的使用状况
[root@localhost ~]# netstat -anp|grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 876/sshd
tcp 0 36 192.168.80.121:22 192.168.80.1:50926 ESTABLISHED 1677/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 876/sshd
unix 4 [ ] DGRAM 9022 1/systemd /run/systemd/notify
unix 2 [ ] DGRAM 22457 1677/sshd: root@pts