How do I configure networking in Ubuntu 18.04?

How do I configure networking in Ubuntu 18.04?

Ubuntu 18.04 has changed from using the interfaces file config to using Netplan


This uses YAML based configuration files to configure the network interfaces.

Here is an example of the YAML config I created for setting a static IP

ftp@ftpserver:/etc/netplan$ cat config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
      addresses:
        - 10.101.24.81/22
      gateway4: 10.101.24.1
      nameservers:
          search: [localhost]           
          addresses: [8.8.8.8]

Here is an example of a DHCP config


network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true


Once your config is done, you can apply it with

  1. sudo netplan apply