Ubuntu18.04以上设置DNS

问题:Ubuntu18.04上使用传统方式设置DNS未生效,直接ping IP可以通,ping 域名无法ping通。

auto ens33
iface ens33 inet static
address 192.168.32.10
netmask 255.255.255.0
gateway 192.168.32.2
dns-servernames 192.168.32.2

上面的DNS配置不生效。

正确DNS设置方法
1、编辑/etc/systemd/resolved.conf

sudo vim /etc/systemd/resolved.conf

[Resolve]
DNS=192.168.32.2
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes

2、保存退出后执行:

systemctl restart systemd-resolved.service

3、查看当前DNS设置

resolvectl status

Global
       LLMNR setting: no
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
  Current DNS Server: 192.168.32.2
         DNS Servers: 192.168.32.2
          DNSSEC NTA: 10.in-addr.arpa
                      16.172.in-addr.arpa
                      168.192.in-addr.arpa
                      17.172.in-addr.arpa
                      18.172.in-addr.arpa
                      19.172.in-addr.arpa
                      20.172.in-addr.arpa
                      21.172.in-addr.arpa
                      22.172.in-addr.arpa
                      23.172.in-addr.arpa
                      24.172.in-addr.arpa
                      25.172.in-addr.arpa
                      26.172.in-addr.arpa
                      27.172.in-addr.arpa
                      28.172.in-addr.arpa
                      29.172.in-addr.arpa
                      30.172.in-addr.arpa
                      31.172.in-addr.arpa
                      corp
                      d.f.ip6.arpa
                      home
                      internal
                      intranet
                      lan
                      local
                      private
                      test

Link 2 (ens33)
      Current Scopes: none
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: no
    DNSSEC supported: no

你可能感兴趣的:(Ubuntu18.04以上设置DNS)