How to Set a Static IP Address in Ubuntu 18.04 Bionic Beaver

Make your networking changes in /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg. For example:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
     dhcp4: no
     addresses: [192.168.1.100/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [192.168.1.1,1.1.1.1,8.8.8.8]

Then:

sudo cloud-init clean
sudo cloud-init init
sudo netplan apply

If you have multiple network cards and only one of them is connected, you can set the unused card as optional so that the system doesn’t wait for a long time for it to come up at boot. For example:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
     dhcp4: yes
     optional: true
    enp2s0:
     dhcp4: no
     addresses: [192.168.1.100/24]
     gateway4: 192.168.1.1
     nameservers:
       addresses: [192.168.1.1,1.1.1.1,8.8.8.8]
comments powered by Disqus