# Gateways in pairs

_For tartan 0.9.36._

A gateway brings a site's LAN onto your network.

A gateway brings a site's LAN onto your network. Run two per site, on two hosts, so one always serves.

A gateway is a small Linux virtual machine on your own host at the site. Tartan builds it from one Ignition file (the
settings the VM reads on its first boot), and a signed helper creates it on Windows Hyper-V.

## Before you start

- The Owner or Admin role, and a [site](add-site.md) with its LAN ranges and its LAN network card (`eth0`).
- A Windows Hyper-V host at the site with an external virtual switch on the site's LAN. The VM takes 2 GB of
  memory, and the helper refuses to start it if the host would be left with less than 6 GB free.
- The node gets its LAN address by DHCP and must reach control, Tartan's control plane, over the
  internet.
- The released `tartan` CLI on the host as well. It needs no sign-in there: the helper uses it to check the
  Ignition offline.

## 1. Check that control can build one

```sh
tartan edge site-node show --org acme
tartan org show --org acme
```

`site-node show` answers `verified`. When it is `false`, no site node can be built yet: its `why` says so. When it is
`true`, note `gateway_image` and `nat64_image` (each `sha256:...`). `org show` gives the organization's id: the helper
takes the id, not the handle.

## 2. Fetch the helper

On your own computer:

```sh
tartan edge site-node fetch --org acme --dir tartan-node
```

It downloads the helper `New-TartanSiteNode.ps1` (signed by TechSolve LLC), its README and the VM's base image,
checks every file against control's listing, and writes `run-node.cmd`. If any check fails, no folder is left.
Copy the folder to the Hyper-V host and put the released `tartan.exe` beside it. On the first run, the host asks
whether to trust TechSolve LLC as a publisher: answer **Always run**.

## 3. Dry-run on the host

`-WhatIf` runs every host check (the signature, the switch, the VLAN, the LAN, the VM name, the memory) and
changes nothing:

```powershell
powershell.exe -NoProfile -ExecutionPolicy AllSigned -File New-TartanSiteNode.ps1 -Kind gateway -Name warehouse-gw1 -Site warehouse -Org <org id> -ControlUrl <control url> -ExpectCidr 192.168.20.0/24 -Switch <switch> -Vlan 0 -BaseVhdx <base vhdx> -KvpCtl <kvpctl exe> -Tartan .\tartan.exe -WhatIf
```

`-Vlan 0` is untagged. On a switch that carries tagged VMs, give the VLAN: the helper never guesses it.

## 4. Mint the Ignition

On your own computer. This steps up, has no dry run, and its answer holds a one-hour join code: treat the file like
one. The helper takes it for 15 minutes from minting.

```sh
tartan edge ignition --org acme --kind gateway --name warehouse-gw1 --site warehouse --image ghcr.io/tartan-networks/tartan-gateway@<gateway_image> --nat64_image ghcr.io/tartan-networks/tartan-nat64@<nat64_image> --control_url <control url> --host <hyper-v host> --json > answer.json
```

`--nat64_image` installs the NAT64 translator, which [printers and legacy systems](legacy-systems.md) need.

## 5. Build it, then wait for it

Move `answer.json` to the host and run the step 3 line with `-IgnitionFile answer.json -NoWait` in place of
`-WhatIf`, and without `-Site` (the answer carries the site). The helper makes the VM, injects the Ignition, starts
it, deletes the answer file and prints a `-WaitOnly` line. Run that line on your own computer: it waits until the node
has enrolled, then checks it with `tartan edge converge` until it has converged. That check is a change, not a read:
your passkey approves each one.

On a host where you can approve passkey prompts, the helper mints the Ignition itself: run the step 3 line without
`-WhatIf`, and add `-Nat64Image ghcr.io/tartan-networks/tartan-nat64@<nat64_image>`.

## 6. The second gateway

Build the second gateway the same way, with another name, on a second Hyper-V host. Tartan gives each gateway its
own update window and refuses one that overlaps its partner's: the two never update together.

Gateways run in pairs: one powered off, new connections recovered in under 20 s, no lost flows. A rebooted gateway
is serving again in about 24 s.

To rebuild a gateway, run the helper with `-Replace`. For a site's only gateway it also needs `-AckNoPartner`, and
the site has no gateway while it rebuilds.

In the console, **Sites** (pick a site) and **Control plane** both have **Add a gateway**: it gives the
`tartan edge ignition` command to fill in and run.

## Check it worked

```sh
tartan edge list --org acme
tartan edge converge --org acme
```

`edge list` shows each node and its health. `edge converge` checks every node now, and your passkey approves it each
time: each node should say
`CONVERGED`. In the console, **Control plane** has **Check now**, and **Sites** shows each gateway as **Online** or
**Offline**.

## Next

- [Printers and legacy systems](legacy-systems.md)
- [Site relays](site-relays.md)
- [Add a site](add-site.md)
