In this lecture, I'll show you how to statically configure a network interface. Typically laptops 1
and desktops have their IP address assigned dynamically by a DHCP server which is in most cases 2
the router. 3
However, a server requires a static configuration to avoid the single point of failure problem of using 4
DHCP server. 5
Since the release of Ubuntu 17.10, NetPlan is the default network configuration tool to 6
manage networks. 7
It uses yaml files that are located in /etc/netplan Netplan currently supports to renderers 8
or backend services to control network interfaces on Ubuntu based systems. 9
NetworkManager and Systemd- 10
networkd. The Network Manager is mostly used on desktop machines while systemd -networkd is used 11
on servers without a GUI. 12
When used network manager as the renderer or backend service, 13
you'll use the network manager graphical user interface to manage the interfaces. In this lab 14
if you're running Ubuntu in a VM in virtual box, set the network into bridge mode so that Ubuntu has direct 15
access to the LAN. 16
Go to networks, network settings 17
and here, select Attached to Bridge Adapter 18
It;'s like a stand alone machine connected to the LAN. 19
Let's see how to set up a static IP address using the network manager renderer. 20
To set up a static IP address on Ubuntu desktops, click on the network icon in the top menu, here, 21
then select Wired Connections 22
wired settings and then click this icon! 23
Go to IPv6 or IPv4 depending on the protocol version your LAN is using and choose Manual 24
for IPv4 to set a static IP. Write the IP address, the network mask, the gateway, the DNS servers, 25
and when you are ready, you just click apply. 26
It's really simple! 27
Let's move ahead and see how to configure the network interface on a server if there is no GUI available 28
using the systemd, the networkd renderer. The first step is to disable the network manager. 29
The network interface can be managed either by network manager or by networkd, but not by both of them 30
at the same time. I'm becoming route: sudo su . I am route. 31
I'm stopping network manager: systemctl stop NetworkManager It was stopped; I'm disabling network 32
manager so that it won't start after the system restarts. 33
And I'll check its status! 34
It's inactive and to check if it will start at boot time run: systemctl is-enabled 35
NetworkManager 36
Use the correct spelling, OK, and it is disabled. 37
The next step is to create a yaml file in /etc/netplan 38
And if you don't use the network manager renderer anymore 39
my advice is to remove the existing yaml file for a network manager that exists in in /etc/netplan 40
That file could interfere with your static configuration. 41
So vim/etc/netplan and the file name, you can name it something like a 01-netconfig. 42
yaml 43
Inside the file, I'll paste some lines. 44
Let me explain to you the configuration you are seeing! Each Netplan Yaml file starts with the network 45
keyword 46
and then at least three required elements: the version of the network configuration format, which is 2, 47
the renderer, which is networkd and the device type, which in this case is ethernets 48
But if you use a wireless card, there will be WiFis. Under the device’s type (in this case ethernets), 49
you specify one or more network interfaces. 50
My Linux VM has only one interface called enp0s3 that will be statically configured. 51
So DHCP will be false. 52
Then I specify the IP address, the default gateway and the name servers. 53
Take this file as an example and use it in your own LAN, changing it accordingly. You'll find 54
attached as resource to this lecture. 55
I'm saving the file; if you want to configure the network interface using the DHCP, then you can only 56
write dhcp4: true under the name of the interface; 57
so under enp0s3 58
You'll end up with something similar to this. 59
When you are done editing the YAML file, save it and exit . To apply the changes run as route 60
netplan apply. 61
To verify the changes run if config 62
and we see the new IP address that was statically configured and route-n to see that the default gateway 63
And we see that the changes were applied. 64
Let's open again the yaml configuration file. 65
This one! Yaml uses two spaces for indentation, if you are not consistent, you'll get a syntax 66
error. 67
For example, if I add only one space here, the Yaml file will have errors; I'm saving the file and 68
executing netplan apply again. 69
And there is an error! I'll make it right again. 70
There are some good online yaml validators, if you have errors and do not know exactly where they 71
are. 72
This is, for example, a good one. 73
I'm copying the contents of the file and paste it in the validator. 74
I'm clicking validate, and it's a valid YAML file, but this one is not a valid. 75
Anyway, I'll attached more examples to this lecture so you can see yaml configuration files for netplan 76
for many situations, including how to configure wifi networks.