UDE

udeslirp
Login

udeslirp

Purpose: giving guests on a UDE network the host's network, the way QEMU's user-mode networking does, without root.

Every option is in udeslirp(8). For a whole network with DHCP, start with the how-to; for what happens to each packet, see Routing and NAT.

A gateway on the switch

udeslirp is a host on the switch with the gateway address, 10.0.2.2/24 unless -a gives another. Guests that use it as their default router reach the outside world through the host:

udeswitch &
udeslirp -v &
udenc --addr 10.0.2.15/24 --gateway 10.0.2.2 example.org 80

It needs no privileges: every guest connection becomes a connection made by the udeslirp process, so it works wherever an ordinary program can open sockets, and the outside world sees the host's address. With -v it logs each connection and UDP mapping as it starts and ends:

udeslirp: gateway 10.0.2.2/24 on 3a:..., DNS 10.0.2.3 -> 192.168.1.1:53
udeslirp: tcp 10.0.2.15:50634 -> 172.30.0.2:18080 connected
udeslirp: tcp 10.0.2.15:50634 -> 172.30.0.2:18080 closed (25 bytes from the guest, 3000205 to it)
udeslirp: udp 10.0.2.15:62826 mapped (DNS)
udeslirp: udp 10.0.2.15:62826 expired

kill -USR1 prints the statistics; so does Ctrl+C, before it exits.

DNS

Address 3 of the subnet (10.0.2.3) answers ARP and ping and relays DNS on UDP and TCP port 53 to the host's resolver, the first IPv4 nameserver in /etc/resolv.conf. -D 192.168.1.1 (or -D 127.0.0.1:5353) picks another; Windows has no /etc/resolv.conf, so there -D is needed. --dns-address none turns the relay off.

Port forwards

A guest's server is reachable from the host through a forward:

udeslirp -R tcp:2222:10.0.2.15:22 -R udp:6969:10.0.2.15:69
ssh -p 2222 user@127.0.0.1

Forwards listen on 0.0.0.0 unless a host address comes first (tcp:127.0.0.1:2222:10.0.2.15:22) or -b/--bind is given, matching QEMU's SLIRP. A listen address that is not loopback is warned about once:

udeslirp: WARNING: a forward is not bound to a loopback address; anyone who can reach this host can connect to the guest

In the guest, forwarded connections come from the gateway. Give the guest a fixed address, statically or with a udedhcpd -r reservation, so that the forward finds it.

Hosts behind a router: --route

udeslirp can be the "ISP" of a bigger network: a uderouter joins other switches to its subnet and uses it as the default gateway. Tell udeslirp which networks are behind which router, and it serves their hosts like its own guests:

udeslirp --route 192.168.1.0/24:10.0.2.15

Their connections, mappings and pings go out through the host as usual; replies, ICMP errors and port forwards (-R tcp:2222:192.168.1.10:22) go back to them through the router at 10.0.2.15, whose MAC address udeslirp finds with ARP. A guest on 10.0.2.0/24 that sends to 192.168.1.0/24 through udeslirp is passed on to the router unchanged but for its TTL, as a real router would. The gateway must be on udeslirp's own subnet; up to 16 routes. See Several networks for the whole setup.

-b/--bind

-b 192.168.1.5 binds outgoing host sockets (TCP, UDP, the DNS relay, and ping sockets where they exist) to that address before connecting or sending, so the traffic leaves through that interface. A forward that omits the host address listens there instead of on 0.0.0.0. If the address is not the host's, udeslirp exits at startup:

udeslirp: cannot bind to 192.0.2.1: Cannot assign requested address

--bind 0.0.0.0 undoes an earlier -b.

The host's loopback

SLIRP lets a guest reach the host's own 127.0.0.1 through the gateway address. udeslirp does too, but only with --host-loopback: services that listen on loopback often trust everyone who can reach them, and with this option that includes every guest and anyone who can join the switch. Without it, TCP to the gateway is refused, and UDP to it gets port unreachable (except replies to UDP forwards).

With both --host-loopback and -b of a non-loopback address, the host socket is still bound to -b first, then connected to 127.0.0.1. On Linux that reaches the host's loopback services; on some systems it may fail, and the guest then sees a reset or an ICMP unreachable.

Limiting what guests reach

Ping

Ping needs raw sockets, which an unprivileged program cannot open; Linux and macOS offer "ping sockets" instead. On Linux they are allowed for the groups in net.ipv4.ping_group_range: if the first outside ping says

udeslirp: no ICMP echo socket (Permission denied): pings to the outside are refused; on Linux, see sysctl net.ipv4.ping_group_range

then sudo sysctl net.ipv4.ping_group_range="0 2147483647" allows them. Windows has no such sockets that its older versions share, so there outside pings are always refused, with ICMP "administratively prohibited" from the gateway. Pings to the gateway and the DNS address always work. A guest that judges the network by ping alone may think it is offline; TCP and UDP still work.

Configuration file keys

Each long option is also a key of the [udeslirp] table of a configuration file, with _ for -: --host-loopback is host_loopback, --udp-timeout is udp_timeout, --switch is connection (which [global] connection also sets), and --forward, --route and --deny take a list. A boolean has a --no-X form, so icmp = false is --no-icmp. Give the file with -C / --configuration, or UDE_CONFIG; the command line overrides it, --check-config reports unknown keys and --print-config shows the effective options.

[global]
connection = "udp://127.0.0.1:7500"

[udeslirp]
address = "10.0.2.2/24"
forward = ["tcp:127.0.0.1:2222:10.0.2.15:22"]
deny = ["192.0.2.0/24"]
udeslirp -C lab.toml -v

The complete list is in ude.conf(5).

guest 10.0.2.15 udeswitch udeslirp 10.0.2.2, DNS .3 host sockets Internet TCP spliced, UDP mapped, ping if allowed
G: box "guest" "10.0.2.15" fit
S: box "udeswitch" fit at G + (2.0, 0)
R: box "udeslirp" "10.0.2.2, DNS .3" fit at S + (2.2, 0)
H: box "host sockets" fit at R + (2.2, 0)
N: box "Internet" rad 0.2 fit at H + (2.0, 0)
line from G.e to S.w
line from S.e to R.w
arrow <-> from R.e to H.w
arrow <-> from H.e to N.w
text "TCP spliced, UDP mapped, ping if allowed" at R.s + (1.1, -0.35)