Skip to content

Instantly share code, notes, and snippets.

@jaysridhar
Last active February 12, 2021 15:10
Show Gist options
  • Save jaysridhar/462338ca0587235b5209a79117ceb693 to your computer and use it in GitHub Desktop.
Save jaysridhar/462338ca0587235b5209a79117ceb693 to your computer and use it in GitHub Desktop.

Following netplan creates a virtual bridge br0 connected to interface enp2s0 and both have same mac address (as required by hetzner)

network:
  version: 2
  renderer: networkd
  ethernets:
    enp2s0:
      match:
        macaddress: 44:8a:5b:9b:a0:5b
      dhcp4: no
      dhcp6: no
  bridges:
    br0:
      macaddress: 44:8a:5b:9b:a0:5b
      interfaces: [enp2s0]
      addresses:
        - 148.251.151.77/32
        - 2a01:4f8:210:504c::2/64
      routes:
        - on-link: true
          to: 0.0.0.0/0
          via: 148.251.151.65
      gateway6: fe80::1
      nameservers:
        addresses:
          - 213.133.100.100
          - 213.133.98.98
          - 213.133.99.99
          - 2a01:4f8:0:1::add:1010
          - 2a01:4f8:0:1::add:9999
          - 2a01:4f8:0:1::add:9898

Create a vm using the following commands:

Note the following:

  1. We have set the network to default so we have internet connectivity via the host

  2. VNC is set to listen on 0.0.0.0 so we can connect using VNC and complete the installation.

qemu-img create -f qcow2 images/hellovm-9.qcow2 10G
virt-install --virt-type kvm \
  --name hellovm-9 \
  --ram 2048 \
  --disk images/hellovm-9.qcow2,format=qcow2 \
  --network network=default \
  --graphics vnc,listen=0.0.0.0 \
  --noautoconsole \
  --cdrom boot/ubuntu-18.04.5-live-server-amd64.iso

After the installation is complete, start the VM, SSH into it and change the network as follows. Here we are setting a static IP to the only interface. This means internet connectivity, but no connectivity from the KVM host.

network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      addresses:
        - 148.251.151.90/32
      routes:
        - to: 0.0.0.0/0
          via: 148.251.151.65
          on-link: true
      nameservers:
        addresses:
          - 213.133.100.100
          - 213.133.98.98
          - 213.133.99.99

Save the configuration and shutdown the guest.

Back on the KVM host, edit the guest configuration using the following command:

virsh edit hellovm-9

And change the network config from this:

    <interface type='network'>
      <mac address='52:54:00:86:2b:c4'/>
      <source network='default'/>
      <model type='rtl8139'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

to this:

    <interface type='bridge'>
      <mac address='00:50:56:00:20:0d'/>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

We have changed the following:

  1. Interface type changed to type='bridge'

  2. MAC address updated to whatever you get from Hetzner.

  3. Source changed to bridge='br0'

Save and edit. Restart the guest. It should now be connected to the Internet with both incoming and outgoing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment