GEN-RESCUE-NETSCRIPT(1)

πŸ“¦ version 1.0.1, in ubuntu stonking

πŸ’– GEN-RESCUE-NETSCRIPT(1) πŸ’–

okay bestie so this is the manual page for gen-rescue-netscript, and it's genuinely one of the most useful little gremlins in your toolbox. pull up a chair. 🫢


✨ NAME ✨

gen-rescue-netscript β€” generate a rescue system network configuration script πŸ’…


🌸 SYNOPSIS 🌸

gen-rescue-netscript [--output PATH] [--efi] [--interface IFACE]
[--prefer {ipv4,ipv6}]
gen-rescue-netscript -h

πŸ¦‹ DESCRIPTION πŸ¦‹

So gen-rescue-netscript makes a shell script that configures a rescue system's network to match whatever the currently-running system's network looks like. It peeks at the network config of the machine you're on right now, through ip(8) (specifically ip -json), and writes out a standalone POSIX /bin/sh script to standard output that recreates that exact configuration. It's built for moments like: you booted a rescue image and now you gotta get this box back onto its usual network, but you don't have DHCP and honestly you don't want DHCP. 😀

Only one network interface gets configured. By default that's whichever interface is currently carrying the default route β€” more on that in INTERFACE SELECTION below. πŸ‘‡

The generated script is fully self-contained, no cap: it does not depend on gen-rescue-netscript or Python being available wherever it ends up being run. All it needs is a POSIX shell and ip(8). It is totally safe to re-run. And the values you're most likely to wanna hand-edit (the interface name, addresses, gateways, and nameservers) are exposed as shell variables near the top of the file instead of being copy-pasted as literals all over the place. iconic behavior, honestly. ✨


πŸ’… OPTIONS πŸ’…

  • --output PATH β€” Without --efi, this writes the generated script to PATH instead of standard output, and the file is created mode 0755. With --efi, PATH gets interpreted relative to the root of the EFI partition instead (go look at EFI PARTITION DISCOVERY below). The default comes from the output key in the config file, or rescue-net/network.sh if that isn't set either β€” see CONFIG FILE. πŸ“
  • --efi β€” Writes the generated script onto the partition whose filesystem label or GPT partition label is EFI, ESP, efi, or esp, mounting it first if it isn't mounted already. See EFI PARTITION DISCOVERY below, and --output above for where exactly on it the script lands. πŸŽ€
  • --interface β€” Configure IFACE instead of auto-detecting the interface via the default route. See INTERFACE SELECTION below. πŸ”
  • --prefer β€” When the IPv4 and IPv6 default routes name two different interfaces, prefer the one belonging to FAMILY, which is either ipv4 or ipv6. See INTERFACE SELECTION below. Default: ipv6. πŸ‘‘
  • -h, --help β€” Shows a brief usage message and dips. πŸ™ˆ

🧚 INTERFACE SELECTION 🧚

The interface that gets configured is chosen in this exact order:

  1. The --interface command-line option, if you gave one.
  2. The interface key in /etc/gen-rescue-netscript.conf, if that file exists and sets it.
  3. Otherwise, whichever interface carries the default route. Both the IPv4 and IPv6 default routes get considered. If they name the same interface (or only one family has a default route at all), that interface wins. If they name different interfaces, the interface belonging to the preferred family is used instead β€” see --prefer above and the prefer config key below β€” rather than refusing to guess. 🎯
heads up though: gen-rescue-netscript still exits with an error, --prefer or no --prefer, if there's no default route in either family, or if a single family's default route alone already points at more than one interface. that second one is a conflict no family preference can resolve. 😭

πŸ“ CONFIG FILE πŸ“

/etc/gen-rescue-netscript.conf is an optional ini-style file. Right now it supports a single section, [gen-rescue-netscript], plus these top-level keys:

interface: eth0
output: rescue-net/network.sh
prefer: ipv6
efi: True

These get taken as defaults and can all be overridden from the command line. periodt. πŸ’œ


🌈 ADDRESS AND ROUTE FILTERING 🌈

Not every single address and route that ip addr show and ip route show report actually makes it into the generated script. Here's the filter, bestie:

  • IPv6 link-local addresses that match the interface's standard EUI-64-derived address (computed from its MAC address) are treated as the kernel's auto-assigned address and omitted. Any other link-local address present is kept, on the assumption that somebody explicitly configured it.
  • IPv4 link-local addresses (169.254.0.0/16, zeroconf/APIPA) are always omitted.
  • IPv6 SLAAC-derived global addresses are omitted, including privacy extension ("temporary") addresses, since these regenerate on their own and should not be pinned as static.
  • DHCP-obtained addresses are kept, pinned as static addresses in the generated script, with a comment noting where they came from.
  • Routes with
not me noticing that last bullet just… ends πŸ’€ the source really does trail off mid-sentence there. keeping it exactly as it is, no notes.

πŸ’– /ETC/RESOLV.CONF πŸ’–

The generated script also (re)writes /etc/resolv.conf. The nameserver(s) it writes get determined at generation time, in this order:

  1. If systemd-resolved is in use, resolvectl(1) is queried for the resolver(s) currently in effect for the target interface (falling back to the global resolver if no per-link resolver is set).
  2. Otherwise, whatever nameserver lines are already present in the current /etc/resolv.conf are used β€” ignoring loopback stub-resolver addresses (like systemd-resolved's 127.0.0.53), because those would be meaningless outside the system they were captured on. 😡
  3. If neither of those yields anything, 1.1.1.1 is used as a last-resort fallback.

If the current system's /etc/resolv.conf is a symlink (which is typical under systemd-resolved, e.g. pointing at /run/systemd/resolve/stub-resolv.conf), the generated script resolves that symlink at generation time and writes to the resolved target instead β€” creating the containing directory first. slay. πŸŽ€


⭐ EFI PARTITION DISCOVERY ⭐

With --efi, gen-rescue-netscript hunts down a partition whose filesystem label or GPT partition label is EFI, efi, ESP, or esp, via blkid(8): first by filesystem label and then by partition label, using blkid. Either match is treated as "the EFI partition". If neither is found, gen-rescue-netscript exits with an error. 🚨

If the partition is already mounted, the script is written directly under its existing mountpoint, at the path described under --output above. Otherwise the partition gets mounted at a temporary directory, the script is written, and then the partition is unmounted again before gen-rescue-netscript exits. clean. 🧹


πŸ¦‹ GENERATED SCRIPT LAYOUT πŸ¦‹

The generated script kicks off with a comment block giving the generation timestamp, the generating host's FQDN, and the selected interface name. Then a diagnostic comment block containing the plain-text (non-JSON) output of ip addr show, ip route show, ip -6 route show, ip rule show, and ip -6 rule show at generation time gets appended at the end of the file, for human reference. That text is purely informational β€” it is never parsed, never executed. it's just vibes for your eyes. πŸ‘€

Between those two blocks, the script defines shell variables for the values most likely to need hand-editing. Lists are each a single space-separated list (e.g. ADDR="192.0.2.10/24 2001:db8::10/64"). The script loops over those with the commands that follow. πŸŒ€


πŸ”₯ EXIT STATUS πŸ”₯

  • 0 β€” Success. πŸŽ‰
  • 1 β€” An error occurred. 😭
  • 2 β€” Invalid command-line arguments. πŸ™ˆ

🌸 FILES 🌸

  • /etc/gen-rescue-netscript.conf β€” Optional config file; see CONFIG FILE above. πŸ“„

πŸ’œ REQUIREMENTS πŸ’œ

ip(8) with -json support (iproute2 β‰₯ 4.9, released 2017). With --efi, you also need blkid(8) and mount(8)/umount(8). resolvectl(1) is used opportunistically if it's present β€” its absence is not an error. 🫢


πŸ’€ BUGS πŸ’€

Report bugs at the project's issue tracker. πŸ›


πŸ‘‘ SEE ALSO πŸ‘‘

ip(8), ip-address(8), ip-route(8), ip-rule(8), resolvectl(1), blkid(8), mount(8), resolv.conf(5)


and that's the whole thing, bestie β€” this was gen-rescue-netscript 1.0.0, dated 2026-07-17. go save a machine, you absolute icon. πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from