如何用ifconfig查看网络接口信息

作者:技术拾光时间:2026-08-17 09:22:31浏览:177

在Linux系统中,ifconfig命令用于查看网络接口状态、IP地址、子网掩码及MAC地址等详细信息。直接输入ifconfig可列出所有活动接口,如eth0和lo。也可用ifconfigeth0查看特定接口详情。该命令属于net-tools工具集,新发行版已弃用,推荐使用ipaddrshow替代,功能更强。

ifconfig 是 Linux 系统中常用的传统网络管理命令,主要用于查看和配置网络接口。通过执行该命令,可以快速查看当前系统中网卡的状态、IP 地址、子网掩码等关键信息。下面介绍具体操作方法。

如何用ifconfig查看网络接口信息

使用 ifconfig 查看网络接口信息

打开终端(Terminal)后,输入以下命令:

ifconfig

执行后,系统会显示当前所有活动网络接口及其详细信息。输出示例如下:

eth0: flags=4163mtu 1500
inet 192.168.1.100netmask 255.255.255.0broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe4e:66a1prefixlen 64scopeid 0x20
ether 08:00:27:4e:66:a1txqueuelen 1000(Ethernet)
RX packets 1003456bytes 123456789 (117.7 MiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 987654bytes 987654321 (941.5 MiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0

lo: flags=73mtu 65536
inet 127.0.0.1netmask 255.0.0.0
inet6 ::1prefixlen 128scopeid 0x10looptxqueuelen 1000(Local Loopback)
RX packets 12345bytes 123456 (120.4 KiB)
RX errors 0dropped 0overruns 0frame 0
TX packets 12345bytes 123456 (120.4 KiB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0

查看指定网络接口详情

在上述示例中,可以看到两个接口:eth0(以太网接口)和 lo(本地回环接口)。如果只想查看某一个网络接口的信息,例如 eth0,可以在命令后追加接口名称:

ifconfig eth0

新版本 Linux 的替代命令

需要注意的是,在较新的 Linux 发行版中,例如 Ubuntu 18.04 及更高版本,ifconfig 已经不再是更推荐的默认工具,通常建议使用 ip 命令来查看网络接口信息。使用方法如下:

ip addr show

以上就是通过 ifconfig 查看网络接口的方法。对于习惯传统命令的用户来说,ifconfig 依然直观易用;而在新系统中,ip 命令则是更常见的选择。