How to change static ip address on Ubuntu server 18.04

0
(0)

Canonical has changed the way we configure static IPs in Ubuntu.

Ubuntu Server requires editing a .yaml file (complete with proper adherence to correct code indent for each line of the block), in order to configure your IP addressing.

The new method

Open up a terminal window on your Ubuntu 18.04 server (or log in via secure shell). Change into the /etc/netplan directory with the command cd /etc/netplan. Issue the command ls and you should see a file named 50-cloud-init.yaml. If you don’t also see a file named 01-netcfg.yaml, create it with the command sudo touch 01-netcfg.yaml. Before we edit that file, we need to know the name of our networking interface. Issue the command ip a and you should see your system network interface listed by name

root@live:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:00:28:47 brd ff:ff:ff:ff:ff:ff
    inet xx.xx.xx.xx/27 brd xxx.xxx.xxx.xxx scope global dynamic ens32
       valid_lft 27835sec preferred_lft 27835sec
    inet6 fe80::250:56ff:fe00:2847/64 scope link
       valid_lft forever preferred_lft forever

Now we’re going to create a new netplan configuration file. If you don’t see the 01-netcfg.yaml file, create one with the command sudo nano 01-netcfg.yaml. Our file is going to look like that which you see in

network:
    version: 2
    renderer: networkd
    ethernets:
      ens32: 
        dhcp4: no
        addresses: [192.168.1.206]
        gateway4: 192.168.1.254
        nameservers:
          addresses: [8.8.8.8,8.8.4.4]

What’s crucial about the layout of this file is not using the exact same spacing as my example, but that you’re consistent. If you’re not consistent with your indents, the file will not work. What you see in that sample file is all you need to configure that static IP address. Do notice, you aren’t setting the address is the same fashion as you did with Ubuntu 16.04. With the old method, you set IP address and netmask like so:

address = 192.168.1.206
netmask = 255.255.255.0

With netplan, these are set with a single line:

addresses : [192.168.1.206/24]

Restarting/testing networking

With the new method, you must restart networking using netplan. So once you’ve configured your interface, issue the command:

sudo netplan apply

The above command will restart networking and apply the new configuration. You shouldn’t see any output. If networking fails to function properly, you can issue the command:

sudo netplan --debug apply

That’s all there is to it

There ya go. That’s all there is to configuring a static IP address in Ubuntu Server 18.04. Remember, you’ll have to do this for each interface you have on your server. Make sure to name the files something like 01-netcfg.yaml and 02-netcfg-yaml. It’s not terribly difficult, once you’re used to not working with that old-school interfaces file.

Similar Posts:

2,408

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Scroll to Top