Setting a static IP on Ubuntu 18.04 server

I notice you guys are using Ubuntu 18.04 server, so you may have already solved this. But it took me forever to figure out how to set a static IP. It’s different than 16.04 or 14.04.

You edit a file called /etc/netplan/01-netcfg.yaml and put in whatever static IP information is right for your server.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:       (or whatever your interface is called)
      dhcp4: no
      addresses: [192.168.1.19/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [192.168.1.1]

Then you run this command

sudo netplan apply

I hope this has been helpful!

2 Likes

Thanks!

Where were you three weeks ago when I was trying to figure this out ? :slight_smile:

Something else that tripped me up is that the file you edit can’t have tabs, only spaces. Or else you will get an error when you do netplan apply.

1 Like

Same thing happened to me.

1 Like

Thank’s.
you saved me life with this tutorial.