网卡命令
ifup / ifdown
- 功能:启用或关闭网络接口。
- 依赖配置文件:在 RHEL/CentOS 系统,读取 /etc/sysconfig/network-scripts/ifcfg-*。
用法:
ifup eth0 # 启用 eth0
ifdown eth0 # 关闭 eth0
限制:如果没有写配置文件,会提示 not configured,所以更偏向于系统初始化/脚本使用。
2. ifconfig
功能:查看和配置网络接口(老工具,来自 net-tools)。
sudo yum install net-tools # CentOS 7
sudo dnf install net-tools # CentOS 8 / Fedora
典型操作:
ifconfig # 显示所有网卡信息
ifconfig eth0 up # 启用 eth0
ifconfig eth0 down # 关闭 eth0
ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up # 临时配置 IP
如果你不想装 net-tools
,直接用 iproute2
提供的命令:
查看所有网卡和 IP 地址:
ip addr show
# 或简写
ip a
查看网卡链路状态:
ip link show
启动/关闭网卡:
ip link set eth0 up
ip link set eth0 down