February 25, 2020

Ubuntu 18 guest OS with two network interfaces: bridge, host only

Ubuntu 18 with two network interfaces:

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.95  netmask 255.255.255.0  broadcast 192.168.1.255

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.99.95  netmask 255.255.255.0  broadcast 192.168.99.255


enp0s3 is bridge network, enp0s8 is host only.


$ sudo vi /etc/netplan/50-cloud-init.yaml

network:
    ethernets:
        enp0s3:
            addresses: [192.168.1.95/24]
            gateway4: 192.168.1.1
            dhcp4: no
            nameservers:
                addresses: [192.168.1.1]
            optional: true
        enp0s8:
            addresses: [192.168.99.95/24]
            dhcp4: no
            nameservers:
                addresses: [192.168.99.1]
            optional: true
            routes:
            - to: 192.168.99.0/16
              via: 192.168.99.1

    version: 2


$ sudo netplan apply

There should be only one gateway.


UPDATE-20200307:

Why two adapters for VM?
1. faster - traffic doesn't go through the router.
2. since it's not going through the router, even when your router is down or has a problem, you can still access VMs.

No comments: