在 Debian(以及大多数 Linux 发行版)中,ifconfig 是用于查看和配置网络接口的传统命令。不过需要注意:新版本 Debian 默认可能未安装 ifconfig,更推荐使用 ip 命令。
下面分几个部分说明。
ifconfig
如果提示:
command not found
说明没有安装,可用以下命令安装:
sudo apt update
sudo apt install net-tools
ifconfig
或只看启用的接口:
ifconfig -a
输出示例:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>
inet 192.168.1.10 netmask 255.255.255.0
inet6 fe80::20c:29ff:fe...
ifconfig eth0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
⚠️ 重启后失效(临时配置)
sudo route add default gw 192.168.1.1
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
sudo ifconfig eth0 promisc
sudo ifconfig eth0 -promisc
Debian 官方更推荐 ip 命令:
ip addr show
ip link set eth0 up
ip addr add 192.168.1.100/24 dev eth0
ifconfig 只能临时配置,永久配置用:
编辑:
/etc/network/interfaces
如果你愿意,可以告诉我:
cat /etc/debian_version)我可以给你更精确的命令。