安装
刚新安装的CentOS,想使用netstat -ant,提示-bash: netstat: command not found,原来是没有安装net-tools
# CentOS下安装方式 yum install net-tools # Ubuntu下安装方式 # apt install net-tools
使用方法
- 查看路由表
[root@localhost ~]# netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 10.64.249.1 0.0.0.0 UG 0 0 0 ens192 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 ens192
-n 加上这个选项后,如果是default这种名字,会被强制解析成IP,如0.0.0.0
- 查看接口信息
[root@localhost ~]# netstat -i Kernel Interface table Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ens192 1500 221404 0 0 0 100323 0 0 0 BMRU lo 65536 1838 0 0 0 1838 0 0 0 LRU
- 查看网络连接状态
[root@localhost ~]# netstat -ant Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:2122 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:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:36528 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:25 0.0.0.0:* LISTEN tcp 0 36 10.0.1.190:2122 1.2.3.4:56119 ESTABLISHED tcp6 0 0 :::2122 :::* LISTEN tcp6 0 0 :::111 :::* LISTEN tcp6 0 0 :::8080 :::* LISTEN tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::55636 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:25 :::* LISTEN tcp6 0 0 127.0.0.1:8005 :::* LISTEN tcp6 0 0 10.0.1.190:52796 4.3.2.1:1521 ESTABLISHED
ESTABLISHED说明已经有其他IP连接正在访问
LISTEN说明本地端口正在监听,可以准备外部IP访问
- 查看网络服务
[root@localhost ~]# netstat -pnltu Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:2122 0.0.0.0:* LISTEN 16819/sshd tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 17527/rpcbind tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 20012/nginx: master tcp 0 0 0.0.0.0:36528 0.0.0.0:* LISTEN 17525/rpc.statd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 16819/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7202/master tcp6 0 0 :::2122 :::* LISTEN 16819/sshd tcp6 0 0 :::111 :::* LISTEN 17527/rpcbind tcp6 0 0 :::8080 :::* LISTEN 23177/java tcp6 0 0 :::80 :::* LISTEN 20012/nginx: master tcp6 0 0 :::55636 :::* LISTEN 17525/rpc.statd tcp6 0 0 :::22 :::* LISTEN 16819/sshd tcp6 0 0 ::1:25 :::* LISTEN 7202/master tcp6 0 0 127.0.0.1:8005 :::* LISTEN 23177/java udp 0 0 0.0.0.0:111 0.0.0.0:* 17527/rpcbind udp 0 0 0.0.0.0:37449 0.0.0.0:* 17525/rpc.statd udp 0 0 0.0.0.0:742 0.0.0.0:* 17527/rpcbind udp 0 0 127.0.0.1:743 0.0.0.0:* 17525/rpc.statd udp6 0 0 :::53207 :::* 17525/rpc.statd udp6 0 0 :::111 :::* 17527/rpcbind udp6 0 0 :::742 :::* 17527/rpcbind
这个命令也很有用,可以显示正在对外开放的服务,开放的端口,以及是什么程序
文章评论