Linux常用网络命令

Linux 常用网络命令

Linux 命令学习方法

Linux 命令都可以通过 Linux 提供的手册自己学习,一般来讲有三种方式查看命令的用法,如下:

就拿最常用的 ls 命令来举例子吧

第一种:

1
ls --help

第二种:

1
info ls

第三种:

1
man ls

大家可以使用 命令 --help, info + 命令, man + 命令 三种方式来学习新的命令,大家也可以使用 The Linux man-pages project 来查找对应的命令。说到这里,让我们来学习下 Linux 的常用网路命令吧

Linux 常用网络命令

今天主要跟大家分享下 Linux 系统常用网络的命令:

  • ifconfig
  • ifup
  • ifdown
  • ip
  • route
  • ip route
  • ping
  • traceroute
  • netstat
  • nslookup
ifconfig

查看所有网卡信息

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
shenjy@DESKTOP-MCQT724:~$ ifconfig -a
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.2 netmask 255.255.255.0 broadcast 192.168.3.255
ether b4:b6:86:fc:12:07 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.1 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::6715:52aa:2c80:112f prefixlen 64 scopeid 0xfd<compat,link,site,host>
ether 0a:00:27:00:00:03 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth2: flags=64<RUNNING> mtu 1500
inet 169.254.202.32 netmask 255.255.0.0
inet6 fe80::971b:12ac:b88c:961d prefixlen 64 scopeid 0xfd<compat,link,site,host>
ether 7c:76:35:43:62:9f (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.22.96.1 netmask 255.255.240.0 broadcast 172.22.111.255
inet6 fe80::584c:ccd0:e077:634c prefixlen 64 scopeid 0xfd<compat,link,site,host>
ether 00:15:5d:41:e6:ee (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 1500
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0xfe<compat,link,site,host>
loop (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wifi0: flags=64<RUNNING> mtu 1500
inet 169.254.169.148 netmask 255.255.0.0
ether 7c:76:35:43:62:9b (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wifi1: flags=64<RUNNING> mtu 1500
inet 169.254.112.16 netmask 255.255.0.0
ether 7c:76:35:43:62:9c (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wifi2: flags=64<RUNNING> mtu 1500
inet 169.254.241.4 netmask 255.255.0.0
ether 7e:76:35:43:62:9b (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

其余,参数大家可以通过手册自行学习,这里要大家注意下 MTU 这个关键参数,大家可以根据着篇 blog 进行学习。

大家也可以参照这篇 Blog 学习这个命令。

ifup

激活网络接口eth0

1
shenjy@DESKTOP-MCQT724:~$ ifup eth0

大家也可以参照这篇 Blog 学习这个命令。

ifdown

禁用网络端口eth0

1
shenjy@DESKTOP-MCQT724:~$ ifdown eth0

大家也可以参照这篇 Blog 学习这个命令。

ip

查看机器所有网卡的 ip

1
shenjy@DESKTOP-MCQT724:~$ ip a

大家也可以参照这篇 Blog 学习这个命令。

route

查看 Linux 内核路由表

1
shenjy@DESKTOP-MCQT724:~$ route

大家也可以参照这篇 Blog 学习这个命令。

ip route

查看默认路由表(main)路由

1
shenjy@DESKTOP-MCQT724:~$ ip route

大家也可以参照这篇 Blog 学习这个命令。

ping

查看网络链路是否通

1
2
3
shenjy@DESKTOP-MCQT724:~$ ping www.baidu.com
shenjy@DESKTOP-MCQT724:~$ ping localhost
shenjy@DESKTOP-MCQT724:~$ ping 127.0.0.1

大家也可以参照这篇 Blog 学习这个命令。

traceroute

追踪网络数据包的路由途径,也可以顺道学习下 tracert 这个命令

1
shenjy@DESKTOP-MCQT724:~$ traceroute www.baidu.com

大家也可以参照这篇 Blog 学习这个命令。

netstat

Print network connections, routing tables, interface statistics, masquerade connections, and multicast member‐
ships

1
2
3
4
5
6
7
shenjy@DESKTOP-MCQT724:~$ netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 0 0 0 0 0 0 0 BMRU
eth1 1500 0 0 0 0 0 0 0 0 BMRU
eth3 1500 0 0 0 0 0 0 0 0 BMRU
lo 1500 0 0 0 0 0 0 0 0 LRU

大家也可以参照这篇 Blog 学习这个命令。

nslookup

Nslookup is a program to query Internet domain name servers. Nslookup has two modes: interactive and non-interactive.
Interactive mode allows the user to query name servers for information about various hosts and domains or to print a list
of hosts in a domain. Non-interactive mode is used to print just the name and requested information for a host or domain.

1
2
3
4
5
6
7
shenjy@DESKTOP-MCQT724:~$ nslookup baidu.com
Server: 8.8.8.8
Address: 8.8.8.8#53

Non-authoritative answer:
Name: baidu.com
Address: 39.156.66.10

大家也可以参照这篇 Blog 学习这个命令。

以上就是一些常用的 Linux 网络命令了,但是还没有完,以后如果遇到一些新的命令,我还会继续往这里追加的, 也欢迎大家留言~