温馨提示×

如何通过ifconfig查看网络接口

小樊
46
2025-10-04 08:35:13
栏目: 编程语言

ifconfig 是一个用于配置和显示 Linux 内核中网络接口的命令行实用程序。通过 ifconfig,你可以查看网络接口的状态、IP 地址、子网掩码等信息。以下是如何使用 ifconfig 查看网络接口的步骤:

  1. 打开终端(Terminal)。

  2. 输入以下命令并按 Enter 键:

    ifconfig
    
  3. 你将看到系统中所有活动的网络接口及其相关信息。输出结果类似于以下内容:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::a00:27ff:fe4e:66a1  prefixlen 64  scopeid 0x20<link>
            ether 08:00:27:4e:66:a1  txqueuelen 1000  (Ethernet)
            RX packets 1003456  bytes 123456789 (117.7 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 987654  bytes 987654321 (941.5 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 12345  bytes 123456 (120.4 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 12345  bytes 123456 (120.4 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    在这个例子中,有两个网络接口:eth0loeth0 是一个以太网接口,lo 是一个本地回环接口。

  4. 你可以查看特定网络接口的信息,例如 eth0,只需在 ifconfig 命令后添加接口名称:

    ifconfig eth0
    

请注意,在某些 Linux 发行版中(如 Ubuntu 18.04 及更高版本),ifconfig 可能已被弃用,建议使用 ip 命令替代。要使用 ip 命令查看网络接口,请输入以下命令:

ip addr show

0