Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Contenido

Set a static IP address on Ubuntu Server 17.10 and later.............................................2


Set a fixed IP address in NetPlan........................................................................................4
Apply changes.......................................................................................................................6

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

Contents of the 01-netcfg.yaml file .

In the case of Ubuntu Server, the default NetPlan configuration will be


like this:

network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes

Simply explained, what it establishes is that:

 the network administrator will be the systemd-networkd daemon


 the network adapter we are defining is enp0s3
 it will use DHCP

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:

sudo nano /etc/netplan/01-netcfg.yaml

We will include the network configuration values:

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: [192.168.1.10/24]: It establishes that the IP


address of the computer will be 192.168.1.10. It also indicates
that the netmask uses 24 bits (which is equivalent to
255.255.255.0 ).
 gateway4: 192.168.1.1: Determines that the gateway
address for TCP / IPv4.
 nameservers: Configure the Internet address (or addresses)
where the DNS server that we will use to convert domain names
into IP addresses is located.

If we need to define more than one DNS server, we can include


several addresses separated by commas:

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.

To overwrite, just press the key Intro .

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:

sudo netplan apply

We write the command and press the key Intro .

And finally, to check that the changes have taken effect, we can check
the current network configuration:

ip address show

You might also like