0

I'd want to setup a very "simple" configuration in a guest Ubuntu Server 18.04 LTS under KVM:

  • a lan NIC interface, handled by DHCP, able to receive some static routing rules from DHCP and some local DNS resolution in a 'local' domain

  • a NAT outbound access to internet via a different interface managed with DHCP, with DNS public resolution

In the host (Ubuntu Desktop) in KVM, i've defined two networks, both enabled for DHCP:

  • 'default' as NAT
  • 'public1' as routed

In the host, internet access is configured with NetworkManager for a wifi connection.

In the guest, I have defined two NIC, handled by DHCP on both networks.

With this setup, The guest OS obtains two "default" gateway, with routing ambiguity that cause internet connectivity problems.

# at guest
route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.122.1   0.0.0.0         UG    100    0        0 ens5
0.0.0.0         192.168.200.1   0.0.0.0         UG    100    0        0 ens4
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 ens5
192.168.122.1   0.0.0.0         255.255.255.255 UH    100    0        0 ens5
192.168.200.0   0.0.0.0         255.255.255.0   U     0      0        0 ens4
192.168.200.1   0.0.0.0         255.255.255.255 UH    100    0        0 ens4


In the host, KVM network configuration:

<network>
  <name>default</name>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

<network>
  <name>public1</name>
  <forward mode='route'/>
  <bridge name='virbr2' stp='on' delay='0'/>
  <domain name='pub.local.net'/>
  <ip address='192.168.200.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.200.128' end='192.168.200.254'/>
    </dhcp>
  </ip>
  <route address='192.168.210.0' prefix='24' gateway='192.168.200.1' metric='3040'/>
</network>

in the guest, the system is configured with defaults from 'cloud-init', generating netplan config:

in /etc/netplan/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:
        ens4:
            dhcp4: true
        ens5:
            dhcp4: true
    version: 2

In order to resolve default gateway ambiguity i tried to force gateway 'metric' definition in the guest, without success:

#/etc/netplan/99-config.yaml

network:
   version: 2
   ethernets:
#        ens4:
#            dhcp4: true
        ens5:
            dhcp4: true
#            dhcp4-overrides:
#                route-metric: 90
            routes:
                - to: 0.0.0.0/0
                  via: 192.168.122.1
                  metric: 90

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.