Ubuntu 18.x/20.x – netplan to set static IP address
- July 23rd, 2021
- Posted in Documentation
- Write comment
Here we go again. A completely different way to configure the network using netplan. I used the following on an Ubuntu 18.x LTS server to configure the static IP address:
$ cd /etc/netplan
If this directory, there will be a yaml file. I have seen this have a couple different names, but it has always been the only file in the directory. In this case, the file was named: 00-installer-config.yaml
If you brought the machine using DHCP, you need to change the “dhcp4: yes” line to “dhcpv: no”. Below, is an example setting the IP address, mask via the CIDR designation (subnet bits) after the IP address, the gateway, the nameservers and a search domain.
Note: the format (indentation) of the lines in the file are important.
$ sudo vi 00-installer-config.yaml
…
network:
ethernets:
ens160:
dhcp4: no
addresses: [aaa.bbb.ccc.ddd/mm]
gateway4: eee.fff.ggg.hhh
nameservers:
addresses: [www.xxx.yyy.zzz, mmm.nnn.ooo.ppp]
search: [my.domain, my.otherdomain]
version: 2
For Ubuntu 20.x:
network:
ethernets:
ens32:
addresses:
– aaa.bbb.ccc.ddd/mm
gateway4: eee.fff.ggg.hhh
nameservers:
addresses:
– www.xxx.yyy.zzz
– mmm.nnn.ooo.ppp
search:
– my.domain
version: 2
Note: Make sure you do the following from the console, if modifying the IP address.
Apply the configuration:
$ sudo netplan apply
No comments yet.