Find the default network configuration file:
$ ls /etc/netplan/
50-cloud-init.yaml
Check the contents of the file:
$ cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource. Changes to it will not persist acress 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:
eth0:
addresses: []
dhcp4: true
optional: true
eth1:
addresses: []
dhcp4: true
optional: true
version: 2
As seen, this server has two network cards, namely eth0 and eth1. Both are configured to use DHCP.
Let us configure the static IP addresses to both network cards. Open the network configuration file:
$ sudo vim /etc/netplan/50-cloud-init.yaml
network:
ethernets:
eth0:
addresses: [172.16.0.2/16]
gateway4: 172.16.0.1
dhcp4: no
nameservers:
addresses: [1.1.1.1,1.0.0.1]
optional: true
eth1:
addresses: [10.0.0.2/8]
gateway4: 10.0.0.1
dhcp4: no
nameservers:
addresses: [1.1.1.1,1.0.0.1]
optional: true
version: 2
DON'T use TABs as they won't work in Ubuntu 18.04. Use spaces to align all lines.
Apply the network configuration using command:
$ sudo netplan apply
If there are issues, check them with
$ sudo netplan --debug apply
Check the network configuration:
$ ip addr