如何使用 netplan config 在 kubuntu 20.04 上设置自定义 DNS 服务器并使用 DHCP?

如何使用 netplan config 在 kubuntu 20.04 上设置自定义 DNS 服务器并使用 DHCP?

好吧,这很令人困惑,所以这里有一个清晰的版本来说明发生了什么。如果我使用以下配置和静态 IP 地址,我只能使用 /etc/netplan/01-network-manager-all.yaml 设置自定义 DNS 服务器:

d@a:~$ more /etc/netplan/01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  wifis:
    wlp3s0:
      dhcp4: false
      addresses: [10.0.0.49/24]
      gateway4: 10.0.0.1   
      access-points:
        accesspointename:
          password: passwordgoeshere
      nameservers:
        addresses: [8.8.4.4,8.8.8.8,1.1.0.0,1.1.1.1]

上述配置有效,网络管理器在发出后重新启动 sudo netplan --debug apply,创建了一个新的连接,其名称与我原来的接入点相同,但前面加上了 netplan-wlp3s0。

我不想使用静态 IP 地址。当我尝试以下配置来设置自定义 DNS 服务器并启用 DHCP 时。没有创建新连接,原始连接具有服务提供商 DNS 服务器。

d@a:~$ more /etc/netplan/01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  wifis:
    wlp3s0:
      dhcp4-overrides:
        use-dns: no
      access-points:
        accesspointname:
          password: passwordgoeshere
      nameservers:
        addresses: [8.8.4.4,8.8.8.8,1.1.0.0,1.1.1.1]

d@a:~$ sudo netplan --debug apply
** (generate:11280): DEBUG: 22:03:24.251: Processing input file /etc/netplan/01-network-manager-all.yaml..
** (generate:11280): DEBUG: 22:03:24.251: starting new processing pass
** (generate:11280): DEBUG: 22:03:24.251: wlp3s0: adding wifi AP 'accesspointname'
** (generate:11280): DEBUG: 22:03:24.252: We have some netdefs, pass them through a final round of validation
** (generate:11280): DEBUG: 22:03:24.252: wlp3s0: setting default backend to 2
** (generate:11280): DEBUG: 22:03:24.252: Configuration is valid
** (generate:11280): DEBUG: 22:03:24.252: Generating output files..
** (generate:11280): DEBUG: 22:03:24.252: networkd: definition wlp3s0 is not for us (backend 2)
(generate:11280): GLib-DEBUG: 22:03:24.252: posix_spawn avoided (fd close requested) 
DEBUG:no netplan generated networkd configuration exists
DEBUG:netplan generated NM configuration changed, restarting NM
DEBUG:wlp3s0 not found in {}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets: {}
  vlans: {}
  wifis:
    wlp3s0:
      access-points:
        accesspointname:
          password: passwordgoeshere
      dhcp4-overrides:
        use-dns: false
      nameservers:
        addresses:
        - 8.8.4.4
        - 8.8.8.8
        - 1.1.0.0
        - 1.1.1.1

DEBUG:Skipping non-physical interface: lo
DEBUG:Skipping non-physical interface: enp0s25
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp0s25
DEBUG:netplan triggering .link rules for wlp3s0

如何保持 DHCP 开启并使用自定义 DNS 服务器?

谢谢

相关内容