Configuring Static IP Addresses on Ubuntu 17.10 Servers

Ubuntu 17.10 network configuration is completely changed. Have you heard of NetPlan? Probably not, but 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 by writing a 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.

This brief tutorial is going to show students and new users how to use NetPlan to set a static IP address on Ubuntu servers. This should be easy and quick.

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 redenrer configuration file for a Ubuntu server using DHCP IP configuration…. If you want to setup 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 your changes, apply and you’re done.

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 NetPlay, visit this site.

 

Congratulations! You’ve just successfully configured static IP addresses on Ubuntu 17.10 servers.

Enjoy!~

You may also like the post below:

Install VMware Tools on VMware Workstation Ubuntu 17.10 Guest

23 Replies to “Configuring Static IP Addresses on Ubuntu 17.10 Servers

  1. What was wrong with using the /etc/network/interfaces file? Using YAML is the dumbest thing I’ve ever seen. I mean really…. this does not improve anything, and adds to the confusion. No we have to adhere to the stupid YAML format… counting spaces… counting spaces…. and counting more spaces…. dumb dumb dumb!

    1. Generally I agree, however there were a lot of shortcomings in the /etc/network/interfaces methods, involving various hacks (policy based routing, bridge configuration, etc), and this (like systemd) is just another thing we have to swallow. At least there are benefits from this.

      YAML is stupid as a human editable configuration file. It’s not as bad a json though.

  2. How about if I want to configure nameservers while using dhcp configuration?

    I am using ubuntucore.
    I tried adding nameservers entry in the config file but that doesn’t seem to work. resolv.conf always gets overwritten on reboots. I disabled systemd-resolved and still no luck. updating any file (for example /etc/resolvconf/resolv.conf.d/base, /etc/dhcp/dhclient.conf) is also not possible since it’s a read-only file system.

    any help with that?

  3. THANK YOU THANK YOU THANK YOU. I spent hours messing with /etc/network/interfaces before I finally found this!

  4. Another year, yet another way to configure networking in Linux. Wish you would all just pick something and stick to it

    1. /etc/network/interfaces has been the way to configure networks for as far back as I started using debian – version 2.2 in 2000. One change after 20 years isn’t terrible.

  5. Agree, not sure what the value is here. Just because you can doesn’t always mean you should. YAML has it’s place but I’m not sure using it to configure your NICs is a good fit.

  6. How about setting 17.10 server with static wlan address ? I have managed to do configuration file without dns server, but when i add dns servers, it goes broken.. i really dont know where to put them and how.. resolv.conf works until next reboot ..

  7. This change aligns with other industry standards – you may complain but down the track you will see the benefit unless you are narrow minded. Change happens always get use to it. Almost 30 years in the industry and I am still learning. Fantastic !

  8. I still wonder why people always use stock images of Mac’s when referencing more specifically Ubuntu. Theres planty of images of computers running Linux, much less Ubuntu.

    Great article though, just nitpicking!

  9. Sorry, you may not like XML but i’ts better for this kind of thing. yaml is not easy to catch spacing errors as their not visible.
    Font’s will be critical when editing. yaml validator is an excellent tool, but it’s not available to offline systems.
    And not easy to add as a software tool either.
    I hope ubuntu considers making the validator a default tool on all installations if their sticking with it.
    I vote to either go back or use XML.

    1. XML is idiotic. YAML is slightly less idiotic.

      Plain static text files are the best possible way to configure anything.

  10. how to set static ip with dns from dhcp, the systemd-networkd equivalent is
    iface eth1 inet dhcp
    post-up addr add 192.0.2.200 dev eth0

  11. If anyone is using mc and the internal edit feature of that program, do not use ‘tab’ for indents when creating your YAML file. This will result in an error when you try to apply the config. Instead, use spaces (single, double, triple, etc.). This may be obvious to some, but it caused me some grief.

  12. Thank you for the write up. Only thing I found is for whatever reason, netplan did not like a the space in between my dsn severs, so just had to user a comma:
    network:
    ethernets:
    eno3:
    addresses: [172.22.7.175/22]
    dhcp4: no
    gateway4: 172.22.4.1
    nameservers:
    addresses: [8.8.8.8,172.22.0.16]
    version: 2

  13. This is idiotic.

    Sometimes I feel like these bozos just like changing things for no other reason than to change them. I was just done getting pissed off over systemd-resolved, and now this.

    Static text file configuration is one of the things I love about Linux. I feel like Ubuntu’s server edition hit the sweet spot with 14.04 LTS. Sure, it wasn’t pure init based, but upstart was way better than systemd, and ifupdown is key. Every release since has just been step after step in the wrong direction.

    I have a bunch of servers still running 14.04 LTS I’ve been procrastinating updating. I may just move them to 16.04 LTS and stay there until support ends in 2021. If I do go with 18.04, I’ll probably wind up uninstalling netplan, and reinstalling ifupdown. I wish I could get rid of systemd-resolved too.

    Long term I don’t know what the solution is. Even once conservative Debian has been making lots of stupid changes lately, so moving there is not really an option. Maybe it’s time to move to BSD? O_o

  14. You have got to be kidding. This is AWFUL. This is exactly why I moved some of my servers to FreeBSD.

    Linux really has no business even being called “UNIX-like” at this point. I don’t know what you would call it, but every iteration gets worse than the last.

Leave a Reply to Eric Cancel 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.

%d bloggers like this: