Static IPs on Ubuntu 18.04 With Netplan

Aug 30, 2018 00:02 · 114 words · 1 minute read Static IP Ubuntu 18.04 netplan

  1. Create a copy of existing Netplan config
cd /etc/netplan/
sudo cp 50-cloud-init.yaml 90-custom.yaml
  1. Update 90-custom.yaml
network:
  version: 2
  ethernets:
    ens5:
      dhcp4: true #enable or disable dhcp for IPv4
      dhcp6: false #enable or disable dhcp for IPv6
      accept-ra: false #set to true to allow IPv6 to be configured automatically. Distinct setting from dhcp6.
      #Both DHCP and Static IPs can be enabled at the same time!
      addresses: [<IPv4 Address>/20, '<IPv6 Address>/128'] 
      gateway4: <IPv4 Gateway>
      #IPv6 route might differ depending on cloud vendor. Check ip -6 route to get the actual route used via DHCP6/RA first
      gateway6: 'fe80::1'
      nameservers:
       addresses: [<DNS1>, <DNS2>]
  1. Apply changes
sudo netplan apply
  1. Confirm changes
ip -4 addr show
ip -6 addr show