I've seen some people saying the file to set static ip is still /etc/network/interfaces

And I've seen other people saying that in 18.04 it's now on /etc/netplan (which people seem unhappy about)

I've tried to say it

version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.1.9/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [192.168.1.1, 8.8.8.8, 8.8.4.4]

In my /etc/netplan/50-cloud-init.yaml and doing sudo netplan apply but that just kills the servers connection to the internet.

Best Answer


All the answers telling you to directly edit /etc/netplan/50-cloud-init.yaml are wrong since CloudInit is used and will generate that file. In Ubuntu 18.04.2 it is clearly written inside the file .

$ cat /etc/netplan/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:
        eno1:
            dhcp4: true
    version: 2

So you should not edit that file but the one under /etc/cloud/cloud.cfg.d/ if you still want to use CloudInit.

Another way is to completely disable CloudInit first by creating an empty file /etc/cloud/cloud-init.disabled (see https://cloudinit.readthedocs.io/en/latest/topics/boot.html ) and then the other answers are OK. Under Ubuntu 18.04.2 I had to use dpkg-reconfigure cloud-init to let it take into account the file /etc/cloud/cloud-init.disabled . I think this is a little weird

I suggest you to rename the file (not the right name since 50-cloud-init.yaml let us think it still uses CloudInit).

Then you may end up with a file name /etc/netplan/01-netcfg.yaml which contains the configuration below. Note the use of the networkd renderer instead of NetworkManager because the configuration is on a server.

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: no
      addresses: [192.168.1.246/24]
      gateway4: 192.168.1.1
      nameservers:
         addresses: [192.168.1.1]