在较新的 Linux 发行版中,ifconfig 命令默认可能未安装,因为它属于 net-tools 工具包,而许多系统已转向使用 ip 命令(来自 iproute2)。以下是开启/使用 ifconfig 的方法:
which ifconfig
或
ifconfig
如果提示 command not found,说明未安装。
sudo apt update
sudo apt install net-tools
sudo yum install net-tools
或(CentOS 8+)
sudo dnf install net-tools
sudo pacman -S net-tools
sudo zypper install net-tools
安装完成后即可使用:
ifconfig
查看网卡信息:
ifconfig eth0
启用/禁用网卡:
sudo ifconfig eth0 up
sudo ifconfig eth0 down
ip addr
ip link
启用网卡:
sudo ip link set eth0 up
如果你是在 容器(Docker) 或 最小化系统 中,也可能无法直接使用 ifconfig,可以告诉我你的系统版本,我可以给你更精确的步骤。