Linux netstat命令详解
netstat命令用于显示各种网络相关信息。如网络连接,路由表,接口状态(Interface Statistics),masquerade连接,多播成员(Multicast Memberships)等。
常见参数:
-a 显示所有选项,默认不显示LISTEN相关信息
-t 仅显示tcp相关选项
-u 仅显示udp相关选项
-n 拒绝显示别名,能显示数字的全部转化成数字
-l 仅列出有在Listen(监听)的服务状态
-p 显示建立相关的程序名
-r 显示路由信息,路由表
-e 显示扩展信息
-s 按各个协议进行统计
-c 每隔一个固定时间,执行该netstat命令
提示:LISTEN各LISTENING的状态只有用-a或-l才能看到[root@apenglinux-001 ~]# netstat -a //列出所有端口(包括监听和未监听的)
[root@apenglinux-001 ~]# netstat -atu //列出所有tcp和udp端口
[root@apenglinux-001 ~]# netstat -lx //列出所有监听UNIX端口
[root@apenglinux-001 ~]# netstat -sut //显示tcp和udp的统计信息
[root@apenglinux-001 ~]# netstat -rn //显示路由表
[root@apenglinux-001 ~]# netstat -tlnp|grep httpd
[root@apenglinux-001 ~]# netstat -i //显示网络接口列表
[root@apenglinux-001 ~]# netstat -ie //显示与ifconfig一样的信息
ifconfig命令[root@apenglinux-002 yum.repos.d]# ifconfig
[root@apenglinux-002 yum.repos.d]# ifdown ens33;ifup ens33 //重启某一个网卡
[root@apenglinux-002 yum.repos.d]# systemctl restart network //重启网卡
给一个网卡设定多个ip[root@apenglinux-002 network-scripts]# cd /etc/sysconfig/network-scripts/
[root@apenglinux-002 network-scripts]# cp ifcfg-ens33 ifcfg-ens33:1
[root@apenglinux-002 network-scripts]# vi ifcfg-ens33:1
[root@apenglinux-002 network-scripts]# ifdown ens33;ifup ens33
查看网卡连接状态[root@localhost ~]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok[root@localhost ~]# ethtool ens33
Settings for ens33:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: off (auto)
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes