Networking
Give the guest QEMU's network cards and backends. In Node the user network uses real sockets, in a browser it goes through a relay, and several guests can share a network over a WebSocket hub.
Networking works as in QEMU, with the same -netdev backends, -nic and -net shorthands, network cards and defaults, all described on QEMU's network emulation page.
As in QEMU, a machine has a network unless you say otherwise. With no -net, -netdev or -nic, it gets a virtio-net-pci card on the user network. To choose the card or its options:
warm-system-aarch64 ... -netdev user,id=n0 -device virtio-net-pci,netdev=n0
# or, in one option
warm-system-aarch64 ... -nic user,model=virtio-net-pciFor no network at all, pass -nic none (or -nodefaults).
The user network
-netdev user is QEMU's user network: a router inside the machine, using QEMU's addresses:
| Address | What |
|---|---|
10.0.2.15 | The guest (by DHCP) |
10.0.2.2 | The gateway. TCP to it reaches the host's 127.0.0.1. |
10.0.2.3 | DNS |
With wision=on (-netdev user,id=n0,wision=on), it also answers to the name wision and serves the installer for Warm64's 3D guest driver; see Display and input.
In Node
warm-system-aarch64 and nodeWARMHost() give the user network everything QEMU's has, using the host's own sockets: DHCP, DNS through the host's nameserver, TCP and UDP to anywhere, ping, IPv6, and the options hostfwd, guestfwd, restrict, tftp and smb (which needs Samba's smbd, as QEMU's does). The guest can reach the internet, and your machine's local services at 10.0.2.2.
hostfwd forwards a host port into the guest. For example, for SSH:
warm-system-aarch64 ... -nic user,hostfwd=tcp::2222-:22
ssh -p 2222 root@localhostIn a browser
A web page can't open sockets or look up names itself, so the guest's TCP connections and DNS lookups go through a relay, a small Node program that does them on the page's behalf. Give browserWARMHost() the relay's address:
import { WARM, browserWARMHost } from "@warm-virtual/warm64";
const vm = await WARM.launch("... -nic user", browserWARMHost({ relay: "wss://relay.example.com/?token=SECRET" }));Each TCP connection becomes a WebSocket to the relay, and each lookup becomes a GET /dns request to it. To put the host together yourself, use its two halves, webSocketConnector() and webSocketResolver(): { ...browserWARMHost(), connector: webSocketConnector(url), resolve: webSocketResolver(url) }.
The Warm64 repository includes a relay, examples/net/tcp-relay.mjs. You give it a port, an allow-list of the hosts and networks the guest may reach, and a token that every connection and lookup must carry:
ALLOW="example.com:443,10.0.0.0/8" TOKEN=secret node examples/net/tcp-relay.mjs 7682Warning A relay opens connections on the guest's behalf. Run it with an allow-list and a token, or anyone who can reach it can use it as a proxy.
In a browser, the user network carries DHCP, DNS, outgoing TCP, and ping to its own addresses. Without a relay, the guest's TCP connections are refused and every name lookup fails. Forwarding into the guest (hostfwd) and UDP beyond DHCP and DNS need sockets that a page doesn't have.
In the guest
On Alpine's netboot initramfs:
modprobe virtio_net
udhcpc -i eth0
echo nameserver 10.0.2.3 > /etc/resolv.conf
wget -O - http://example.com/Most installed systems set up the network over DHCP on their own.
Other backends
In Node, QEMU's other backends work as they do in QEMU on a Mac: tap, bridge, vmnet-shared, vmnet-host and vmnet-bridged (which need the same privileges as QEMU's), socket, stream, dgram and hubport. In a web page they're refused, with an error naming the host member that would provide them: this platform has no sockets for a tap netdev (WARMHost.netSockets).
Guests on one network
-netdev socket,connect=ws:// connects the guest to an Ethernet hub over a WebSocket, so several machines in different pages or processes can share a network. It works in a browser too. The repository's examples/net/relay-hub.mjs is a hub like that:
node examples/net/relay-hub.mjs 7681
warm-system-aarch64 ... -netdev socket,id=n0,connect=ws://localhost:7681 -device virtio-net-pci,netdev=n0There's no DHCP on the hub: give each guest its own address on the same subnet.
Link state
set_link, in QMP and the monitor, takes a network card's link down and brings it back up. Name the netdev's id or the card's name (info network lists them):
await vm.qmp("set_link", { name: "n0", up: false });