在 Debian 系统中,ifconfig 属于 net-tools 工具包,而现代 Debian 默认更倾向于使用 ip 命令(来自 iproute2)。下面分情况说明如何在 Debian 中使用 ifconfig。
先确认 ifconfig 是否可用:
ifconfig
如果提示:
bash: ifconfig: command not found
说明 net-tools 未安装。
sudo apt update
sudo apt install net-tools
安装完成后即可使用:
ifconfig
ifconfig -a
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
现代 Debian 建议使用 ip 命令替代 ifconfig:
ip addr
sudo ip link set eth0 up
sudo ip link set eth0 down
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1
ifconfig 和 ip 命令 重启后失效,永久配置请编辑:
sudo nano /etc/network/interfaces
示例(DHCP):
auto eth0
iface eth0 inet dhcp
示例(静态 IP):
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
然后重启网络:
sudo systemctl restart networking
| 场景 | 建议 |
|---|---|
| 临时调试 | ip 或 ifconfig |
| 永久配置 | /etc/network/interfaces |
| 新系统 | 优先使用 ip 命令 |
如果你告诉我 Debian 版本(如 10 / 11 / 12)或 服务器/桌面环境,我可以给你更精确的配置方案。