Set A Static IP Address On Ubuntu Server 17
Set A Static IP Address On Ubuntu Server 17
1
Set a static IP address on Ubuntu
Server 17.10 and later
Until now, Ubuntu server based its network configuration on
parameters stored in the /etc/network/interfaces configuration
file, a structure inherited directly from Debian .
However, as of version 17.10, Canonical introduces a new network
configuration tool called NetPlan, which aims to facilitate the work of
developers and users in general.
The operation of NetPlan is based on a file with the description of the
network adapters that we need to define. The file will be written in
YAML ( YAML Ain't Markup Language ), a plain text file with a specific
format for serialization that is easily understood by people.
Therefore, as of version 17.10, we must use configuration files with the
yaml extension, stored in the /etc/netplan path .
By default, we only have one file, called 01-netcfg.yaml .
2
NetPlan Initial Configuration
To check the initial value of the 01-netcfg.yaml file, just write a
command like this:
cat /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
3
Set a fixed IP address in NetPlan
We must edit the corresponding configuration file (in our example, 01-
netcfg.yaml ) and make the appropriate modifications. To achieve
this, you can use the nano text editor:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [208.67.222.222]
The lines that appear under dhcp4: no, set the static values we
need:
addresses: [208.67.222.222,208.67.220.220]
4
When we have completed the configuration, we are ready to exit
editing the file.
To achieve this, we just have to press the Control + key combination X.
When doing so, the editor asks us if we want to save the changes.
To answer affirmatively, we press the key S.
5
Apply changes
Back at the system prompt, we are ready to apply the configuration file
changes. Something that we can achieve by executing the following
command:
And finally, to check that the changes have taken effect, we can check
the current network configuration:
ip address show