ifconfig
是一个用于配置和显示 Linux 内核中网络接口的命令行实用程序。虽然 ifconfig
在许多 Linux 发行版中仍然可用,但它在某些发行版中已被 ip
命令取代。不过,你仍然可以使用 ifconfig
来查看网络连接状态。
要使用 ifconfig
查看网络连接状态,请按照以下步骤操作:
打开终端(Terminal)。
输入以下命令并按 Enter 键:
ifconfig
这将显示系统上所有活动网络接口的详细信息。输出可能类似于以下内容:
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 524288 (512.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64 bytes 524288 (512.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
在这个例子中,你可以看到两个网络接口:eth0
和 lo
。eth0
是一个以太网接口,它的 IP 地址是 192.168.1.100,子网掩码是 255.255.255.0,广播地址是 192.168.1.255。lo
是一个本地回环接口,用于测试本地网络连接。
要查看特定网络接口的状态,只需在 ifconfig
命令后添加接口名称,例如:
ifconfig eth0
这将仅显示 eth0
接口的详细信息。请注意,如果你的系统上没有安装 ifconfig
,你可能需要使用包管理器(如 apt
、yum
或 pacman
)安装它。在某些发行版中,你可以使用 ip addr
命令代替 ifconfig
。