當我的設備在機房,懶得去查看網線連接情況;或者設備在遠端,沒有條件讓眼睛親臨現場,我需要在終端查看設備網絡接口的物理連接狀態。基於此種場景,我就了解了幾種關於命令查看網絡狀態的方法。
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