在 Debian(以及大多数 Linux 发行版)中,ifconfig 属于 net-tools 工具包,主要用于查看和临时配置网络接口。需要注意的是:
ifconfig 设置的网络参数是临时的,重启后会失效ip 命令或 NetworkManager / systemd-networkd / /etc/network/interfaces下面按常见场景说明。
sudo apt update
sudo apt install net-tools
ifconfig
或只看某个接口:
ifconfig eth0
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
ifconfig 不能设置默认网关,需要用 route 或 ip:
sudo route add default gw 192.168.1.1
或使用推荐方式:
sudo ip route add default via 192.168.1.1
sudo ifconfig eth0 down
sudo ifconfig eth0 hw ether 00:11:22:33:44:55
sudo ifconfig eth0 up
/etc/network/interfacessudo nano /etc/network/interfaces
示例(静态 IP):
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
应用配置:
sudo systemctl restart networking
nmtui
或:
nmcli connection modify eth0 ipv4.addresses 192.168.1.100/24
nmcli connection modify eth0 ipv4.gateway 192.168.1.1
nmcli connection modify eth0 ipv4.method manual
nmcli connection up eth0
| 功能 | ifconfig | 推荐方式 |
|---|---|---|
| 查看接口 | ✅ | ip addr |
| 临时 IP | ✅ | ip addr add |
| 网关 | ❌ | ip route |
| 永久配置 | ❌ | interfaces / NetworkManager |
如果你告诉我:
我可以给你更精确的配置示例。