在 Debian 系统中,网络配置方式取决于你使用的 Debian 版本 以及是否使用 桌面环境 / 服务器环境。下面按常见场景详细说明。
ip a
ip route
查看网卡名称(如 eth0、ens33、wlan0)。
/etc/network/interfaces
auto eth0
iface eth0 inet dhcp
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
注意:把
eth0换成你的实际网卡名
systemctl restart networking
或:
ifdown eth0 && ifup eth0
apt update
apt install network-manager
systemctl enable NetworkManager
systemctl start NetworkManager
nmcli device
nmcli device connect eth0
nmcli con add type ethernet con-name static-eth0 ifname eth0
nmcli con modify static-eth0 ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8"
nmcli con up static-eth0
systemctl enable systemd-networkd
systemctl start systemd-networkd
/etc/systemd/network/20-wired.network
[Match]
Name=eth0
[Network]
DHCP=yes
[Match]
Name=eth0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
systemctl restart systemd-networkd
apt install wpasupplicant
wpa_passphrase SSID 密码 > /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
echo "nameserver 8.8.8.8" > /etc/resolv.conf
/etc/systemd/resolved.conf
或写在 /etc/network/interfaces:
dns-nameservers 8.8.8.8 114.114.114.114
ip a
ping 8.8.8.8
ping www.baidu.com
journalctl -u networking
dmesg | grep eth
| 场景 | 推荐方式 |
|---|---|
| Debian 桌面 | NetworkManager |
| Debian 服务器 | /etc/network/interfaces 或 systemd-networkd |
| 云服务器 | DHCP + systemd-networkd |
如果你愿意,可以告诉我:
我可以给你一份完全适配你环境的配置示例。