Configure Static IP Addresses On Ubuntu Server 18.04 LTS via netplan

This short post about configure netplan config on Ubuntu 18.04

The first thing I noticed was how different it handles network interfaces. The way Ubuntu manages network interfaces has completely changed. NetPlan is a new network configuration tool introduced in Ubuntu 17.10 to manage network settings. More about Netplan on official website

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.

Default configuration file 50-cloud-init.yaml


# 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
            optional: true
    version: 2
        

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

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.56.102)

Run the commands below to create a new network configuration file


            sudo nano /etc/netplan/01-netcfg.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:
        enp0s8:
            addresses: [192.168.56.102/24]
            dhcp4: false
            optional: false
    version: 2
        

Exit and save your changes by running the commands below (Ctrl+O and Ctrl+X)


sudo netplan apply
        

Congratulations! You’ve just successfully configured static IP addresses on Ubuntu servers. You can check this, follow command


$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe14:73e3  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:14:73:e3  txqueuelen 1000  (Ethernet)
        RX packets 318  bytes 311538 (311.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 136  bytes 15518 (15.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.102  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fe3f:9ac7  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:3f:9a:c7  txqueuelen 1000  (Ethernet)
        RX packets 298  bytes 33385 (33.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 257  bytes 39440 (39.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 96  bytes 7260 (7.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 96  bytes 7260 (7.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                

Enjoy!

2018-06-02 16:54:40