在 CentOS 中,ifconfig
是一个用于配置和显示网络接口的命令行工具
- 查看所有网络接口及其状态:
ifconfig
- 查看特定网络接口的状态(例如,查看名为
eth0
的接口):
ifconfig eth0
- 查看 IP 地址和子网掩码:
ifconfig eth0 | grep 'inet '
- 查看广播地址:
ifconfig eth0 | grep 'broadcast'
- 查看网络接口的 MAC 地址:
ifconfig eth0 | grep 'ether'
- 添加一个新的网络接口(例如,添加名为
eth1
的接口):
sudo ifconfig eth1 up
- 配置静态 IP 地址(例如,为
eth1
接口配置 IP 地址192.168.1.10
和子网掩码255.255.255.0
):
sudo ifconfig eth1 192.168.1.10 netmask 255.255.255.0
- 禁用网络接口(例如,禁用
eth1
接口):
sudo ifconfig eth1 down
- 启用网络接口(例如,启用
eth1
接口):
sudo ifconfig eth1 up
- 删除网络接口(例如,删除
eth1
接口):
sudo ifconfig -d eth1
请注意,CentOS 7 及更高版本中的网络管理工具已从 ifconfig
更改为 ip
。在这些系统上,您需要使用 ip
命令进行网络诊断。