Skip to content

Gateway (create a zone)

A zone is a subnet, with a gateway, behind which you connect as many machines as you like. The first gateway is installed from the administration workstation, set up next to it, without a coordination server.

darkone add gateway does everything from the administration workstation : pairing the machine, declaring it in etc/config.yaml, installation, recabling, checks. The manual variant remains possible.

The gateway is ideally installed on a mini-computer that is always on, with at least two network interfaces: one to the ISP box (WAN), the others to the local network (LAN, ethernet or wifi).

The gateway’s WAN connects to the box ; the entire local network is behind it.

Diagram
  • The box Wi-Fi remains outside the zone: its devices do not receive an address from the gateway.
  • A Wi-Fi access point connects behind the gateway, without DHCP.
  • The switch is optional : a workstation can be plugged into a LAN port.

darkone add gateway runs on the administration workstation, in the project (/etc/nixos). It only asks for the machine’s address and its code.

  1. Connect

    The gateway’s WAN to the box. The administration workstation stays on the box (cable or Wi-Fi).

  2. Boot

    On the generic ISO, written to a USB key, entry 2) Add this machine to an existing network from the menu (or dnf-pair). The screen gives the address and the pairing code :

    - IP: 192.168.1.50
    Pairing code: 123456-7890 (10 min, a new one after)
  3. Run

    Fenêtre de terminal
    cd /etc/nixos
    darkone add gateway

    The wizard asks for the address, then the code. It probes the machine and suggests the name (gw), the WAN (the card carrying the route to the box), the LAN (the other wired cards) and the disk (a question if there are several).

  4. Confirm

    The summary names the disk to be erased and the final choices. Then comes the diff of etc/config.yaml, with a second confirmation : nothing is written before that.

  5. Recable

    At the prompt Now unplug this machine from the box and plug it into a LAN port of gw, connect the administration workstation to a LAN port of the gateway. The wizard resumes on its own, applies this workstation (just apply-local) and checks the network.

The final message, Step 2 of 4 done, announces step 3.

The code PPPPPP-FFFF proves that the typed address is the right machine before any key is sent.

PartRole
PPPPPPnixos password, single-use, valid for 10 min
FFFFhost key fingerprint, verified by the workstation

The workstation computes FFFF from the key it reads on the network : if it differs, nothing is sent. Otherwise it pushes its deployment key (usr/secrets/nix.pub) and locks the password ; the screen displays Paired. The verified host key is then kept until the end of the installation. An already-paired machine does not ask for a code again.

--dry-run pairs and probes the machine, then displays the plan, the diff of etc/config.yaml and the commands of a real run. Nothing is written to the project ; the machine itself stays paired.

An answers file replaces the questions. The pairing code never goes in it : it is typed on the terminal.

reponses.yaml
version: 1
address: "192.168.1.50" # address displayed by the machine
host:
hostname: "gw" # optional
nics:
wan: "enp1s0" # optional : the card carrying the route
lan: ["enp2s0"] # always to be given
disk:
device: "/dev/disk/by-id/nvme-Example_SSD_256GB_S4EXAMPLE0001" # optional : a single disk ≥ 20 GB
confirm: true # required with --non-interactive
Fenêtre de terminal
darkone add gateway --answers reponses.yaml --dry-run
darkone add gateway --answers reponses.yaml --non-interactive
  • confirm: true skips both confirmations (the diff is still displayed) ; without it, --non-interactive refuses to start.
  • An unknown key is rejected ; all errors are listed at once.

The wizard refuses before writing when :

CaseWhat to do
Repository not cleancommit or stash
Gateway already there, or several zonesdeclare by hand
Box network in the zonechange the box network
Fewer than two wired cardsuse a machine with two cards
Machine in BIOSswitch the firmware to UEFI

The zone prefix is final : if the box overlaps it, the box is the one that moves. The server-1-disk layout requires UEFI. Disks smaller than 20 GB (USB key) are not offered.

After confirmation, the wizard writes to etc/config.yaml the zone’s gateway block and the gw host (<zone>:1.1). The administration workstation receives its fixed address (<zone>:2.1) and its mac if they are missing. Then just clean and the commit chore(gateway): add gw.

The failure message lists the remaining commands, in order.

FailureStateRecovery
Before writingnothing changedrerun
just clean, commitfile written, nothing committedcontinue by hand, or git stash --include-untracked then rerun
just full-installdeclaration committedjust full-install gw nixos <ip>, then just apply-local
just apply-localgateway installedjust apply-local
Checksgateway installedthe remedy follows each check

Once the declaration is committed, darkone add gateway refuses to replay (the zone has its gateway) : recovery is done by hand, and asks the formatting question again. The checks verify the default route (the gateway), the resolution of gw and access to the Internet.

Without the wizard, the same installation is done recipe by recipe : the declaration in etc/config.yaml comes before just full-install.

  1. Connect

    The gateway’s WAN to the box. The administration workstation stays on the box (cable or Wi-Fi).

  2. Boot

    On the ISO, written to a USB key. The screen gives what needs to be declared :

    - IP: 192.168.1.50
    - MAC: aa:bb:cc:dd:ee:01
    Network cards (wan.interface, lan.interfaces):
    NAME MAC LINK IPV4 NOTE
    enp1s0 aa:bb:cc:dd:ee:01 up 192.168.1.50/24 default route (WAN)
    enp2s0 aa:bb:cc:dd:ee:02 down -
    Disks (disko.devices), installation medium left out:
    /dev/disk/by-id/nvme-Example_SSD_256GB_S4EXAMPLE0001
    239G Example SSD 256GB [nvme0n1]
    LineUsed for
    - IP:just full-install
    Network cardswan.interface, lan.interfaces
    Disksdisko.devices (path to copy)

    The card marked default route (WAN) carries the route to the box : that is the WAN, the other wired ones are the LAN. dnf-netinfo redisplays the screen. With the generic ISO, the menu entry 2) Add this machine to an existing network displays the same tables.

    The screen also displays the pairing code (Pairing code: PPPPPP-FFFF) : just full-install asks for it at step 4, nothing to authorize before. The just build-iso image already carries the key : no code.

Everything is declared before installation : the gateway is born with the administration workstation’s reservation, which receives its fixed address as soon as it is recabled.

  1. Declare

    In etc/config.yaml : the zone’s gateway block, the gw host, and a fixed address for the administration workstation.

    etc/config.yaml
    zones:
    main:
    description: "Main network"
    ipPrefix: "10.0" # zone in 10.0.0.0/16
    gateway:
    wan:
    interface: "enp1s0" # card to the box
    lan:
    interfaces: ["enp2s0"] # cards to the local network
    hosts:
    - hostname: "gw"
    name: "Passerelle"
    zone: "main:1.1" # fixed IP 10.0.1.1
    profile: "gateway"
    disko:
    profile: "server-1-disk"
    devices:
    main: "/dev/disk/by-id/nvme-Example_SSD_256GB_S4EXAMPLE0001"
    - hostname: "admin" # the administration workstation
    zone: "main:2.1" # was "main" : fixed IP 10.0.2.1
    mac: "aa:bb:cc:dd:ee:ff" # unchanged
    # … the rest is unchanged

    No mac for the gateway : its LAN address is fixed (1.1) and its WAN address comes from the box.

    Fenêtre de terminal
    just clean
    git add . && git commit -m "host(gw): passerelle"
  1. Install

    Fenêtre de terminal
    just full-install gw nixos 192.168.1.50
    • gw : declared hostname.
    • nixos : the ISO’s user.
    • 192.168.1.50 : the - IP: line of the screen.

    Before the formatting question, the recipe announces the recabling : get the cable ready now. The disk is then formatted, the system installed, then the gateway reboots.

    If the box network overlaps the zone’s (the box in 10.0.0.0/16), the recipe refuses before any formatting : WAN and LAN would be on the same network.

    Cannot install gw on 10.0.0.50: the box network (10.0.0.0/24 on enp1s0) overlaps
    zone 'main' (10.0.0.0/16), so its WAN and LAN would share one network.

    The zone prefix is final : change the box network (subnet or DHCP range), reboot the ISO, start over.

  2. Recable

    At the prompt Now unplug this machine from the box and plug it into a LAN port of gw, unplug the administration workstation from the box and plug it into a LAN port of the gateway (or of the switch). Nothing to press : the recipe waits up to 30 minutes for 10.0.1.1 to respond, then runs configure, apply and a final reboot.

    No response after 30 minutes :

    Fenêtre de terminal
    just configure gw 10.0.1.1
    just apply gw

    This pause only happens if the gateway keeps its SSH closed on the box side (coordination inactive, or gateway.vpn.ipv4 already declared) : see SSH access according to role.

  3. Finish

    Fenêtre de terminal
    just apply-local

    The administration workstation takes its fixed address (10.0.2.1).

For a first gateway, prefer a plain disk (server-1-disk) : it reboots on its own after a power outage, otherwise the network stays down until someone types the passphrase. Encryption and remote unlocking are described in Disk encryption (LUKS).

A gateway is often prepared elsewhere than at its destination. Connect its WAN interface to the local network of the host zone : it receives there the gateway address that this zone reserves for it based on its MAC. Here, the gateway’s mac key (the - MAC: line on the ISO screen) remains useful.

Three conditions :

  • the gateway’s mac key is declared in etc/config.yaml ;
  • the host zone’s gateway has been redeployed from this declaration;
  • the administration machine too, so that SSH reads the redirection set up during installation.

Then, just full-install gw needs no address : the tooling computes the target and follows it from start to finish. The principle is described in Machines outside their zone.

Someone on site connects the gateway to the box and starts it on the just build-iso image (it carries the deployment key) ; the administrator installs over SSH. This path requires active coordination (HCS) and gateway.vpn.ipv4 not declared : otherwise SSH stays closed on the box side once the gateway is installed.

  1. Redirect port 22 of the box to the gateway.
  2. Install with the box’s public IP address : just full-install gw nixos <ip-publique>.
  3. Remove the redirection after declaring gateway.vpn.ipv4 and applying : the gateway no longer responds from the Internet, access goes through the VPN (just enter gw).

A gateway is a Tailscale client: it advertises its zone’s subnet in the tailnet. As long as it is not enrolled there, the other zones cannot see it. just full-install enrolls it on the way ; otherwise, or to check :

Fenêtre de terminal
just tailnet-enroll gw

All that remains is to declare its tailnet address: see Enregister a gateway.

  • Linux hosts: see Add a machine.
  • Smartphones, tablets, third-party PCs: connect automatically to the gateway’s network.

Replacing the computer of a gateway in service is a distinct procedure : the machine is new, but its state is not. See Migrating a gateway’s hardware.

A wrong code costs 10 seconds of waiting (PAM delay), and the wizard allows three attempts. A wrong code and an expired code give the same refusal : reread the screen. After six 10-minute codes, pairing closes ; the machine’s dnf-pair command generates a new one.

“not the machine whose screen shows this code”?

Section titled ““not the machine whose screen shows this code”?”

The FFFF fingerprint of the code does not match the machine responding at this address : another device on the network, incorrectly recorded address. Nothing was sent ; check the address on the screen.