Purpose: more than one IPv4 network on UDE, joined by routers, with DHCP on each, the outside world, and the Linux host taking part.
One switch is one Ethernet segment: one broadcast domain, one subnet. A real network is often several, joined by routers, and UDE can be built the same way. A router can be uderouter, which needs no privileges, or the Linux host itself, reached through udetap; both can be in the same network. The commands below were run as shown; the switches are on one host, but each could be anywhere a datagram reaches.
Two switches and a router
A: box "udeswitch" ":7500" fit R: box "uderouter" fit at A + (2.4, 0) B: box "udeswitch" ":7600" fit at R + (2.4, 0) DA: box "udedhcpd" "10.0.1.2" fit at A + (-0.9, -1.1) HA: box "guests" "10.0.1.100-199" fit at A + (0.9, -1.1) DB: box "udedhcpd" "10.0.2.2" fit at B + (-0.9, -1.1) HB: box "guests" "10.0.2.100-199" fit at B + (0.9, -1.1) line from A.e to R.w "10.0.1.1" above line from R.e to B.w "10.0.2.1" above line from DA.n to A.s line from HA.n to A.s line from DB.n to B.s line from HB.n to B.s→ /pikchrshow
udeswitch -p 7500 &
udeswitch -p 7600 &
uderouter -i 127.0.0.1:7500,10.0.1.1/24 -i 127.0.0.1:7600,10.0.2.1/24 &
udedhcpd -s 127.0.0.1:7500 -a 10.0.1.2/24 -g 10.0.1.1 -p 100-199 &
udedhcpd -s 127.0.0.1:7600 -a 10.0.2.2/24 -g 10.0.2.1 -p 100-199 &
- Each switch has a subnet of its own and the router has an address on each, conventionally host 1.
- DHCP is broadcast, and a router does not forward broadcasts, so each
switch needs its own DHCP server. Each hands out its own side of the
router as the gateway (
-g). - Emulated machines join either switch as usual (see QEMU and 86Box) and get an address and a gateway from DHCP.
UDE's own tools take part with DHCP too. A responder on one side and a ping from the other:
udeping -s 127.0.0.1:7600 -r &
udeping -s 127.0.0.1:7500 -c 2 10.0.2.100
udeping: 10.0.2.100/24 on 46:eb:d8:2c:59:e7 (DHCP from 10.0.2.2, lease 3600 s), gateway 10.0.2.1
udeping: 10.0.1.100/24 on 02:94:58:0c:6f:df (DHCP from 10.0.1.2, lease 3600 s), gateway 10.0.1.1
PING 10.0.2.100 from 10.0.1.100: 56 data bytes
64 bytes from 10.0.2.100: icmp_seq=1 ttl=63 time=0.225 ms
A TTL of 63 rather than 64 shows the packet went through a router;
udeping -t 1 gets "time to live exceeded" from it instead.
More switches are more -i options, up to 16. A switch can also be a
classic VDE switch (-i vde:///tmp/sw,10.0.3.1/24).
The outside world: a chain to udeslirp
udeslirp gives one subnet the host's network.
For several, give it a switch of its own with a leg of the router on it,
make it the router's default route, and tell it with --route which
subnets are behind the router:
A: box "udeswitch" ":7500" "10.0.1.0/24" fit B: box "udeswitch" ":7600" "10.0.3.0/24" fit at A + (0, -1.3) R: box "uderouter" fit at A + (2.6, -0.65) C: box "udeswitch" ":7700" "10.0.2.0/24" fit at R + (2.4, 0) S: box "udeslirp" "10.0.2.2, DNS .3" fit at C + (2.4, 0) N: box "host sockets" fit at S + (0, -1.1) line from A.e to R.w "10.0.1.1" above line from B.e to R.w "10.0.3.1" below line from R.e to C.w "10.0.2.254" above line from C.e to S.w arrow <-> from S.s to N.n→ /pikchrshow
udeswitch -p 7500 &
udeswitch -p 7600 &
udeswitch -p 7700 &
udeslirp -s 127.0.0.1:7700 -v \
--route 10.0.1.0/24:10.0.2.254 --route 10.0.3.0/24:10.0.2.254 &
uderouter -i 127.0.0.1:7500,10.0.1.1/24 -i 127.0.0.1:7600,10.0.3.1/24 \
-i 127.0.0.1:7700,10.0.2.254/24 -r default:10.0.2.2 &
udedhcpd -s 127.0.0.1:7500 -a 10.0.1.2/24 -g 10.0.1.1 -N 10.0.2.3 &
udedhcpd -s 127.0.0.1:7600 -a 10.0.3.2/24 -g 10.0.3.1 -N 10.0.2.3 &
udeslirp: gateway 10.0.2.2/24 on b6:b4:59:00:94:1f, DNS 10.0.2.3 -> 10.0.0.2:53
udeslirp: route 10.0.1.0/24 via 10.0.2.254
udeslirp: route 10.0.3.0/24 via 10.0.2.254
- The guests' gateway is their side of
uderouter, which sends anything that is not on one of its subnets on toudeslirp. udeslirpcarries their connections out through the host as for its own guests, and sends the replies, and its port forwards (-R tcp:2222:10.0.1.100:22), back through the router.- The DNS relay at 10.0.2.3 is reachable from every subnet: hand it out
with
-N. - Without
--route,udeslirpwould not know where 10.0.1.0/24 is, and the guests' packets would leave but the replies never come back.
The switch at :7700 can also have guests of its own, with udeslirp as
their gateway; it then passes what they send to 10.0.1.0/24 or
10.0.3.0/24 on to the router.
The Linux host as a router: udetap
udetap gives the Linux host an interface on a switch. With one on each of two switches and forwarding turned on, the host's own IP stack is the router:
A: box "udeswitch" ":7500" "10.0.1.0/24" fit T1: box "udetap" "udeA" fit at A + (2.2, 0) H: box "Linux host" "ip_forward = 1" fit at T1 + (2.2, -0.65) T2: box "udetap" "udeB" fit at A + (2.2, -1.3) B: box "udeswitch" ":7600" "10.0.2.0/24" fit at A + (0, -1.3) line from A.e to T1.w line from B.e to T2.w line from T1.e to H.w "10.0.1.1" above line from T2.e to H.w "10.0.2.1" below→ /pikchrshow
udeswitch -p 7500 &
udeswitch -p 7600 &
sudo ip tuntap add dev udeA mode tap user $USER
sudo ip tuntap add dev udeB mode tap user $USER
udetap -i udeA -s 127.0.0.1:7500 &
udetap -i udeB -s 127.0.0.1:7600 &
sudo ip addr add 10.0.1.1/24 dev udeA
sudo ip addr add 10.0.2.1/24 dev udeB
sudo ip link set udeA up
sudo ip link set udeB up
sudo sysctl net.ipv4.ip_forward=1
Hosts on each switch use 10.0.1.1 or 10.0.2.1 as their gateway (with a
udedhcpd on each switch, as above), and the host's firewall rules
apply to what passes between them. This is the most flexible router,
with the whole of Linux's routing, filtering and NAT, at the price of
root, once for the TAP devices and every time the configuration
changes; ip_forward affects every interface of the host.
Mixing the two
Routers of both kinds can be in the same network. Here the host is on
two switches through TAP, as above, and a uderouter joins a third:
A: box "udeswitch" ":7500" "10.0.1.0/24" fit H: box "Linux host" "udeA, udeB" fit at A + (2.4, 0) B: box "udeswitch" ":7600" "10.0.2.0/24" fit at H + (2.4, 0) R: box "uderouter" fit at B + (0, -1.1) C: box "udeswitch" ":7700" "10.0.3.0/24" fit at R + (0, -1.1) line from A.e to H.w "10.0.1.1" above line from H.e to B.w "10.0.2.1" above line from B.s to R.n "10.0.2.254" ljust line from R.s to C.n "10.0.3.1" ljust→ /pikchrshow
udeswitch -p 7700 &
uderouter -i 127.0.0.1:7600,10.0.2.254/24 -i 127.0.0.1:7700,10.0.3.1/24 \
-r 10.0.1.0/24:10.0.2.1 &
sudo ip route add 10.0.3.0/24 via 10.0.2.254
Each router needs a route to what is behind the other: the host's
ip route sends 10.0.3.0/24 to uderouter, and uderouter -r sends
10.0.1.0/24 to the host. A host on the first switch then reaches one on
the third through both, and the TTL shows it:
PING 10.0.3.5 from 10.0.1.5: 56 data bytes
64 bytes from 10.0.3.5: icmp_seq=1 ttl=62 time=2.131 ms
The host also reaches 10.0.3.0/24 itself, with its own tools. For a
host that only needs to reach the UDE networks, one TAP interface on one
switch is enough: give it an address there and an ip route for each
subnet behind a uderouter, and no ip_forward at all.
Routers and links
A udelink cable joins two switches into one segment; a router joins two segments into two subnets. Do not do both between the same switches: a cable makes them one broadcast domain, and the router then has two interfaces on the same wire. Routers, unlike cables, may form loops, but every packet then goes round until its TTL runs out; with static routes, check that every network has one way to every other.
Troubleshooting
uderouter -vlogs every packet it drops and every ICMP error it sends: "no route", "TTL exceeded", "does not answer ARP".udeping -t Nfinds the router where a path ends: the hop at which "time to live exceeded" stops and "destination unreachable" or silence starts.- "destination unreachable (code 0)" is a missing route, "(code 1)" a next hop that does not answer ARP: the host is down, or on the wrong switch.
- Replies that never come back are usually a missing route in the other
direction:
udeslirp --route,uderouter -ror the host'sip route. - udedump on a switch shows the router's MAC
addresses,
02:55:and the address in hexadecimal.