TTL=52:TTL是Time To Live的缩写,表示DNS记录在DNS服务器上存在的时间,是IP协议包的一个值,告诉路由器啥时候抛弃这个数据包,(大体上可以通过这个值来判断目标类型的操作系统。)
发送指定数目
可以通过 参数-c 来发送指定数目的包后停止
1 2 3 4 5 6 7 8 9 10 11
$ ping www.baidu.com -c 5 PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data. 64 bytes from 115.239.211.112: icmp_seq=1 ttl=52 time=6.03 ms 64 bytes from 115.239.211.112: icmp_seq=2 ttl=52 time=5.96 ms 64 bytes from 115.239.211.112: icmp_seq=3 ttl=52 time=5.79 ms 64 bytes from 115.239.211.112: icmp_seq=4 ttl=52 time=5.79 ms 64 bytes from 115.239.211.112: icmp_seq=5 ttl=52 time=6.21 ms
--- www.a.shifen.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4007ms rtt min/avg/max/mdev = 5.791/5.958/6.215/0.186 ms
此时将在发送5次数据包以后自动停止,在Linux里面,如果不加这个参数,是会一直发送运行的。
设定发送时间间隔
可以通过 参数 -i N指定每个N秒发送一次信息,如下将每隔3秒发送一次ping信息。
1 2 3 4 5 6 7 8 9 10 11 12
$ ping www.baidu.com -i 3 PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=55 time=28.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=55 time=28.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=55 time=28.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=55 time=28.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=5 ttl=55 time=28.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=6 ttl=55 time=28.6 ms ^C --- www.a.shifen.com ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 15041ms rtt min/avg/max/mdev = 28.650/28.670/28.697/0.139 ms
如上,每隔3秒会发送一次,对于需要持续检测或者记录的可以考虑适当加大这个时间间隔。
注意,只有管理员可以设置小于0.2秒的时间间隔。所以这个数值可以是浮点数~
组合使用
上面的几个例子是可以配合使用的,比如
1 2 3 4 5 6 7 8 9 10 11
$ ping www.baidu.com -c 4 -i 5 PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=55 time=29.4 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=55 time=29.3 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=55 time=29.4 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=4 ttl=55 time=29.4 ms
--- www.a.shifen.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 20045ms rtt min/avg/max/mdev = 29.396/29.428/29.461/0.110 ms
这个例子为:每个5秒查询一次,一共查询4次,然后退出。
Linux ip命令
Linux ip 命令与 ifconfig 命令类似,但比 ifconfig 命令更加强大,主要用于显示或设置网络设备。
# 显示网络设备 $ ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN mode DEFAULT group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
# 显示IP等更多信息 $ ip address show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet 192.168.1.123/24 brd 192.168.254.255 scope global noprefixroute eno1 valid_lft forever preferred_lft forever inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/64 scope global noprefixroute valid_lft forever preferred_lft forever 3: eno2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 9000 qdisc mq state DOWN group default qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
命令中的show为默认,也可以直接使用ip link或者ip address,结果一致。
设置IP地址
可以通过ip addr add/del xxx.xxx.xxx.xxx dev interface 来设置或者删除IP地址。