目标是为名为 的机器上的 wifi 设备设置静态 IP我的主机,它运行的是 Ubuntu 18.04 LTS。设备名称是wlp1s0,所需的 IP 地址是192.168.1.10。所有尝试都失败了。
步骤顺序:
1)识别ip:
$ ip route
default via 192.168.1.254 dev wlp1s0 proto dhcp metric 600
169.254.0.0/16 dev wlp1s0 scope link metric 1000
192.168.1.0/24 dev wlp1s0 proto kernel scope link src 192.168.1.154 metric 600
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.254 0.0.0.0 UG 600 0 0 wlp1s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 wlp1s0
192.168.1.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp1s0
2)检查/etc/resolv.conf
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver 127.0.0.1
search attlocal.net
3)关闭设备
sudo ip link set down
4)编辑/etc/网络/接口
编辑版本:
cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto wlp1s0
iface wlp1s0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.254
5) 编辑/etc/主机
编辑版本:
cat /etc/hosts
127.0.0.1 localhost
192.168.1.10 myhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::6 ip6-allnodes
ff02::2 ip6-allrouters
192.168.1.180 mysystem.mydomain
6) 恢复设备:
sudo ip link set wlp1s0 up
7) 重启机器
reboot
重启后
$ ip route
default via 192.168.1.254 dev wlp1s0 onlink linkdown
169.254.0.0/16 dev wlp1s0 scope link metric 1000 linkdown
192.168.1.0/24 dev wlp1s0 proto kernel scope link src 192.168.1.10 linkdown
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 wlp1s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 wlp1s0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp1s0
$ dmesg | grep wlp1s0
[ 37.095682] iwlwifi 0000:01:00.0 wlp1s0: renamed from wlan0
[ 38.911441] IPv6: ADDRCONF(NETDEV_UP): wlp1s0: link is not ready
尝试将名称服务器添加到/etc/网络/接口:
cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto wlp1s0
iface wlp1s0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.254
dns-nameservers 192.168.1.254
那没有工作。
这里缺少什么?
答案1
对于上面提到的 Ubuntu 18.04,Netplan 似乎是前进的方向。
有多种有用的资源:https://netplan.io/examples/特别是对于您的特定情况,以下配置可能会起作用:
network:
version: 2
wifis:
wlp1s0:
dhcp4: no
addresses: 192.168.1.10
gateway4: 192.168.1.254
nameservers:
addresses: [8.8.8.8]
access-points:
"network_ssid_name":
password: "**********"
请注意,缩进非常重要,如果缩进不正确,配置将无法工作。
/etc/netplan
将上述配置添加到继续运行时找到的yaml文件中sudo netplan --debug apply
。
此命令将提供有关出现问题的信息,否则它将重新启动您的网络。