-
使用ifconfig命令查看网络接口
ifconfig
查看所有网卡:ifconfig -a
查看指定网卡:ifconfig 设备名例:[root@localhost ~]# ifconfig eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.148.8 netmask 255.255.255.0 broadcast 192.168.148.255 inet6 fe80::20c:29ff:fe92:f615 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:92:f6:15 txqueuelen 1000 (Ethernet) RX packets 4519 bytes 4175981 (3.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 474 bytes 57047 (55.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 0 (Local Loopback) RX packets 20 bytes 1728 (1.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 20 bytes 1728 (1.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
注:最小化安装,没有ifconfig的解决方法
例:root@localhost ~]# yum provides */ifconfig #查看命令属于哪个安装包 已加载插件:fastestmirror Loading mirror speeds from cached hostfile net-tools-2.0-0.17.20131004git.el7.x86_64 : Basic networking tools 源 :cdrom 匹配来源: 文件名 :/sbin/ifconfig [root@localhost ~]# yum -y install net-tools 已加载插件:fastestmirror Loading mirror speeds from cached hostfile 正在解决依赖关系 --> 正在检查事务 ...... 中间过程省略 ...... 正在安装 : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1 验证中 : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1 已安装: net-tools.x86_64 0:2.0-0.17.20131004git.el7 完毕!
-
使用ip 、ethtool查看网络接口
查看网络接口的数据链路层信息:ip link例:[root@localhost ~]# ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000 link/ether 00:0c:29:92:f6:15 brd ff:ff:ff:ff:ff:ff
查看网络接口的网络层信息:ip a
例:[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:92:f6:15 brd ff:ff:ff:ff:ff:ff
inet 192.168.148.8/24 brd 192.168.148.255 scope global eno16777728
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe92:f615/64 scope link
valid_lft forever preferred_lft forever
查看指定网络接口的接口速率,模式信息:ethtool 网卡名
例:[root@localhost ~]# ifconfig | head -1
eno16777728: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
[root@localhost ~]# ethtool eno16777728
Settings for eno16777728:
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
-
查看路由表信息
route
-n : 不执行DNS反向查找,直接以数字的形式显示IP地址例:[root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.148.2 0.0.0.0 UG 100 0 0 eno16777728 192.168.148.0 0.0.0.0 255.255.255.0 U 100 0 0 eno16777728
-
查看网络连接情况
netstat
-a:显示当前主机所有活动网络信息
-n:以数字的形式显示
-t:显示TCP协议有关信息
-u:显示UDP协议相关信息
-p:显示进程号,进程名称等信息
-l:只查看监听状态的进程
-r:显示路由表信息例:[root@localhost ~]# netstat -antp 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 1376/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1549/master tcp 0 0 192.168.148.8:22 192.168.148.1:55532 ESTABLISHED 2072/sshd: root@pts tcp6 0 0 :::22 :::* LISTEN 1376/sshd tcp6 0 0 ::1:25 :::* LISTEN 1549/master [root@localhost ~]# netstat -anup Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
补充:
ss -aupt
lsfo -i :22
例:[root@localhost ~]# ss -aupt
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 *:ssh *:* users:(("sshd",1376,3))
tcp LISTEN 0 100 127.0.0.1:smtp *:* users:(("master",1549,13))
tcp ESTAB 0 0 192.168.148.8:ssh 192.168.148.1:55532 users:(("sshd",2072,3))
tcp LISTEN 0 128 :::ssh :::* users:(("sshd",1376,4))
tcp LISTEN 0 100 ::1:smtp :::* users:(("master",1549,14))
[root@localhost ~]#
[root@localhost ~]# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1376 root 3u IPv4 17254 0t0 TCP *:ssh (LISTEN)
sshd 1376 root 4u IPv6 17256 0t0 TCP *:ssh (LISTEN)
5.测试网络连通性
ping 命令
-c:指定发送数据包的个数
-i:ping通时,间隔多少秒发送下一个数据包
-w:ping不通是,指定发送的每个数据包的超时时间
-s:指定数据包的大小
例:[root@localhost ~]# ping -c 4 www.baidu.com
PING www.a.shifen.com (182.61.200.7) 56(84) bytes of data.
64 bytes from 182.61.200.7: icmp_seq=1 ttl=128 time=12.5 ms
64 bytes from 182.61.200.7: icmp_seq=2 ttl=128 time=6.89 ms
64 bytes from 182.61.200.7: icmp_seq=3 ttl=128 time=12.2 ms
64 bytes from 182.61.200.7: icmp_seq=4 ttl=128 time=6.55 ms
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3029ms
rtt min/avg/max/mdev = 6.556/9.556/12.539/2.837 ms
[root@localhost ~]# ping -c 4 -i 3 www.baidu.com
PING www.a.shifen.com (182.61.200.6) 56(84) bytes of data.
64 bytes from 182.61.200.6: icmp_seq=1 ttl=128 time=10.6 ms
64 bytes from 182.61.200.6: icmp_seq=2 ttl=128 time=22.4 ms
64 bytes from 182.61.200.6: icmp_seq=3 ttl=128 time=4.99 ms
64 bytes from 182.61.200.6: icmp_seq=4 ttl=128 time=11.7 ms
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 9029ms
rtt min/avg/max/mdev = 4.990/12.464/22.481/6.324 ms
[root@localhost ~]# ping -c 4 -s 100 www.baidu.com
PING www.a.shifen.com (182.61.200.6) 100(128) bytes of data.
108 bytes from 182.61.200.6: icmp_seq=1 ttl=128 time=7.80 ms
108 bytes from 182.61.200.6: icmp_seq=2 ttl=128 time=16.6 ms
108 bytes from 182.61.200.6: icmp_seq=3 ttl=128 time=4.85 ms
108 bytes from 182.61.200.6: icmp_seq=4 ttl=128 time=8.26 ms
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3023ms
rtt min/avg/max/mdev = 4.852/9.394/16.650/4.389 ms
补充:常见的TTL值
Windows:128
linux:64
Unix:255
Cisco:255
跟踪数据包的途径
traceroute
-n : 不执行DNS反向查找,直接显示数字形式IP地址
例:[root@localhost ~]#
[root@localhost ~]# traceroute -n www.baidu.com
traceroute to www.baidu.com (182.61.200.6), 30 hops max, 60 byte packets
1 192.168.148.2 0.277 ms 0.164 ms 0.084 ms
2 * * *
3 * * *
4 * * *
DNS域名解析
nslookup 地址
例:[root@localhost ~]# nslookup www.baidu.com
Server: 202.106.46.151
Address: 202.106.46.151#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 182.61.200.7
Name: www.a.shifen.com
Address: 182.61.200.6