Ubuntu 18.04 LTS Server - Configure Static IP Addresses

Posted on wednesday, 13 of June of 2018
1245by Octávio Gonçalveslinuxsetupsecuritycommand line

The network configuration was severely changed on Ubuntu 18.04.

On Ubuntu 18.04 we now have Netplan. Have you heard of NetPlan?
Probably not, if you have, then you’re a step ahead of many.
NetPlan is a new network configuration tool introduced in Ubuntu 17.10 to manage network settings.

It can be used write simple YAML description of the required network interfaces with what they should be configured to do; and it will generate the required configuration for a chosen renderer tool.

This new tool replaces the static interfaces (/etc/network/interfaces) file that had previously been used to configure Ubuntu network interfaces. Now you must use /etc/netplan/*.yaml to configure Ubuntu interfaces.

The new interfaces configuration file now lives in the /etc/netplan directory. There are two renderers. NetworkManager and networkd.

NetworkManager renderer is mostly used on desktop computers and networkd on servers. If you want NetworkManager to control the network interfaces, use NetworkManager as the renderer, otherwise use networkd.

When you use NetworkManager as the renderer, you will use the NetworkManager GUI to manage the interfaces.

Below is a sample file for a network interface using networkd as renderer using DHCP. Networkd uses the command line to configure the network interfaces.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
dhcp6: yes

To save your changes, you run the commands below.

sudo netplan apply

Configuring Static IP Addresses with Networkd

To configure a static IP address using the new NetPlan tool, the file should look like this: IPv4 address (192.168.1.2), Gateway (192.168.1.1), DNS Servers (8.8.8.8,8.8.4.4)

Run the commands below to create a new network configuration file

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

Then configure IPv4 addresses as shown below.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [192.168.1.2/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]

Exit and save your changes by running the commands below.

sudo netplan apply

You can add IPv6 addresses line, separated by a comma.. example below.

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [192.168.1.2/24, '2001:1::2/64']
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]

Save your changes, apply and you’re done.

This is how to set static IP addresses on Ubuntu 18.04 Server.

Ifconfig command is changed also.

Like Netplan, the ifconfig comand is deprecated, and has been so for quite a number of years.
The new kid in town is the ip command, which can configure IP's, routes, and everything associated with networks.

You can install ifconfig with sudo apt install net-tools, if you absolutely need to have it.
If not, start learning ip.

Examples to use ip:

ip link show
ip address show

That's it. Happy Networking.

Share or save this article

slashdot