Linux显示/显示可用的网络接口

时间:2020-01-09 10:41:45  来源:igfitidea点击:

如何使用bash shell提示符显示Linux操作系统下所有可用的网络接口名称?
在Linux上如何使用ip命令列出接口/NIC?
您可以使用以下命令查看Linux操作系统下的所有网络接口:

  • ip命令用于显示或操纵路由,设备,策略路由和隧道。
  • netstat命令用于显示网络连接,路由表,接口统计信息,伪装连接和多播成员身份。
  • ifconfig命令用于显示或配置网络接口。

在Linux上使用ip命令列出网络接口

输入以下ip命令,执行:

$ ip link show

输出示例:

$ 1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
3: wlan0:  mtu 1500 qdisc mq state DOWN qlen 1000
    link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff
4: vboxnet0:  mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff
5: pan0:  mtu 1500 qdisc noop state DOWN 
    link/ether c2:10:fa:55:8e:32 brd ff:ff:ff:ff:ff:ff
6: vmnet1:  mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff
7: vmnet8:  mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff
11: ppp0:  mtu 1496 qdisc pfifo_fast state UNKNOWN qlen 3
    link/ppp

Linux使用nmcli和ip命令列出所有网络接口

在Linux中使用netstat命令显示所有网络接口的表

执行以下命令:

$ netstat -i

输出示例:

Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0   2697347      0      0 0       2630262      0      0      0 BMRU
lo        16436 0      2840      0      0 0          2840      0      0      0 LRU
ppp0       1496 0    102800      0      0 0         63437      0      0      0 MOPRU
vmnet1     1500 0         0      0      0 0            49      0      0      0 BMRU
vmnet8     1500 0         0      0      0 0            49      0      0      0 BMRU

使用ifconfig命令的Linux IP列表接口

执行以下ifconfig命令:

$ /sbin/ifconfig -a

输出示例:

eth0      Link encap:Ethernet  HWaddr b8:ac:6f:65:31:e5  
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::baac:6fff:fe65:31e5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2697529 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2630541 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2159382827 (2.0 GiB)  TX bytes:1389552776 (1.2 GiB)
          Interrupt:17 
 
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2849 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2849 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:2778290 (2.6 MiB)  TX bytes:2778290 (2.6 MiB)

如何在Linux上查看路由表?

使用以下命令:

ip r

输出示例:

0.0.0.0/1 via 10.8.0.1 dev tun0 
default via 192.168.1.254 dev enp6s0 proto static metric 100 
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2 
128.0.0.0/1 via 10.8.0.1 dev tun0 
139.59.1.155 via 192.168.1.254 dev enp6s0 
169.254.0.0/16 dev virbr0 scope link metric 1000 linkdown 
192.168.1.0/24 dev enp6s0 proto kernel scope link src 192.168.1.24 metric 100 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown

如何在Linux上看到arp缓存连接到我的NIC?

运行arp命令:

arp
arp -a
arp -e
arp -n

输出示例:

Address                  HWtype  HWaddress           Flags Mask            Iface
centos7                  ether   00:01:c0:1c:09:4c   C                     enp6s0
freebsd11-box            ether   00:01:c0:1c:09:4c   C                     enp6s0
192.168.1.203            ether   00:01:c0:1c:09:4c   C                     enp6s0
fw0-pfsense-sg-3100.swe  ether   00:08:a2:0d:05:41   C                     enp6s0
192.168.1.205            ether   00:01:c0:1c:09:4c   C                     enp6s0
192.168.1.202            ether   00:01:c0:1c:09:4c   C                     enp6s0