我刚刚首次安装 Ubuntu,我想为我的电脑设置一个固定 IP 地址,作为通过 ssh 从外部连接的第一步。我在路由器中找不到将 IP 地址与 MAC 地址关联的菜单,因此我改为/etc/netplan我看到一个名为的文件01-网络管理器-全部.yaml其中包含:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
我将其附加到包含以下内容:
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
wifis:
wlp5s0:
addresses: [192.168.0.100/24]
dhcp4: no
gateway4: 192.168.0.1
access-points:
sparrow:
password: my password
接下来我运行:
ian@sparrow:~$ sudo netplan --debug apply
** (generate:2459): DEBUG: 08:03:58.881: Processing input file //etc/netplan/01-network-manager-all.yaml..
** (generate:2459): DEBUG: 08:03:58.881: starting new processing pass
** (generate:2459): DEBUG: 08:03:58.881: wlp5s0: adding wifi AP 'sparrow'
** (generate:2459): DEBUG: 08:03:58.881: wlp5s0: setting default backend to 2
** (generate:2459): DEBUG: 08:03:58.882: Generating output files..
** (generate:2459): DEBUG: 08:03:58.882: networkd: definition wlp5s0 is not for us (backend 2)
DEBUG:no netplan generated networkd configuration exists
DEBUG:netplan generated NM configuration exists, restarting NM
DEBUG:replug enp4s0: unbinding 0000:04:00.0 from /sys/bus/pci/drivers/r8169
DEBUG:replug enp4s0: rebinding 0000:04:00.0 to /sys/bus/pci/drivers/r8169
DEBUG:replug wlp5s0: unbinding 0000:05:00.0 from /sys/bus/pci/drivers/iwlwifi
DEBUG:replug wlp5s0: rebinding 0000:05:00.0 to /sys/bus/pci/drivers/iwlwifi
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo
ian@sparrow:~$
我不确定该如何理解这个输出。
为了查看发生了什么,我重新启动并运行:
ian@sparrow:/etc/netplan$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether b0:6e:bf:0a:9a:5d brd ff:ff:ff:ff:ff:ff
3: wlp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:e1:8c:7f:10:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.102/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp5s0
valid_lft 86003sec preferred_lft 86003sec
inet6 fe80::1d31:c36:616f:422c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ian@sparrow:/etc/netplan$
这表明我让 Ubuntu 请求 192.168.0.100/24 的尝试失败了。
如何修复我的机器的 LAN IP?
按照如下所述生成 01-networkd.yaml 后,我运行知识产权我得到:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
link/ether b0:6e:bf:0a:9a:5d brd ff:ff:ff:ff:ff:ff
3: wlp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:e1:8c:7f:10:48 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.102/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp5s0
valid_lft 86003sec preferred_lft 86003sec
inet6 fe80::1d31:c36:616f:422c/64 scope link noprefixroute
valid_lft forever preferred_lft forever
ian@sparrow:/etc/netplan$
更正:输出自sudo netplan--debug 生成是:
Processing input file //etc/netplan/01-networkd.yaml..
starting new processing pass
wlp5s0: adding wifi AP 'sparrow
enp4s0: setting default backend to 1
wlp5s0: setting default backend to 1
Generating output files..
NetworkManager: definition enp4s0 is not for us (backend 1)
wlp5s0: Creating wpa_supplicant configuration file run/netplan/wpa-wlp5s0.conf
Creating wpa_supplicant service enablement link /run/systemd/system/multi-user.target.wants/[email protected]
NetworkManager: definition wlp5s0 is not for us (backend 1)
答案1
如果必须使用Netplan
...
消除/etc/netplan/01-network-manager-all.yaml
创造/etc/netplan/01-networkd.yaml
...
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
dhcp4: true
optional: true
wifis:
wlp5s0:
addresses: [192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [192.168.0.1, 8.8.8.8]
access-points:
"sparrow":
password: "**********"
sudo netplan --debug generate
sudo netplan apply
reboot
如果您决定继续使用 NetworkManager...
删除所有不必要的 .yaml 文件/etc/netplan
创造/etc/netplan/01-network-manager-all.yaml
...
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
sudo netplan --debug generate
sudo netplan apply
reboot
连接到所需的无线网络。
断开无线网络。
在 ( 中编辑这些设置18.04.1) 无线配置文件...
更新#1:
- 添加了 enp4s0 LAN 连接的代码
- 添加重启
- 添加了有关使用 NetworkManager 的信息