Ubuntu 18.04 – Setup Network on Secondary Interface

linux-networkingnetplannetworkingubuntu-18.04

I've got a VM running Ubuntu 18.04 – it's all setup and running on a single public IP and has two interfaces – ens160 (public) & ens192 (private).

My interface ens160 is already fully configured. However, when I try and setup ens192 and apply the settings with netplan apply, ens160 stops pinging externally.

ifconfig –

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 78.111.203.13  netmask 255.255.255.224  broadcast 78.111.203.31
        inet6 fe80::250:56ff:feb2:ac74  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:b2:ac:74  txqueuelen 1000  (Ethernet)
        RX packets 8761053  bytes 3882588408 (3.8 GB)
        RX errors 0  dropped 242551  overruns 0  frame 0
        TX packets 10449256  bytes 4654699595 (4.6 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::250:56ff:feb2:3d74  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:b2:3d:74  txqueuelen 1000  (Ethernet)
        RX packets 242552  bytes 14553120 (14.5 MB)
        RX errors 0  dropped 227391  overruns 0  frame 0
        TX packets 7256  bytes 2349506 (2.3 MB)
        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 9194  bytes 2309681 (2.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9194  bytes 2309681 (2.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Here's the configuration file 50-cloud-init.yaml I'm attempting below –

network:
    ethernets:
        ens160:
            addresses:
            - 78.111.203.13/27
            gateway4: 78.111.203.1
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
            optional: true
        ens192:
            addresses: 
            - 10.0.203.13/27
            gateway4: 10.0.203.1
            optional: true
    version: 2

As soon as I run netplan try, I can no longer ping my external IP 78.111.203.13 until the timeout and the network resets itself. Interestingly though, I can still ping the external IP from other VM's within the network – I'm not sure if that means anything?

The newly configured internal IP also begins pinging within the network – what I'd expect.

I hope you can help!

Chris.

Best Answer

The problem is almost certainly related to you attempting to set a default gateway on the secondary interface.

It is important to always remember that the default gateway isn't really a property of an individual interface instead it is a route added to the route table. The 'default gateway' is the route that is used when no other more specific routes do not match a given destination. If you attempt to add two default gateways with the same metric, only one or the other will work.