This is how we solved the “new” netplan network stuff in Ubuntu 18.04 LTS.

When installing the default 18.04 iso things suddenly feels strange if your an old Ubuntu server admin..
All kind of new stuff with networking like netplan, yaml, cloud-init, networkd etc.

And instead of going old shcool and removing all the new “features” we tried to use them as much as possible. :)

First thing that made me wondering was how to set a good old static ip on a nic..

Here comes netplan in play. And this is my “mental notes on netplan in Ubuntu 18.04”

Show ip address:

dude@smegol:~$ ip addr

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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:86:d3:e6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe86:d3e6/64 scope link 
       valid_lft forever preferred_lft forever

Show nic settings:

dude@smegol:~$ sudo ethtool enp0s3

Settings for enp0s3:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Supported FEC modes: Not reported
	Advertised link modes:  10baseT/Half 10baseT/Full 
	                        100baseT/Half 100baseT/Full 
	                        1000baseT/Full 
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Speed: 1000Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: off (auto)
	Supports Wake-on: umbg
	Wake-on: d
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

Temporary set ip on nic:

dude@smegol:~$ sudo ip addr add 192.168.1.0/24 dev enp0s3

Temporary delete ip on nic:

dude@smegol:~$ sudo ip addr del 192.168.1.0/24 dev enp0s3

Set static ip on nic:

dude@smegol:~$ sudo vim /etc/netplan/99_config.yaml 

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      addresses:
        - 192.168.1.10/24
      gateway4: 192.168.1.1
      nameservers:
          search: [example.com, net.example.com, srv.example.com]
          addresses: [192.168.1.2, 192.168.1.3]

And then disable cloud-init with:

dude@smegol:~$ sudo touch /etc/cloud/cloud-init.disabled

And to try out the settings before restarting:

dude@smegol:~$ sudo netplan apply --debug

Error in network definition //etc/netplan/99_config.yaml line 0 column 0: unknown key SuperERrorHEre

Change hostname with hostnamectl:

dude@smegol:~$ sudo hostnamectl

   Static hostname: broekn-lab
         Icon name: computer-vm
           Chassis: vm
        Machine ID: ffffffffffffffffffffffffffffffff
           Boot ID: ffffffffffffffffffffffffffffffff
    Virtualization: oracle
  Operating System: Ubuntu 18.04 LTS
            Kernel: Linux 4.15.0-23-generic
      Architecture: x86-64

dude@smegol:~$ sudo hostnamectl set-hostname broekn-lab

dude@broekn-lab:~$ sudo hostnamectl
   Static hostname: broekn-lab
         Icon name: computer-vm
           Chassis: vm
        Machine ID: fffffffffffffffffffffffffffffff
           Boot ID: fffffffffffffffffffffffffffffff
    Virtualization: oracle
  Operating System: Ubuntu 18.04 LTS
            Kernel: Linux 4.15.0-23-generic
      Architecture: x86-64