Routing

IP-Forwarding

You need to configure IP forwarding in /etc/sysctl.d/70-ip-forwarding.conf

# IPv4 forwarding
net.ipv4.ip_forward=1
# IPv6 forwarding
net.ipv6.conf.all.forwarding=1

Load the new settings:

sysctl -p /etc/sysctl.d/70-ip-forwarding.conf

Script for setting up IPv4 routing

You can use this networksetup.sh script to setup IPv4 routing for IPs.

#!/bin/bash

CMD=$1

#

IPS="198.51.100.2
198.51.100.3
198.51.100.4
198.51.100.5"

if [ -z $CMD ]
        then
                echo "No command given"
                exit 1
fi

date >> /var/log/networksetup.log
echo "$CMD" >> /var/log/networksetup.log

if [ $CMD == 'up' ]
        then
                while read -r line; do
                        echo $line >> /var/log/networksetup.log
                        /sbin/ip route add $line/32 dev xenbr0 2>&1 >> /var/log/networksetup.log
                done <<< "$IPS"
fi

if [ $CMD == 'down' ]
        then
                while read -r line; do
                        echo $line >> /var/log/networksetup.log
                        /sbin/ip route del $line/32 dev xenbr0 2>&1 >> /var/log/networksetup.log
                done <<< "$IPS"
fi

Possible bridge setup

auto lo
iface lo inet loopback
iface lo inet6 loopback

auto xenbr0
iface xenbr0 inet static
        address 203.0.113.86
        netmask 255.255.255.0
        gateway 203.0.113.1
        bridge_ports enp0s31f6
        # route 203.0.113.0/24 via 203.0.113.1 if required by provider
        pre-up /sbin/brctl addbr xenbr0
        up route add -net 203.0.113.0 netmask 255.255.255.0 gw 203.0.113.1 dev xenbr0

iface xenbr0 inet6 static
        address 2001:db8::2
        netmask 128
        post-up /sbin/ip -6 route add default via fe80::1 dev xenbr0

auto xenbr1
iface xenbr1 inet static
        address 203.0.113.86
        netmask 255.255.255.255
        bridge_ports none
        bridge_stp off
        bridge_fd 0
        pre-up /sbin/brctl addbr xenbr1
        up /root/networksetup.sh up
        down /root/networksetup.sh down

iface xenbr1 inet6 static
        address 2001:db8::2
        netmask 64

Generate custom MAC-Adressen for VM setup

You can use this macgen.py script to generate a MAC address for guests on Xen.

!/usr/bin/python
# macgen.py script to generate a MAC address for guests on Xen
#
import random
#
def randomMAC():
        mac = [ 0x00, 0x16, 0x3e,
                random.randint(0x00, 0x7f),
                random.randint(0x00, 0xff),
                random.randint(0x00, 0xff) ]
        return ':'.join(map(lambda x: "%02x" % x, mac))
#
print randomMAC()