我安装了 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 statusnetworking.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
答案1
编辑你的/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
答案2
- write under::
auto wlp2s0
allow-hotplug wlp2s0
iface wlp2s0 inet dhcp
address 10.0.0.163
netmask 255.255.255.0
broadcast 10.0.0.255
gateway 10.0.0.1
################################################
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf# or your wpa conf file path
#or
wpa-ssid "home-network-ssid"
wpa-psk "secret-key"
################################################
你可以看看
- $ 人机接口
- $ 人 ifcfg
- $ 人 ifconfig