SSH from outside ( the bastion )

How to reach the homelab from off-site. What is deliberately impossible from there. Read this page together with DNS and name resolution.

The path

The UniFi gateway forwards TCP 2222 from the WAN to the gatekeeper sshd on port 2222. That sshd listens on BOTH 22 ( direct LAN/VPN connections ) and 2222 ( the bastion port ). The bastion is that sshd, and jumpto:2222 behaves identically from the LAN, the VPNs and the WAN ( change of 2026-12-02 ). The public name jumpto.homelab.fredcorp.cc points at the current WAN address. The ovh-ddns timer keeps the record current.

Every off-site connection goes through this one door.

The client configuration

Put this block in ~/.ssh/config. Use your FreeIPA login in place of <your-login>. The key is the file you generated for the homelab. This block works on the LAN and off-site, for every host:

### Homelab config ###
Host jumpto.homelab.fredcorp.cc
    Port 2222
    IdentityFile ~/.ssh/homelab_servers
    IdentitiesOnly yes
    User <your-login>

Match !localnetwork 10.0.0.0/12,10.254.0.0/16,192.168.2.0/24 host *.homelab.fredcorp.cc !host jumpto.homelab.fredcorp.cc
    ProxyJump jumpto.homelab.fredcorp.cc

Host *.homelab.fredcorp.cc
    IdentityFile ~/.ssh/homelab_servers
    IdentitiesOnly yes
    User <your-login>
    ServerAliveInterval 300

This is the same block as in the from-scratch tutorial ( Phase 3 ) and the Getting access page. Do not keep different copies.

How a connection chooses its path

The Match rule reads the addresses of YOUR OWN network interfaces. OpenSSH 9.4 or newer is needed for it ( the localnetwork criterion was added in 9.4 ).

  • On the LAN, an interface is inside 10.0.0.0/12. The rule is false. The connection goes direct.
  • Off-site, no interface is inside any listed range. The rule is true. The connection goes through jumpto.

With ProxyJump, the client hands the NAME STRING of the destination to the bastion. The bastion resolves the name with the internal zone and routes the connection to the real host.

The address list after !localnetwork covers the whole internal plan: 10.0.0.0/12 is the Default LAN; 10.254.0.0/16 covers the Identity VLAN ( 10.254.0.0/24 ), the L2TP pool ( 10.254.2.0/24 ) and the WireGuard pool ( 10.254.3.0/24 ); 192.168.2.0/24 is the Teleport pool ( fixed: the UniFi UI cannot change it, verified 2026-12-02 ). A VPN client therefore behaves like a LAN client: direct connections, no bastion. This needs the VPN profile to push the internal resolver. The pools sit OUTSIDE the Default LAN on purpose; the plan and the reasons are on the network reference page.

Names from outside

The client must resolve the target name before the Match rule can run. Off-site, a public resolver answers for two kinds of names:

  • jumpto.homelab.fredcorp.cc: the real WAN address. The bastion itself.
  • every name in ovh_public_names: a PLACEHOLDER value, 10.254.0.1. The ovh-dns role keeps these records at OVH.

The placeholder routes nothing. It exists so the name resolution succeeds and the jump engages. A name that is not on the list answers NXDOMAIN off-site, and ssh stops with "Could not resolve hostname" before it connects. Add the name to ovh_public_names in group_vars/all/main.yml, then run site-dns.yml.

Emergency fallback when only the jump is reachable:

ssh -J <your-login>@jumpto.homelab.fredcorp.cc:2222 <your-login>@<internal-ip>

This form needs no name resolution. The internal IP is in the hardware reference.

Keys and passwords

The gatekeeper sshd does not accept passwords. Key authentication is the only method through the bastion, from every network. The keys live in FreeIPA. Every enrolled host fetches them through SSSD. No per-host authorized_keys file exists.

For the key to work on a LOGIN, the target host must know the login's shell. The shell role installs /bin/zsh everywhere and sets it as the FreeIPA default. A host without zsh refuses the login with a bare "Permission denied". The reason is in /var/log/secure on the target ( incident 2026-12-01 ).

First connection, and host keys

After a gatekeeper reinstall the host keys change. Clear the stale ones first:

ssh-keygen -R jumpto.homelab.fredcorp.cc
ssh-keygen -R [10.254.0.1]:2222

Fail2ban, and one caution

Repeated failed attempts ban the source address. During the 2026-11-30 incident, legitimate traffic was caught too. If connections reset from outside, try a different source address ( a hotspot ) before you assume the host is down. A ban expires on its own. Unbanning needs a shell on the gatekeeper.

Checklist

  • [ ] From outside: ssh jumpto.homelab.fredcorp.cc answers with the key and refuses a password.
  • [ ] Port 2222 forwarded on the UniFi gateway to 10.254.0.1:2222. Nothing else is forwarded.
  • [ ] The gatekeeper sshd listens on both ports: on the gatekeeper, ss -tlnp | grep sshd shows 22 and 2222.
  • [ ] DynHost record current: dig jumpto.homelab.fredcorp.cc @1.1.1.1 +short matches the current WAN address.
  • [ ] Placeholder records answer: dig nginx.homelab.fredcorp.cc @1.1.1.1 +short returns 10.254.0.1.
  • [ ] From outside: ssh nginx.homelab.fredcorp.cc lands on nginx, not on the gatekeeper. Key-only, no password prompt.