Note that from inside the guest, connecting to a port on the "gateway" IP address will connect to that port on the host; so for instance "ssh 10.0.2.2" will ssh from the guest to the host.
You can configure User Networking using the -netdev user command line option.
Adding the following to the qemu command line will change the network configuration to use 192.168.76.0/24 instead of the default (10.0.2.0/24) and will start guest DHCP allocation from 9 (instead of 15):
-netdev user,id=mynet0,net=192.168.76.0/24,dhcpstart=192.168.76.9
You can isolate the guest from the host (and broader network) using the restrict option. For example -netdev user,id=mynet0,restrict=y or -netdev type=user,id=mynet0,restrict=yes will restrict networking to just the guest and any virtual devices. This can be used to prevent software running inside the guest from phoning home while still providing a network inside the guest. You can selectively override this using hostfwd and guestfwd options.
Advanced user networking options
The -netdev user parameter has some more useful options:
- The DHCP address and name for the guest can be set with -netdev user,id=n0,host=addr,hostname=name
- You can specify the guest-visible virtual DNS server address with -netdev user,id=n0,dns=addr
- QEMU can simulate a TFTP server with -netdev user,id=n0,tftp=xxx,bootfile=yyy
- To share files between your guest and host, you can use -netdev user,id=n0,smb=dir,smbserver=addr
- To forward host ports to your guest, use -netdev user,id=n0,hostfwd=hostip:hostport-guestip:guestport
For details, please see the QEMU documentation.
./qemu-system-x86_64 -machine pc -enable-kvm -m 8G -smp 8 -cpu host \
-boot c -hda ./ubt20.04_10G.qcow2 \
-device edu \
-device e1000,netdev=net0 \
-netdev user,id=net0,net=192.168.76.0/24,dhcpstart=192.168.76.9 \
#-device remote-port,id=rp1 -machine-path /tmp/machine-x86 \
-monitor stdio
#socat stdin,raw,echo=11111111111111 unix-connect:/tmp/machine-x86/qemu-rport-_machine_peripheral_rp1