Linux ifconfig命令详解

ifconfig 是 Linux 中常用的网络配置命令,可以用于查看和设置网络接口的配置信息,如 IP 地址、子网掩码、MAC 地址等。下面是 ifconfig 命令的使用详解。

查看所有网络接口的信息:

ifconfig

该命令会显示所有网络接口的详细信息,包括接口名称、IP 地址、MAC 地址、MTU 等。

查看指定网络接口的信息:

ifconfig eth0

该命令会显示指定网络接口 eth0 的详细信息。

启用或禁用指定网络接口:

ifconfig eth0 up
ifconfig eth0 down

第一条命令会启用 eth0 网络接口,第二条命令会禁用 eth0 网络接口。

配置指定网络接口的 IP 地址:

ifconfig eth0 192.168.1.100

该命令会将 eth0 网络接口的 IP 地址设置为 192.168.1.100。

配置指定网络接口的子网掩码:

ifconfig eth0 netmask 255.255.255.0

该命令会将 eth0 网络接口的子网掩码设置为 255.255.255.0。

配置指定网络接口的广播地址:

ifconfig eth0 broadcast 192.168.1.255

该命令会将 eth0 网络接口的广播地址设置为 192.168.1.255。

配置指定网络接口的 MAC 地址:

ifconfig eth0 hw ether 00:11:22:33:44:55

该命令会将 eth0 网络接口的 MAC 地址设置为 00:11:22:33:44:55。

修改指定网络接口的 MTU:

ifconfig eth0 mtu 1500

该命令会将 eth0 网络接口的 MTU 设置为 1500。

除了上述常用的命令,ifconfig 还可以用于设置其他的网络参数,如设置多播地址、修改 TTL 等。但是由于 Linux 系统中已经逐渐使用 ip 命令来代替 ifconfig 命令,因此建议使用 ip 命令来进行网络配置。