在 Debian 中,设置 IP 地址的方式取决于 Debian 版本 以及你使用的是 传统 ifconfig + 手动配置 还是 现代网络管理方式(如 ip 命令、NetworkManager、/etc/network/interfaces)。
下面分情况说明:
⚠️
ifconfig属于net-tools,新版本 Debian 可能默认未安装
安装:sudo apt install net-tools
ifconfig -a
或
ip addr
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
sudo route add default gw 192.168.1.1
或
sudo ip route add default via 192.168.1.1
临时 DNS(重启会丢):
sudo nano /etc/resolv.conf
添加:
nameserver 8.8.8.8
/etc/network/interfaces(服务器常用)编辑:
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
或
sudo ifdown eth0 && sudo ifup eth0
ip 命令(代替 ifconfig,推荐)sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set eth0 up
sudo ip route add default via 192.168.1.1
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.dns 8.8.8.8
nmcli connection modify eth0 ipv4.method manual
nmcli connection up eth0
sudo apt install net-tools
✅ 使用 ip 命令
✅ 使用 /etc/network/interfaces 或 NetworkManager
如果你告诉我:
我可以给你精确命令。