0

I have configured my network interfaces in my Ubuntu bionic (18.04) server using netplan, and afterwords I ran netplan apply and the configuration kicked in. In particular, I configured the DNS servers, and my server did resolved ips with the nameservers I configured in my netplan configuration.

But, after reboot, the configuration didn't last and any resolving was by default to the 127.0.0.53 nameserver. Only after running netplan apply the configuration kicked in again.

How can I make the netplan configuration persistent to reboots?

Output of cat /etc/*-release:

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Output of cat /etc/network/interfaces:

# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

My netplan yaml files:

10-nameservers.yaml:

network:
    version: 2
    ethernets:
        ens160:
            nameservers:
                addresses: [127.0.0.1]

50-cloud-init.yaml

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# 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:
    ethernets:
        ens160:
            addresses: []
            dhcp4: true
            dhcp-identifier: mac
    version: 2

interfaces_ens160.yaml

network:
  ethernets:
    ens160:
      addresses: [172.16.0.1/16]
      dhcp4: 'no'
      dhcp6: 'no'
      gateway4: 172.16.100.1
      nameservers:
        addresses: [10.0.0.8, 8.8.8.8, 10.15.0.18]
  version: 2
  • 1
    Is this a server or desktop installation? Edit your question and show me cat /etc/netplan/*.yaml and cat /etc/network/interfaces. Report back. – heynnema May 20 at 16:59
  • @heynnema Uploaded :) – Yuval Pruss May 20 at 18:35
  • You must have manually created two of the .yaml files, yes? Which ones? Does your ethernet connection need a static address, or is a dynamic address ok? Are you sure the gateway is correct for that static address? Where are DNS servers 10.0.0.8 and 10.15.0.18? – heynnema May 20 at 18:41
  • Yes, I created the interfaces_ens160.yaml and 10-nameservers.yaml... And my system demands an static IP. Both nameservers are needed... After running netplan apply this conf works perfectly, but when the server reboots, the conf doesn't seem to be applied... @heynnema – Yuval Pruss May 20 at 18:59
  • 1
    I'll need to write you a new .yaml file. But first, show me dpkg -l *dnsmasq* and ls -al /etc/resolv.conf` and cat /etc/resolv.conf. – heynnema May 20 at 19:08
1

You have conflicting .yaml files.

Rename all of the existing .yaml files

  • sudo mv /etc/netplan/10-nameservers.yaml /etc/netplan/10-nameservers.yaml.HOLD
  • sudo mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.HOLD
  • sudo mv /etc/netplan/interfaces_ens160.yaml /etc/netplan/interfaces_ens160.yaml.HOLD

Create a new .yaml file

  • sudo pico /etc/netplan/config.yaml with the following contents... with exact indentation, spacing, and no tabs...

network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
      addresses: [172.16.0.1/16]
      gateway4: 172.16.100.1
      nameservers:
        addresses: [10.0.0.8, 8.8.8.8, 10.15.0.18]

Generate new files

sudo netplan --debug generate # generate config files

sudo netplan apply # apply config

reboot # reboot the server

  • Not using netplan so can't comment on answer but, using sudo mv /etc/netplan/10-nameservers.yaml /etc/netplan/10-nameservers.yaml.HOLD in answer rather than human instructions "rename blah to blah" allows them to copy and paste from your answer direct to their terminal :) – WinEunuuchs2Unix May 20 at 19:49
  • @WinEunuuchs2Unix edits done. Thanks! – heynnema May 20 at 20:04
  • It does work, but my question is- why is my configuration, no differ then that, but in different files, doesn't work... It generates the same output from the systemd-resolve --status and after netplan apply the old configuration, so there is seems to be something I forget to apply or something after reboot? @heynnema – Yuval Pruss May 22 at 7:16
  • @YuvalPruss Your 3 .yaml files had conflicting instructions. ex: one had dhcp4 and the other had static addressing. – heynnema May 22 at 12:55
0

OK, it seems that in this ENV, the resolvconf rpm was installed and uninstalled, preserving the /etc/resolv.conf file. Deleting the file solved the issue.

  • If you deleted /etc/resolv.conf, you don't want to do that. It's required. You'll need to recreate the symlink. – heynnema May 22 at 12:57
  • Why it's required for netplan? – Yuval Pruss May 22 at 14:11
  • Because software uses that file to track DNS server addresses. It's actually a symlink to one of three possible other files on the system. Deleting this file solved what issue for you? – heynnema May 22 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.