当我的设备在机房,懒得去查看网线连接情况;或者设备在远端,没有条件让眼睛亲临现场,我需要在终端查看设备网络接口的物理连接状态。基于此种场景,我就了解了几种关于命令查看网络状态的方法。
1. ifconfig
ifconfig是Linux系统自带命令,可以查看接口配置IP的情况、临时配置接口IP(永久配置可以使用yast或者修改/etc/sysconfig/nework/ifcfg-eth0)、查看网卡口的链路状态。
MYSUSE:/ # ifconfig eth0
eth0 Link encap:Ethernet HWaddr E0:36:76:D1:9F:B0
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::e236:76ff:fed1:9fb0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2200774 errors:0 dropped:4647 overruns:0 frame:0
TX packets:1139522 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2684945760 (2560.5 Mb) TX bytes:116659921 (111.2 Mb)
Interrupt:40
2. yast/yast2
yast2是yast的图形化进阶版,像是windows系统里的控制面板功能。命令就是:yast调出yast界面-->选择Network Devices-->Network Settings,打开网络配置界面。
网卡口有连接网线和已经配置IP的状态:
Broadcom Ethernet controller
MAC : e0:36:76:d1:9f:b0
BusID : 0000:08:00.0
Device Name: eth0
Started automatically at boot
IP address: 192.168.0.1/24
网卡口未连接网线和未配置IP的状态:
82599EB 10 Gigabit Dual Port Backplane Connection (Not connected)
MAC : bc:62:0e:4f:b1:3b
BusID : 0000:02:00.1
Device Name: eth5
The device is not configured. Press Edit to configure.
3. service network status
Linux中常用的服务查询方法,查询结果如下所示:
MYSUSE:/ # service network status
Checking optional network interfaces:
eth0 device: Broadcom Corporation NetXtreme BCM5719 Gigabi
eth0 IP address: 192.168.0.1/24
eth0 is up running
eth1 device: Broadcom Corporation NetXtreme BCM5719 Gigabi
No configuration found for eth1 unused
eth2 device: Broadcom Corporation NetXtreme BCM5719 Gigabi
No configuration found for eth2 unused
eth3 device: Broadcom Corporation NetXtreme BCM5719 Gigabi
No configuration found for eth3 unused
eth4 device: Intel Corporation 82599EB 10 Gigabit Dual Por
eth4 DHCP4 client (dhcpcd) is running
eth4 . . . but is still waiting for data
eth4 is up waiting
eth5 device: Intel Corporation 82599EB 10 Gigabit Dual Por
No configuration found for eth5 unused
Checking mandatory network interfaces:
lo
lo IP address: 127.0.0.1/8
secondary lo IP address: 127.0.0.2/8
lo is up running
Checking service network . . . . . . . . . . . running
4. ip link show eth0
ip link工具查询可以指定接口进行增删改查。
MYSUSE:/ # ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether e0:36:76:d1:9f:b0 brd ff:ff:ff:ff:ff:ff
5. ethtool eth0
ethtool比ip link工具功能更丰富一些。
MYSUSE:/ # ethtool eth0
Settings for eth0:
Supported ports: [ FIBRE ]
Supported link modes: 1000baseT/Half 1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 1000baseT/Half 1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: FIBRE
PHYAD: 8
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: d
Wake-on: d
Current message level: 0x000000ff (255)
drv probe link timer ifdown ifup rx_err tx_err
Link detected: yes