Linux – NetPlan Interface Configuration

Just added a second NIC to a Linux-VM…

  • new config-style – new luck ūüôā
administrator@lx-ubuntu:/etc/netplan$ cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

Ok, it seems to be easy to get back to good-old network-config-style.

But after reading https://netplan.io/examples this seems to be very handy.

The initial „netplan-file“ references only the initial NIC:

administrator@lx-ubuntu:~$ cd /etc/netplan/
administrator@lx-ubuntu:/etc/netplan$ cat 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:
        enp0s3:
            addresses: []
            dhcp4: true
    version: 2

What’s the ID of the new NIC?

  • it’s „enp0s8“
administrator@lx-ubuntu:/etc/netplan$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.104  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fe37:dbef  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:37:db:ef  txqueuelen 1000  (Ethernet)
        RX packets 989  bytes 119568 (119.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 704  bytes 105969 (105.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.3.15  netmask 255.255.255.0  broadcast 10.0.3.255
        inet6 fe80::a00:27ff:fe8d:ab00  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:8d:ab:00  txqueuelen 1000  (Ethernet)
        RX packets 2  bytes 1180 (1.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5  bytes 944 (944.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2032  bytes 123200 (123.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2032  bytes 123200 (123.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Create a backup

administrator@lx-ubuntu:/etc/netplan$ sudo cp 50-cloud-init.yaml 50-cloud-init.yaml.bak

Modify the Netplan-File:

administrator@lx-ubuntu:/etc/netplan$ sudo vi 50-cloud-init.yaml

administrator@lx-ubuntu:/etc/netplan$ cat 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:
        enp0s3:
            addresses: []
            dhcp4: true
        enp0s8:
            addresses: []
            dhcp4: true
    version: 2

Activate the new Config:

administrator@lx-ubuntu:/etc/netplan$ sudo netplan apply

Verify the result

administrator@lx-ubuntu:/etc/netplan$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.104  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fe37:dbef  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:37:db:ef  txqueuelen 1000  (Ethernet)
        RX packets 989  bytes 119568 (119.5 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 704  bytes 105969 (105.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.3.15  netmask 255.255.255.0  broadcast 10.0.3.255
        inet6 fe80::a00:27ff:fe8d:ab00  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:8d:ab:00  txqueuelen 1000  (Ethernet)
        RX packets 2  bytes 1180 (1.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5  bytes 944 (944.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 2032  bytes 123200 (123.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2032  bytes 123200 (123.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Schreibe einen Kommentar