ping
作用:常用于测试网络连通性
注释:ping 主机或IP 默认一直ping(Ctrl+C停止)
常用选项:
 -i 秒数:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次
 -f 极限检测。大量且快速地送网络封包给一台机器,看它的回应
 -c 设置完成要求回应的次数
 -w ping的时间周期

 -W 超时时间
实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@jacken /] # ping -f jd.com
PING jd.com (211.152.122.55) 56(84) bytes of data.
.....^C 
--- jd.com  ping  statistics ---
421 packets transmitted, 416 received, 1% packet loss,  time  9789ms
rtt min /avg/max/mdev  = 67.218 /73 .692 /96 .248 /3 .967 ms, pipe 8, ipg /ewma  23.307 /73 .829 ms
[root@jacken /]
[root@jacken /] # ping -c 2 jd.com
PING jd.com (211.152.122.55) 56(84) bytes of data.
64 bytes from 211.152.122.55: icmp_seq=1 ttl=128  time =72.6 ms
64 bytes from 211.152.122.55: icmp_seq=2 ttl=128  time =76.8 ms
--- jd.com  ping  statistics ---
2 packets transmitted, 2 received, 0% packet loss,  time  4157ms
rtt min /avg/max/mdev  = 72.618 /74 .757 /76 .897 /2 .156 ms
[root@jacken /]
[root@jacken /] # ping -w 3 jd.com
PING jd.com (211.152.122.55) 56(84) bytes of data.
64 bytes from 211.152.122.55: icmp_seq=1 ttl=128  time =74.7 ms
--- jd.com  ping  statistics ---
1 packets transmitted, 1 received, 0% packet loss,  time  4087ms
rtt min /avg/max/mdev  = 74.788 /74 .788 /74 .788 /0 .000 ms
[root@jacken /] #

route
作用:显示和操作IP路由表
注释:
命令格式:route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]] 
常用选项:
 -c 显示更多信息
 -n 不解析名字
 -v 显示详细的处理信息
 -F 显示发送信息
 -C 显示路由缓存
 -f 清除所有网关入口的路由表。 
 -p 与 add 命令一起使用时使路由具有永久性。
 add:添加一条新路由。
 del:删除一条路由。
 -net:目标地址是一个网络。
 -host:目标地址是一个主机。
 netmask:当添加一个网络路由时,需要使用网络掩码。
 gw:路由数据包通过网关。注意,你指定的网关必须能够达到。
 metric:设置路由跳数。
 Command 指定您想运行的命令 (Add/Change/Delete/Print)。 
 Destination 指定该路由的网络目标。 
 mask Netmask 指定与网络目标相关的网络掩码(也被称作子网掩码)。 
 Gateway 指定网络目标定义的地址集和子网掩码可以到达的前进或下一跃点 IP 地址。 
 metric Metric 为路由指定一个整数成本值标(从 1 至 9999),当在路由表(与转发的数据包目标地址最匹配)的多个路由中进行选择时可以使用。 
 if Interface 为可以访问目标的接口指定接口索引。若要获得一个接口列表和它们相应的接口索引,使用 route print 命令的显示功能。可以使用十进制或十六进制值进行接口索引。
实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1、显示当前路由
[root@jacken /] # route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.33.0    *               255.255.255.0   U     1      0        0 eth1
link- local       *               255.255.0.0     U     1002   0        0 eth0
default         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /] #

说明:
第一行表示主机所在网络的地址为192.168.1.0,若数据传送目标是在本局域网内通信,则可直接通过eth0转发数据包;
第四行表示数据传送目的是访问Internet,则由接口eth0,将数据包发送到网关192.168.33.2
其中Flags为路由标志,标记当前网络节点的状态。
Flags标志说明:
U Up表示此路由当前为启动状态
H Host,表示此网关为一主机
G Gateway,表示此网关为一路由器
R Reinstate Route,使用动态路由重新初始化的路由
D Dynamically,此路由是动态性地写入
M Modified,此路由是由路由守护程序或导向器动态修改
! 表示此路由当前为关闭状态

备注:
route -n (-n 表示不解析名字,列出速度会比route 快)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
2、添加网关/设置网关
[root@jacken /] # route add -net 224.0.0.0 netmask 240.0.0.0 dev eth1
[root@jacken /] # route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.33.0    *               255.255.255.0   U     1      0        0 eth1
link- local       *               255.255.0.0     U     1002   0        0 eth0
224.0.0.0       *               240.0.0.0       U     0      0        0 eth1
default         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /]
备注:增加一条 到达244.0.0.0的路由
3、屏蔽一条路由
[root@jacken /] # route add -net 224.0.0.0 netmask 240.0.0.0 reject
[root@jacken /] # route 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
192.168.33.0    *               255.255.255.0   U     1      0        0 eth1
link- local       *               255.255.0.0     U     1002   0        0 eth0
224.0.0.0       -               240.0.0.0       !     0      -        0 -
224.0.0.0       *               240.0.0.0       U     0      0        0 eth1
default         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /]
备注:增加一条屏蔽的路由,目的地址为 224.x.x.x 将被拒绝
4、删除路由记录
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
224.0.0.0       -               240.0.0.0       !     0      -        0 -
224.0.0.0       0.0.0.0         240.0.0.0       U     0      0        0 eth1
0.0.0.0         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /] # route del -net 224.0.0.0 netmask 240.0.0.0
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
224.0.0.0       -               240.0.0.0       !     0      -        0 -
0.0.0.0         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /] # route del -net 224.0.0.0 netmask 240.0.0.0 reject
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /]
5、删除和添加默认网关
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /] # route del default gw 192.168.33.2
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
[root@jacken /] # ping jd.com
connect: Network is unreachable
[root@jacken /] # route add default gw 192.168.33.2
[root@jacken /] # route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.33.0    0.0.0.0         255.255.255.0   U     1      0        0 eth1
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.33.2    0.0.0.0         UG    0      0        0 eth1
[root@jacken /] # ping jd.com
PING jd.com (211.152.122.55) 56(84) bytes of data.
64 bytes from 211.152.122.55: icmp_seq=1 ttl=128  time =72.9 ms
64 bytes from 211.152.122.55: icmp_seq=2 ttl=128  time =69.9 ms
64 bytes from 211.152.122.55: icmp_seq=3 ttl=128  time =73.6 ms
^C
--- jd.com  ping  statistics ---
3 packets transmitted, 3 received, 0% packet loss,  time  5273ms
rtt min /avg/max/mdev  = 69.996 /72 .201 /73 .611 /1 .579 ms
[root@jacken /] #

ifconfig
作用:管理与查看网络接口信息
常用选项:
 up 启动指定网络设备/网卡。
 down关闭指定网络设备/网卡。
 arp 设置指定网卡是否支持ARP协议。
 -promisc 设置是否支持网卡的promiscuous模式,如果选择此参数,网卡将接收网络中发给它所有的数据包
 -allmulti 设置是否支持多播模式,如果选择此参数,网卡将接收网络中所有的多播数据包
 -a 显示全部接口信息
 -s 显示摘要信息(类似于 netstat -i)
 add 给指定网卡配置IPv6地址
 del 删除指定网卡的IPv6地址
 <硬件地址> 配置网卡最大的传输单元
 mtu<字节数> 设置网卡的最大传输单元 (bytes)
 netmask<子网掩码> 设置网卡的子网掩码。掩码可以是有前缀0x的32位十六进制数,也可以是用点分开的4个十进制数。如果不打算将网络分成子网,可以不管这一选项;如果要使用子网,那么请记住,网络中每一个系统必须有相同子网掩码。
 tunel 建立隧道
 dstaddr 设定一个远端地址,建立点对点通信
 -broadcast<地址> 为指定网卡设置广播协议
 -pointtopoint<地址> 为网卡设置点对点通讯协议
 multicast 为网卡设置组播标志
 address 为网卡设置IPv4地址
 txqueuelen<长度> 为网卡设置传输列队的长度
实例:

1
2
3
4
5
6
7
8
9
10
11
1、显示网络设备信息(激活状态的)
[root@jacken /] # ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:AC:3C:10  
           inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
           inet6 addr: fe80::20c:29ff:feac:3c10 /64  Scope:Link
           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
           RX packets:2266 errors:0 dropped:0 overruns:0 frame:0
           TX packets:1700 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000 
           RX bytes:188470 (184.0 KiB)  TX bytes:198774 (194.1 KiB)
[root@jacken /] #

说明:
eth0 表示第一块网卡, 其中 HWaddr 表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是 00:0C:29:AC:3C:10
inet addr 用来表示网卡的IP地址,此网卡的 IP地址是 192.168.1.2,广播地址, Bcast:192.168.1.255,掩码地址Mask:255.255.255.0 
第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)
第二行:网卡的IP地址、子网、掩码
第三行:UP(代表网卡开启状态)RUNNING(代表网卡的网线被接上)MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节
第四、五行:接收、发送数据包情况统计
第七行:接收、发送数据字节数统计信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2、启动关闭某一个网卡
[root@jacken /] # ifconfig eth1 down
[root@jacken /] # ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:AC:3C:1A  
           BROADCAST MULTICAST  MTU:1500  Metric:1
           RX packets:549 errors:0 dropped:0 overruns:0 frame:0
           TX packets:555 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000 
           RX bytes:55119 (53.8 KiB)  TX bytes:54484 (53.2 KiB)
[root@jacken /] # ifconfig eth1 up
[root@jacken /] # ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:AC:3C:1A
           inet addr:192.168.33.128  Bcast:192.168.33.255  Mask:255.255.255.0
           inet6 addr: fe80::20c:29ff:feac:3c1a /64  Scope:Link
           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
           RX packets:550 errors:0 dropped:0 overruns:0 frame:0
           TX packets:561 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000 
           RX bytes:55461 (54.1 KiB)  TX bytes:55264 (53.9 KiB)
[root@jacken /] #

3、修改MAC地址
[root@jacken /]# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:AC:3C:1A  
          inet addr:192.168.33.128  Bcast:192.168.33.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feac:3c1a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:552 errors:0 dropped:0 overruns:0 frame:0
          TX packets:579 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:56145 (54.8 KiB)  TX bytes:57244 (55.9 KiB)

[root@jacken /]# ifconfig eth1 down
[root@jacken /]# ifconfig eth1 hw ether 00:AA:BB:CC:DD:EE
[root@jacken /]# ifconfig eth1 up
[root@jacken /]# ifconfig eth1 
eth1      Link encap:Ethernet  HWaddr 00:AA:BB:CC:DD:EE  
          inet addr:192.168.33.133  Bcast:192.168.33.255  Mask:255.255.255.0
          inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:561 errors:0 dropped:0 overruns:0 frame:0
          TX packets:589 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:57535 (56.1 KiB)  TX bytes:58764 (57.3 KiB)

[root@jacken /]# 
4、如下
[root@jacken /]# ifconfig eth1 arp //启用ARP
[root@jacken /]# ifconfig eth1 -arp //禁用ARP
[root@jacken /]# ifconfig eth1 mtu 1500 //设置最大传输单元1500(能通过的最大数据包大小为 1500 bytes)
[root@jacken /]# 
提示:用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。

nslookup
作用:测试DNS能否正常解析域名
实例
[root@jacken ~]# nslookup
> www.jd.com
Server:  8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name: www.jd.com
Address: 183.56.147.1
> server 114.114.114.114
Default server: 114.114.114.114
Address: 114.114.114.114#53
> www.jd.com
Server:  114.114.114.114
Address: 114.114.114.114#53

Non-authoritative answer:
Name: www.jd.com
Address: 183.56.147.1
> 183.56.147.1
Server:  114.114.114.114
Address: 114.114.114.114#53

** server can't find 1.147.56.183.in-addr.arpa.: NXDOMAIN
> 8.8.8.8
Server:  114.114.114.114
Address: 114.114.114.114#53

Non-authoritative answer:
8.8.8.8.in-addr.arpa name = google-public-dns-a.google.com.

Authoritative answers can be found from:
> exit

[root@jacken ~]#

dig
作用:类似nslookup,但更灵活更强大
常用选项:
 @server 以server作为DNS
 -x 查看反向解析
实例:

1
2
3
4
5
6
dig  www.baidu.com @8.8.8.8   // 用8.8.8.8作为DNS服务器解析百度的A记录
dig  -x 180.97.33.107 @114.114.114.114   // 用114.114.114.114作为DNS为180.97.33.107反向解析
dig  sina.com.cn. +nssearch  // 查找一个域的授权 dns 服务器
dig  news.sina.com.cn +trace  // 从根服务器开始追踪一个域名的解析过程
dig  yahoo.com A +noall +answer  // 查找yahoo.com的A记录:(此处一定是域而不是主机,如我公司为xinpindao.com)
dig  yahoo.com MX +noall +answer  // 查找yahoo.com MX记录

 

本文转自Jacken_yang 51CTO博客,原文链接:http://blog.51cto.com/linuxnote/1635813,如需转载请自行联系原作者