You are not logged in.
Pages: 1
Topic closed
after hours tinkering i finally figured out how to setup my qemu win 7 vm with tap device networking. the host machine is connected to the internet via wifi (wlan0 in my case) and it shares this connection with the vm. thought i'd post the exact commands i used to get this up and running in order to save others the time and trouble.
i found the qemu arch wiki page really wasn't entirely clear on how to do this, especially for ppl like me who don't have a firm grasp on networking concepts and who's eyes tend to gloss over when reading up on the subject.
i'm still not entirely sure why it works, for instance why must i create a bridge (which iirc is like a virtual switch) and a tap device (which iirc is like a virtual ethernet port)? why not just a tap device?
i originally attempted to do this with just a tap device much in the same way you'd hook 2 machines up via cross over ethernet cable, but that didn't seem to really work right. although i was able to gain internet access on the guest, windows bitched about the connection being problematic and svchost.exe got stuck at 100% cpu usage (though that latter could've just been a coincidence, windows being windows and all..), so i decided to give up on that approach.
anyway, below is the list of commands i've been using (execute with root privileges). dnsmasq is required, but that's only b/c i'm lazy and don't feel like setting the ip link info manually on the guest. also, make sure to change wlan0 to whatever interface device name you use to connect to the internet with.
ip link add name br0 type bridge
ip addr add 172.20.0.1/16 dev br0
ip link set br0 up
dnsmasq --interface=br0 --bind-interfaces --dhcp-range=172.20.0.2,172.20.255.254
modprobe tun
[[ ! -d /etc/qemu ]] && mkdir /etc/qemu
echo allow br0 > /etc/qemu/bridge.conf
sysctl net.ipv4.ip_forward=1
sysctl net.ipv6.conf.default.forwarding=1
sysctl net.ipv6.conf.all.forwarding=1
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i tap0 -o wlan0 -j ACCEPT
# now run (as your user):
# $ qemu-system-x86_64 ... -net nic,model=virtio -net bridge,br=br0
the above implicitly makes use of qemu-bridge-helper to automatically bring up a tap device that's assumed will be named tap0 (maybe i could change the firewall rule and replace tap0 with br0 to avoid making this assumption? idk and i don't feel like experimenting anymore..). however if you want to manually create the tap device yourself i can confirm that the following will accomplish the same thing as the above:
ip link add name br0 type bridge
ip addr add 172.20.0.1/16 dev br0
ip link set br0 up
dnsmasq --interface=br0 --bind-interfaces --dhcp-range=172.20.0.2,172.20.255.254
modprobe tun
ip tuntap add dev tap0 mode tap user "YOUR_USER_NAME_HERE"
ip link set tap0 up promisc on
ip link set tap0 master br0
sysctl net.ipv4.ip_forward=1
sysctl net.ipv6.conf.default.forwarding=1
sysctl net.ipv6.conf.all.forwarding=1
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i tap0 -o wlan0 -j ACCEPT
# now run (as your user):
# $ qemu-system-x86_64 ... -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no
edit: since this is a solution and not a problem post i added [SOLVED] to the posts subject text
Last edited by e_tank (2016-01-22 09:53:08)
Offline
Thank you very much. This work perfectly for me.
Offline
Please do not necrobump or empty-post.
https://wiki.archlinux.org/index.php/Co … bumping.22
https://wiki.archlinux.org/index.php/Co … mpty_posts
Closing.
Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD
Making lemonade from lemons since 2015.
Online
Pages: 1
Topic closed