Whlie creating a new template for Ubuntu 18.04, I stumbled across something I didn't expect.
At the end of the template creation process, I usually comment the used IP addresses (to avoid human mistake when someone powers up the template with network card enabled). So I wanted to configure /etc/network/interfaces, as always. But:
root@ubuntu1804:~# cat /etc/network/interfaces
root@ubuntu1804:~#
Umm... the config file is empty. Huh? What's going on?
But during the setup I defined a static IP (10.10.4.44)?
root@ubuntu1804:~# 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: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:8d:5c:45 brd ff:ff:ff:ff:ff:ff
inet 10.10.4.44/24 brd 194.40.217.255 scope global ens192
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe8d:5c45/64 scope link
valid_lft forever preferred_lft forever
Yep, the static IP is configured. Where the hell is this stored now?
root@ubuntu1804:~# grep -rni 10.10.4.44 /etc/*
/etc/hosts:2:10.10.4.44 ubuntu1804.nzzmg.local ubuntu1804
/etc/netplan/01-netcfg.yaml:8: addresses: [ 10.10.4.44/24 ]
/etc/netplan? Never heard of it...
Let's check out this config file (which is written in YAML format):
root@ubuntu1804:~# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
ens192:
addresses: [ 10.10.4.44/24 ]
gateway4: 10.10.4.44.1
nameservers:
search: [ example.com ]
addresses:
- "1.1.1.1"
- "8.8.8.8"
OK, doesn't look that complicated and is quite understandable. Important here is also the "renderer". According to the documentation, this refers to the network daemon reading the netplan config file:
"Netplan reads network configuration from /etc/netplan/*.yaml which are written by administrators, installers, cloud image instantiations, or other OS deployments. During early boot, Netplan generates backend specific configuration files in /run to hand off control of devices to a particular networking daemon."
The Ubuntu default is to hand off control to networkd, which is part of the SystemD jungle:
root@ubuntu1804:~# ps auxf|grep networkd
systemd+ 750 0.0 0.1 71816 5244 ? Ss 13:27 0:00 /lib/systemd/systemd-networkd
root 930 0.0 0.4 170424 17128 ? Ssl 13:27 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher
So if I change the IP address to something else, how does one apply the new IP and will it be immediate?
root@ubuntu1804:~# ip address show ens192
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:8d:5d:37 brd ff:ff:ff:ff:ff:ff
inet 10.10.4.44/25 brd 10.150.2.127 scope global ens192
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe8d:5d37/64 scope link
valid_lft forever preferred_lft forever
root@ubuntu1804:~# sed -i "s/10.10.4.44/10.150.2.98/g" /etc/netplan/01-netcfg.yaml
root@ubuntu1804:~# netplan apply
# [ Note: Here my SSH session got disconnected - so yes, IP change was immediate ]
admck@ubuntu1804:~$ ip address show ens192
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:8d:5d:37 brd ff:ff:ff:ff:ff:ff
inet 10.150.2.98/25 brd 10.150.2.127 scope global ens192
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe8d:5d37/64 scope link
valid_lft forever preferred_lft forever
Right after "netplan apply", the IP was changed. I lost my SSH connection (of course) and could log back in using the new IP. So yes, IP change was immediate.
I just wonder how often I will still use "vi /etc/network/interfaces" as this has been stuck in my head for more than 10 years. Old habits die hard.
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder