温馨提示×

debian sedebian怎么配置网络

小樊
37
2026-10-11 00:29:35
栏目: 智能运维

你提到的“sedebian”应该是笔误,大概率是 Debian(或者你指的是 Raspberry Pi 上的 Raspberry Pi OS / Debian 系系统)。下面我按 Debian 系统配置网络 来说明,覆盖常见场景。


一、查看当前网络状态

ip a
ip route

或旧命令(部分系统仍可用):

ifconfig
route -n

二、使用 /etc/network/interfaces(传统方式,推荐服务器)

1️⃣ 配置静态 IP(有线网卡 eth0)

编辑:

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 114.114.114.114

重启网络:

sudo systemctl restart networking

或:

sudo ifdown eth0 && sudo ifup eth0

2️⃣ DHCP 自动获取 IP

auto eth0
iface eth0 inet dhcp

三、使用 Netplan(Debian 12+ / Ubuntu 风格)

如果你系统是 Debian 12 且使用 netplan:

sudo nano /etc/netplan/01-netcfg.yaml

示例(静态):

network:
  version: 2
  ethernets:
    eth0:
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 114.114.114.114]

应用配置:

sudo netplan apply

四、使用 NetworkManager(桌面版常见)

nmcli device status

设置静态 IP:

nmcli con mod eth0 ipv4.addresses 192.168.1.100/24
nmcli con mod eth0 ipv4.gateway 192.168.1.1
nmcli con mod eth0 ipv4.dns "8.8.8.8"
nmcli con mod eth0 ipv4.method manual
nmcli con up eth0

DHCP:

nmcli con mod eth0 ipv4.method auto
nmcli con up eth0

五、无线网络(Wi-Fi)

方法 1:nmcli

nmcli dev wifi list
nmcli dev wifi connect "SSID" password "密码"

方法 2:wpa_supplicant

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
network={
    ssid="你的WiFi"
    psk="密码"
}
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
dhclient wlan0

六、常见问题

✅ 无法上网:

ping 8.8.8.8
ping www.baidu.com

✅ DNS 不生效:

sudo nano /etc/resolv.conf
nameserver 8.8.8.8

如果你能确认一下:

  • 是 Debian 几?
  • 是 服务器还是树莓派 / 桌面?
  • 是有线还是无线?

我可以直接给你一份可直接复制用的配置文件。

0 踩