Networking Modes ---------------- Since Linux 5.6 the old UML networking modes are deprecated. The recommended mode is the Vector Network Drivers. Not every transport is privileged. Pick the least-privileged one that does what you need: transport needs gives you --------- ----- --------- fd nothing guest networking via an external helper (slirp4netns, passt, ...) that hands UML an open socket vde nothing an L2 network between UML instances via vde_switch gre, l2tpv3 nothing an L2 tunnel to a remote endpoint bess nothing a BESS software switch tap see below a real interface on the host raw, hybrid CAP_NET_RAW direct access to a host interface If you only want outbound connectivity from the guest, use "fd" with a userspace network helper. It needs no privileges, no group membership and no host configuration: linux.uml ubd0=disk.img vec0:transport=fd,fd=3 ... Everything below is about transport=tap only. Using transport=tap ------------------- A tap is a host network interface, so attaching to one is privileged. There are two ways to get that privilege. The first is preferred. 1. A persistent tap owned by a group you belong to (recommended) The administrator creates the tap once and hands it to a group. Members of that group may then attach to it with no capabilities at all. This package creates the group "uml-net" for that purpose. Add yourself to it: sudo adduser uml-net Group membership is only picked up by a NEW login session. Log out and back in, or use "newgrp uml-net" in the current shell, before going further. Then create the tap. With systemd-networkd, start from the shipped examples: sudo cp /usr/share/doc/user-mode-linux/examples/systemd-networkd/*.netdev \ /usr/share/doc/user-mode-linux/examples/systemd-networkd/*.network \ /etc/systemd/network/ sudo systemctl restart systemd-networkd Edit the address range first if 172.16.3.0/24 collides with your network. Without systemd-networkd, the equivalent is: sudo ip tuntap add dev tap0 mode tap group uml-net sudo ip addr add 172.16.3.1/24 dev tap0 sudo ip link set tap0 up IMPORTANT -- give the tap a GROUP, never an owning USER. The kernel check in drivers/net/tun.c, tun_not_capable(), is: ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) || (gid_valid(tun->group) && !in_egroup_p(tun->group))) && !ns_capable(net->user_ns, CAP_NET_ADMIN) The two tests are OR'd. If an owning user is set and it is not you, that alone denies the attach and your group membership is never consulted -- you would then need CAP_NET_ADMIN after all. "User=" in a systemd .netdev, and "user" in "ip tuntap add", are therefore traps: set the group and leave the user unset. 2. CAP_NET_ADMIN on the UML binary (fallback) If you cannot pre-create a tap -- for instance UML must create it on the fly -- grant the capability instead: sudo setcap cap_net_admin=+eip /usr/bin/linux.uml Understand what this grants. CAP_NET_ADMIN is host-wide network administration: anyone who can execute /usr/bin/linux.uml can create and destroy interfaces, change routes and alter firewall rules on the host. Option 1 grants exactly one thing -- attach to one tap. File capabilities are an extended attribute on the inode, so they are LOST whenever the package is upgraded or reinstalled, and whenever you install a locally built linux.uml. If UML networking stops working right after an upgrade, check this first. Troubleshooting --------------- uml_tap: failed to select tap interface uml_tap: failed to create tun interface user_init_tap: init failed, error -1 means the TUNSETIFF ioctl was refused, almost always with EPERM. Check in this order: id -nG | grep -w uml-net Are you in the group -- in THIS login session? (see the newgrp note above) ip -d tuntap show Does tap0 exist? Does it show a "group", and NO "user"? getcap /usr/bin/linux.uml If you chose option 2, is the capability still present? Kernel modules -------------- Modules are installed in /usr/lib/uml/modules/. The easiest way to get to them from within UML is to use hostfs, e.g.: mount -t hostfs -o hostfs=/usr/lib/uml/modules hostfs /lib/modules or: echo "hostfs /lib/modules hostfs hostfs=/usr/lib/uml/modules 0 0" >> /etc/fstab or copy them into your root filesystem (rootstrap can do this automatically). NOTE: to be able to load 2.6 kernel modules you'll need to install module-init-tools in the guest root filesystem. You can easly do this inside the running guest by apt-get'ing the package or when building your rootfs with rootstrap by adding the proper option in the configuration file (include=module-init-tools or install=module-init-tools). Kernel configuration notes -------------------------- Unlike the UML binaries distributed from the official UML website, this kernel does not support DevFS as this feature has been obsoleted in the upstream Linux kernel and will be removed very soon. Instead of DevFS you can run udev inside the guest or simply have static /dev nodes (which I suggest as you'll hardly have many varying devices there). Compiling a Custom UML package ------------------------------ You must have APT configured such that 'apt-get source' works in order to do this the easy way. See sources.list(5). 1. $ apt-get source user-mode-linux 2. # apt-get build-dep user-mode-linux (must be run as root) 3. $ cd user-mode-linux-UMLVERSION 4. $ debian/rules unpack Or, unpack other kernel source and update kernel_version in debian/rules 5. $ debian/rules patch Or, apply a UML patch by hand and touch patch-stamp 5. $ cd linux-source-KVERSION 6. $ make defconfig ARCH=um && make [menu,x]config ARCH=um # etc. All makefile commands must include ARCH=um 7. $ cd .. 8. $ dpkg-buildpackage -rfakeroot -nc -uc -- Matt Zimmerman , Fri Jan 2 14:29:13 2004