Linux – Removing the default DNS servers from ubuntu server 20.04

domain-name-systemlinuxlinux-networkingUbuntuubuntu-20.04

I have an ubuntu 20.04 server and I want to change its DNS settings. The server is using netplan and cloud-init.

I disabled cloud-init network configuraion by creating /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg file with the following content:

network: {config: disabled}

There is an automatically generated /etc/netplan/50-cloud-init.yaml with the following content (I've added the nameservers section by myself):

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        ens3:
            dhcp4: true
            match:
                macaddress: fa:16:3e:d9:e5:96
            mtu: 1458
            set-name: ens3
            addresses: [192.168.0.48/24]
            gateway4: 192.168.0.1
            nameservers:
                addresses: [178.22.122.100, 185.51.200.2]

And Just to make sure nothing overrides these settings, I created a copy of the 50-cloud-init.yaml file, named 60-change-dns.yaml in the /etc/netplan/ directory with the following content:

network:
    version: 2
    ethernets:
        ens3:
            dhcp4: true
            match:
                macaddress: fa:16:3e:d9:e5:96
            mtu: 1458
            set-name: ens3
            addresses: [192.168.0.48/24]
            gateway4: 192.168.0.1
            nameservers:
                addresses: [178.22.122.100, 185.51.200.2]

Then I ran sudo netplan apply command and everything seemed to be working fine. To check if the name servers have changed, I executed sudo resolvectl status and here is the output (the interesting part):

Link 2 (ens3)
      Current Scopes: DNS           
DefaultRoute setting: yes           
       LLMNR setting: yes           
MulticastDNS setting: no            
  DNSOverTLS setting: no            
      DNSSEC setting: no            
    DNSSEC supported: no            
  Current DNS Server: 178.22.122.100
         DNS Servers: 178.22.122.100
                      185.51.200.2  
                      8.8.8.8       
                      8.8.4.4       
          DNS Domain: openstacklocal

What the hell are 8.8.8.8 and 8.8.4.4 in the DNS server list? They were there by default and my purpose was not to add two more DNS servers on top of them. I wanted to completely replace them with my own custom DNS servers.

How do I remove 8.8.8.8 and 8.8.4.4 from the DNS server list?

Best Answer

dhcp4: true

change to dhcp4: false. It's picking up the Google DNS servers from your DHCP server (probably router), and you have a static ip config.

Related Topic