Virtual Switch (VDE)
VM networking with a VDE device.
You create a switch and connect to it a tap device and multiple VMs. To access to the internet you need a firewall to route traffic from ensp3s0/eth0
to tap0
.
The firewall applies to tap0
.
Software needed
vde2
and iptables
.
Optional dnsmasq
.
Load the tun kernel module.
Create the tap
Route the traffic.
iptables -A INPUT -i tap0 -p tcp -m tcp --dport 53 -j ACCEPT
iptables -A INPUT -i tap0 -p udp -m udp --dport 53 -j ACCEPT
iptables -A INPUT -i tap0 -p udp -m udp --dport 67 -j ACCEPT
iptables -A FORWARD -o tap0 -j ACCEPT
iptables -A FORWARD -i tap0 -j ACCEPT
iptables -A OUTPUT -o tap0 -p tcp -m tcp --sport 53 -j ACCEPT
iptables -A OUTPUT -o tap0 -p udp -m udp --sport 53 -j ACCEPT
iptables -A OUTPUT -o tap0 -p udp -m udp --sport 67 -j ACCEPT
Start the Switch
This will create the switch; it looks like it's stuck, just pres enter and you will be presented with a prompt vde$
DHCP
Make sure /etc/dnsmasq.conf is empty or doesn't exists or it's commented out. Also you can use this file for configuring it insted of using a command. You can also change the IPs.
# dnsmasq --listen-address=10.10.10.1 --dhcp-range=10.10.10.10,10.10.10.200,12h --interface=tap0 --except-interface=lo,enp3s0 --dhcp-option=3,10.10.10.1 --dhcp-option=6,1.1.1.1,1.0.0.1
Configure the network in the host. If for whatever reason you don't want a fucking DHCP.
remove network
QEMU shit (Different MAC addresses for every VM)
Diferent MAC addresses for every VM.
Helpful commands
Bridge for everyone
This solution does have problems or misconfigurations. I didn't finished configuring it. Be careful.
Create a bridge and connect the Linux network stack
to it along with the VMs.
You will no longer use the interface directly but rather use the bridge to go out.
A bridge to connect everything and a tap to connect each VM. Yes, each.
Works as a way of connecting directly to the computer network. It does not create another virtual network that is connected to the internet
enp3s0
is my network interface, yours may be eth0
.
You need to create a tap for every VM and add it to the bridge.
Software needed
DUNNO.
You may need to load the tun kernel module
Create the bridge
Create the tap
Add the interfaces to the bridge
Raise the interfaces and get an IP in br0
\\ Give an IP to the bridge
# ip addr add dev br0 10.10.10.1/24
-----------------------------------
\\ Rise the interfaces
# ip link set dev br0 up
# ip link set dev enp3s0 up
# ip link set dev tap0 up
-------------------------
\\ Get an IP for the bridge
# dhclient br0
[Optional] Show the bridge
Update the config in shorewall and restart shorewall
This does NOT apply to everyone. You may need IPtables rules. Or not, I don't know how this works. I don't even know if this (firewall) does something to the bridge.
Start a DHCP server on the tap bridge
Make sure /etc/dnsmasq.conf is empty or doesn't exists or it's commented out. Also you can use this file for configuring it insted of using a command. You can also change the IPs.
# sudo dnsmasq --listen-address=10.10.10.1 --dhcp-range=10.10.10.10,10.10.10.200,12h --interface=br0 --except-interface=lo,enp3s0 --dhcp-option=3,10.10.10.1 --dhcp-option=6,1.1.1.1,1.0.0.1
Shit in QEMU
-device virtio-net-pci,netdev=net0 -netdev tap,id=net0,ifname=tap0,script=no,downscript=no,vhost=on \
Remove bridge and restore network
# ip link set dev br0 down
# ip link set dev enp3s0 down
# ip link set dev tap0 down
# brctl delif br0 enp3s0
# brctl delif br0 tap0
# tunctl -d tap0
# brctl delbr br0
# dhclient enp3s0
Other commands
HOW this SHIT works. Maybe, I'm no expert.
Routed Tap
Create a tap
device and route traffic to it with a firewall like IPTables.
To achieve: tap to QEMU and route with IPtables/Shorewall.
No bridge no bullshit.
Still, you need to create a tap for every VM and route the traffic in the firewall.
Software needed
DUNNO.
You may need to load the tun kernel module
Create the tap
Start a DHCP server on the tap
Make sure /etc/dnsmasq.conf is empty or doesn't exists or it's commented out. Also you can use this file for configuring it insted of using a command. You can also change the IPs.
# dnsmasq --listen-address=10.10.10.1 --dhcp-range=10.10.10.10,10.10.10.200,12h --interface=tap0 --except-interface=lo,enp3s0 --dhcp-option=3,10.10.10.1 --dhcp-option=6,1.1.1.1,1.0.0.1
Update the config in shorewall and restart shorewall
This does NOT apply to everyone. You may need IPtables rules. Or not, I don't know how this works.
Shit in QEMU
-device virtio-net-pci,netdev=net0 -netdev tap,id=net0,ifname=tap0,script=no,downscript=no,vhost=on \
remove network
other commands
There is also another way with OVS (Open Virtual Switch)
https://ninefinity.org/post/openvswitch-for-libvirt-on-arch-linux/
https://bbs.archlinux.org/viewtopic.php?id=159941