0

I use a ubuntu 18.04 LTS server, and I find the content of the yaml file in /etc/netplan is:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
      dhcp6: no

I want to set the dns server and gateway to my config,but still set the ip address using the dhcp, so is it possible to set the netplan as follow?

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
      dhcp6: no
      gateway4: 192.168.0.1
      nameservers:
        addresses:
            - 8.8.8.8
            - 9.9.9.9

Thanks in advance.

1

With netplan.io version 0.98 which is in bionic-updates, you can do this using the dhcp4-overrides section:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: yes
      dhcp4-overrides:
        use-dns: false
        use-routes: false
      gateway4: 192.168.0.1
      nameservers:
        addresses:
            - 8.8.8.8
            - 9.9.9.9
| improve this answer | |
  • Wonderful, excatly what I'm seeking. – sake Mar 31 at 8:24

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.