温馨提示×

ifconfig怎样查看网络接口状态

小樊
39
2025-12-26 16:34:01
栏目: 编程语言

ifconfig 是一个用于配置和显示 Linux 内核中网络接口的命令行实用程序。要使用 ifconfig 查看网络接口状态,请按照以下步骤操作:

  1. 打开终端(Terminal)。

  2. 输入以下命令,然后按 Enter 键:

ifconfig

这将显示系统中所有活动网络接口的详细信息,包括 IP 地址、子网掩码、广播地址等。输出示例:

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 1003421  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 64  bytes 5760 (5.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 64  bytes 5760 (5.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

在这个示例中,eth0 是一个活动的网络接口,其状态为 UP,BROADCAST,RUNNING,MULTICAST。这意味着该接口已启动、可以接收广播消息、正在运行并支持多播。

如果要查看特定网络接口的状态,可以在 ifconfig 命令后指定接口名称,例如:

ifconfig eth0

这将仅显示 eth0 接口的详细信息。请注意,根据您的 Linux 发行版和网络配置,您可能需要使用 ip addr 命令替代 ifconfig

0