Networking Qemu KVM Howto
Networking Qemu KVM Howto
-----------------------------------
User Mode Networking (Easier Setup)
-----------------------------------
By default, QEMU uses user mode networking (SLiRP). This networking mode is the
slowest and is not visible via the outside network, but requires no host-side
setup, so it's perfect if you just want internet but don't care about latency
or about connecting to the VM from an external source.
- In MacOS, turn on SSH under System Preferences > Sharing > Remote Login.
- Modify the startup script to include `-netdev
user,id=net0,hostfwd=tcp::10022-:22`
- Use `ssh localhost -p10022` to get in.
-----------------------------------
Tap Networking (Better Performance)
-----------------------------------
Installing "virt-manager" automagically creates the "virbr0" local private
bridge :-)
#!/usr/bin/env bash
sudo ip tuntap add dev tap0 mode tap
sudo ip link set tap0 up promisc on
sudo ip link set dev virbr0 up
sudo ip link set dev tap0 master virbr0
Note: You may need to enable the `rc.local` functionality manually on modern
Ubuntu versions. Check out the [notes](notes.md) included in this repository
for details.
------------------
Bridged Networking
------------------
QEMU defaults to using NAT for its guests. It has a built-in DHCP server that
provides addresses from the 192.168.12x.0 subnet. However, this configuration
makes file sharing, printer sharing, and other common networking activities
harder to use in a home network.
Bridged networking allows your QEMU guest to get an address on the same subnet
as the host computer. For example, many home networks let the wireless router
handle IP assignment via DHCP. Here are the steps for setting up the bridge.
To setup bridged networking from the command line, refer to this documentation
at the Ubuntu website. https://help.ubuntu.com/community/KVM/Networking
Ultimately, the script for booting the QEMU guest will need a line similar to
the following to enable bridged networking in the guest:
-netdev bridge,id=net0,br=virbr0,"helper=/usr/lib/qemu/qemu-bridge-helper"
Note that this is sometimes viewed as a security hole. Be careful and understand
what you are doing before running this command.
-----------------------
Bridged Networking 2023
-----------------------
sudo ip link set enx00e04c680a67 master br0 && sudo dhclient br0
$ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.ead0ee60b7c1 yes enx00e04c680a67
tap0
Use the following network device in scripts: