在CentOS(以及其他Linux发行版)中,ifconfig
命令用于配置、激活和查询网络接口参数。它允许用户查看当前系统的网络接口状态,如IP地址、子网掩码、广播地址等,并可以进行一些基本的网络配置。
以下是ifconfig
命令的一些常用选项和功能:
ifconfig
:显示所有网络接口的详细信息。ifconfig <interface>
:显示指定网络接口的信息,例如ifconfig eth0
。ifconfig <interface> <ip_address> netmask <subnet_mask>
:设置IP地址和子网掩码。ifconfig <interface> up
:激活网络接口。ifconfig <interface> down
:关闭网络接口。ifconfig <interface> <ip_address> del
:从指定网络接口删除IP地址。ifconfig -a
:显示所有网络接口,包括未激活的。ifconfig -s
:显示每个网络接口的统计信息。ifconfig <interface> hw ether <mac_address>
:设置网络接口的MAC地址。假设你想为以太网接口eth0
设置IP地址192.168.1.100
,子网掩码为255.255.255.0
,并激活该接口,可以使用以下命令:
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
ifconfig
命令可能已被ip
命令取代,后者提供了更强大的功能和更好的兼容性。例如,使用ip addr add 192.168.1.100/24 dev eth0
来添加IP地址。sudo
)。总之,ifconfig
是一个非常有用的工具,可以帮助你管理和诊断网络接口的问题。