Shell学习之网络管理相关命令

该节主要讲解linux中和网络管理相关的一些命令,包括ifconfig, host, ping, traceroute, scp等。

ifconfig

ifconfig 用于显示网络接口,子网掩码等信息, 例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
EHC29: flags=0<> mtu 0
EHC26: flags=0<> mtu 0
XHC20: flags=0<> mtu 0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether a8:20:66:09:68:c9
nd6 options=201<PERFORMNUD,DAD>
media: autoselect (none)
status: inactive

第1列为接口名,后面为详细信息。

列出某个网络接口的详细信息:

1
$ ifconfig eh0

host

host为DNS查找工具,其可以列出某个域名的所有IP地址:

1
2
3
4
5
6
7
8
9
$ host baidu.com
baidu.com has address 220.181.57.216
baidu.com has address 123.125.115.110
baidu.com mail is handled by 20 mx50.baidu.com.
baidu.com mail is handled by 20 mx1.baidu.com.
baidu.com mail is handled by 10 mx.maillb.baidu.com.
baidu.com mail is handled by 20 jpmx.baidu.com.
baidu.com mail is handled by 15 mx.n.shifen.com.

自定义host解析:

1
$ echo 192.168.0.10 server.com >> /etc/hosts

traceroute

traceroute使用ICMP协议, 可以查看请求所经过的网关信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ traceroute baidu.com
traceroute: Warning: baidu.com has multiple addresses; using 220.181.57.216
traceroute to baidu.com (220.181.57.216), 64 hops max, 52 byte packets
1 192.168.31.1 (192.168.31.1) 1.600 ms 0.817 ms 0.974 ms
2 192.168.1.1 (192.168.1.1) 1.476 ms 1.540 ms 1.427 ms
3 27.19.156.1 (27.19.156.1) 3.777 ms 2.985 ms 4.599 ms
4 111.175.209.201 (111.175.209.201) 7.229 ms 7.078 ms
111.175.226.53 (111.175.226.53) 12.943 ms
5 111.175.210.217 (111.175.210.217) 6.566 ms
111.175.209.49 (111.175.209.49) 9.234 ms 5.226 ms
6 202.97.67.17 (202.97.67.17) 21.192 ms 27.989 ms
202.97.67.25 (202.97.67.25) 29.571 ms

ping

ping 使用ICMP协议,能够检查主机是否能够正常访问:

1
$ ping baidu.com

scp

scp 能够进行主机之间的文件上传及下载服务:

1
2
3
4
5
$ scp filename [email protected]:/home/path #上传
$ scp [email protected]:/home/path filename #下载
$ scp -r /home/leon [email protected]:/home/path #递归复制
坚持原创技术分享,您的支持将鼓励我继续创作!