Linux

Debian WIFI 網路不可用無法連接到網際網路

  • February 16, 2021

我安裝了 debian 9,一切正常——我能夠發現周圍的網路並連接到網際網路。當我決定嘗試通過更改此文件從通過 DHCP 自動分配 IP 地址更改為靜態 IP 時,問題就來了/etc/network/interfaces。意識到重啟後我無法連接到網際網路,我嘗試“修復”這個以及我不記得的其他“修復”,現在文件看起來像這樣:

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback
auto enp0s31f6
allow-hotplug enp0s31f6

iface enp0s31f6 inet dhcp

auto wlp2s0
allow-hotplug wlp2s0
iface wlp2s0 inet dhcp

**EDIT**
address 10.0.0.163
netmask 255.255.255.0
gateway 10.0.0.1

這是輸出ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
   inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
   inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
   link/ether 14:b3:1f:17:c8:36 brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
   link/ether f8:59:71:a6:57:4d brd ff:ff:ff:ff:ff:ff

最後這是我從 sudo systemctl status networking.service 得到的

networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor 
preset: enabled)
Active: active (exited) since Tue 2017-09-26 12:23:50 EAT; 34s ago
Docs: man:interfaces(5)
Process: 5293 ExecStop=/sbin/ifdown -a --read-environment --exclude=lo    (code=exited, status=0/SUCCESS)

Process: 5419 ExecStart=/sbin/ifup -a --read-environment (code=exited,     status=0/SUCCESS)

Process: 5413 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ]          && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle (code=exited, status=0/SUCCESS)

Main PID: 5419 (code=exited, status=0/SUCCESS)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/networking.service
      ├─5473 /sbin/dhclient -4 -v -pf /run/dhclient.enp0s31f6.pid -lf   /var/lib/dhcp/dhclient.enp0s31f6.leases -I -df /var/lib/dhcp/dhclient6.enp0s31f6.leases enp0s31f6
      └─5581 /sbin/dhclient -4 -v -pf /run/dhclient.wlp2s0.pid -lf /var/lib/dhcp/dhclient.wlp2s0.leases -I -df /var/lib/dhcp/dhclient6.wlp2s0.leases wlp2s0

編輯您/etc/network/interfaces的如下:

auto lo
iface lo inet loopback

為您的乙太網介面配置靜態 IP:dhcpcd 方法

安裝dhcpcd

sudo apt install dhcpcd5

編輯您的/etc/dhcpcd.conf文件:

sudo nano /etc/dhcpcd.conf

經過以下幾行:

# define static profile 
profile static_enp0s31f6 
static ip_address=10.0.0.163 /24 
static routers=10.0.0.1 
static domain_name_servers=10.0.0.1 

# fallback to static profile on enp0s31f6 
interface enp0s31f6 
fallback static_enp0s31f6

然後禁用dhcpcd守護程序:

sudo update-rc.d -f dhcpcd remove

啟用網路:

sudo systemctl enable networking 

重啟然後執行:

sudo iptables -t nat -A POSTROUTING -o enp0s31f6 -j MASQUERADE
sudo dhcpcd

Archlinux 維基 dhcpcd

引用自:https://unix.stackexchange.com/questions/394498