Setup Fixed / Static IP Addresses on Ubuntu 18.04 / 18.10 Systems

By now you’ve probably heard of NetPlan, the new interface configuration file for Ubuntu starting with 17.10.. If you haven’t, then you behind with the latest Ubuntu updates….

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 is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
    version: 2

To save your changes, you run the commands below.

sudo netplan apply

Configuring Static IP Addresses with Networkd (Server)

To configure a static IP address using the new NetPlan tool on Ubuntu server, the file should look similar to the content below…

For example you might find a default netplan configuration file in the /etc/netplan directory called 50-cloud-init.yaml with a following content using the networkd deamon to configure your network interface via DHCP…..

sudo nano /etc/netplan/50-cloud-init.yaml

Then file should look like this one below:

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
    version: 2

The above is a default networkd rendenrer configuration file for a Ubuntu server using DHCP IP configuration…. If you want to set up a static IP address, configure the file as shown below

sudo nano /etc/netplan/50-cloud-init.yaml

Then configure IPv4 addresses as shown below… take notes of the format the lines are written…

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: [192.168.1.2/24]
            gateway4: 192.168.1.1
            nameservers:
              addresses: [8.8.8.8,8.8.4.4]
            dhcp4: no
    version: 2

Exit and save your changes by running the commands below

sudo netplan apply

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

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: [192.168.1.2/24]
            gateway4: 192.168.1.1
            nameservers:
              [192.168.1.2/24, '2001:1::2/64']
            dhcp4: no
    version: 2

Save and apply your changes…

sudo netplan apply
sudo netplan --debug apply

This is how to set static IP addresses on Ubuntu 18.04 and 18.10 server and desktop… .

For more about NetPlan, visit this site.

Configure Network Interfaces with NetworkManager (Desktop)

On Ubuntu desktop, you can access the default network configuration file using the commands below:

sudo nano /etc/netplan/01-network-manager-all.yaml

Then sample configuration file looks like the one below… and the default renderer will be NetworkManager… If NetworkManager is the redenerer, then you’ll have to use the desktop Network tool (GUI) to configure the network interface….

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

To configure Ubuntu desktop network interface, click on the System Menu at the top right corner and select System Settings…

ubuntu dns change

Then go and click Network on the left to open the panel.

In the left pane, select the network connection that you want to set up manually. If you plug in to the network with a cable, click Wired, then click the settings button in the lower right corner of the panel. For a Wi-Fi connection, the settings button will be located next to the active network.

ubuntu manual network settings

Click on IPv4 or IPv6 in the left pane and change the Addresses to Manual. Type in the IP Address and Gateway, as well as the appropriate Netmask.

ubuntu network settings

In the DNS section, switch Automatic to OFF. Enter the IP address of a DNS server you want to use. Enter additional DNS server addresses using the + button.

In the Routes section, switch Automatic to OFF. Enter the AddressNetmaskGateway and Metric for a route you want to use. Enter additional routes using the + button.

Click Apply.

If you are not connected to the network, click the system status area on the top bar and connect… Test the network settings by trying to visit a website or look at shared files on the network, for example.

That’s it!

Congratulations! You’ve just successfully configured static IP addresses on Ubuntu servers and desktops

Enjoy!~

You may also like the post below:

How to Disable or Turn Off Lock Screen on Ubuntu 18.04 / 18.10 Desktop

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.