Title: Host only networking set up for QEMU Date: 24.03.2017 Modified: 01.03.2020 Author: Andrey Albershtein Status: published Slug: host-only-networking-set-up-for-qemu-hypervisor Tags: qemu, linux, networking Keywords: qemu, linux, network, host-guest Summary: In this short note I will try to describe how to set up host-only network for QEMU. It means that guest system (run in QEMU) will be in LAN network with a host system (physical machine).
In this short note I will try to describe how to set up host-only network for QEMU hypervisor. It means that guest system (run in QEMU) will be in LAN network with a host system (physical machine). I used it for some experiments with SSH functionality of a guest system.
Connection will be establish by virtual bridge and TAP interface. After host setup you will need to assign IP address to the guest system.
Firstly, create a bridge on the host machine:
sudo ip link add br0 type bridgeIf you want to use already created bridge don't forget to clean out IP.
sudo ip addr flush dev br0Assign IP to the bridge.
sudo ip addr add 192.168.100.50/24 brd 192.168.100.255 dev br0Create TAP interface.
sudo ip tuntap add mode tap user $(whoami)
ip tuntap showOutput should contains name of created TAP interface:
~ tap0: tap UNKNOWN_FLAGS:800 user 1000Add TAP interface to the bridge.
sudo ip link set tap0 master br0Make sure everything is up:
sudo ip link set dev br0 up
sudo ip link set dev tap0 upAssign IP range to the bridge.
sudo dnsmasq --interface=br0 --bind-interfaces \
--dhcp-range=192.168.100.50,192.168.100.254Make sure that interfaces are UP. If not run previously mentioned commands to set TAP interface up (br0 will change its state automatically). Run Qemu with some MAC address:
qemu -device e1000,netdev=network0,mac=00:00:00:00:00:00 \
-netdev tap,id=network0,ifname=tap0,script=no,downscript=noIn the guest system assign static IP address to the network interface:
ip addr add 192.168.100.224/24 broadcast 192.168.100.255 dev eth0Don't forget to add root password:
passwdNow you can connect to the Qemu guest system using SSH:
ssh root@192.168.100.224
If you get an error that tap0 is already in use, possibly, you are trying to run more than one version of QEMU for one TAP interface. Described configuration is used only for two peers (host and guest). For multiple connection you need different configuration.
As mentioned before make sure that both TAP and Bridge are up. Otherwise you will fail to connect via SSH.