在 Debian 系统中,ifconfig 属于 net-tools 工具包,用来查看和临时配置网络接口。需要注意:
ifconfig 设置是临时的,重启后失效ip 命令或改 /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
sudo ifconfig eth0 broadcast 192.168.1.255
sudo ifconfig eth0 mtu 1400
ifconfig 不能设置默认网关,需用 route 或 ip:
sudo route add default gw 192.168.1.1
或用 ip 命令(推荐):
sudo ip route add default via 192.168.1.1
编辑:
sudo 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
重启网络:
sudo systemctl restart networking
Debian 10+ 更推荐:
ip addr show
ip addr add 192.168.1.100/24 dev eth0
ip link set eth0 up
如果你告诉我:
我可以给你精确配置命令。