61 lines
2.4 KiB
Markdown
61 lines
2.4 KiB
Markdown
|
|
# 03 — SSH, mDNS and Tailscale on Termux
|
||
|
|
|
||
|
|
Termux's Bionic libc does **not** resolve `.local` names. This repo ships small Python helpers that fix this without needing root or a custom resolver.
|
||
|
|
|
||
|
|
## Scripts involved
|
||
|
|
|
||
|
|
| Script | Role |
|
||
|
|
|--------|------|
|
||
|
|
| `mdns-resolve` | Resolve `<host>.local` via raw multicast UDP. Returns the IP or non-zero. |
|
||
|
|
| `mdns-publish.py` | Publish this device on the LAN as `movil.local` (or whatever you choose) using `zeroconf`. |
|
||
|
|
| `ssh-mdns-proxy` | SSH `ProxyCommand` that tries mDNS first, then Tailscale DNS. Used from `~/.ssh/config`. |
|
||
|
|
| `ssh-fallback` | Lower-level fallback: tries Tailscale, then LAN. Useful when Tailscale is flaky. |
|
||
|
|
|
||
|
|
## SSH config
|
||
|
|
|
||
|
|
Drop the contents of `config/ssh_config.example` into `~/.ssh/config` (or merge it).
|
||
|
|
|
||
|
|
The key entries:
|
||
|
|
|
||
|
|
```ssh-config
|
||
|
|
Host *.local
|
||
|
|
ProxyCommand ~/.local/bin/ssh-mdns-proxy %h %p
|
||
|
|
|
||
|
|
Host lenovo-ideapad
|
||
|
|
ProxyCommand ~/.local/bin/ssh-mdns-proxy %h %p
|
||
|
|
|
||
|
|
Host *.YOUR-TAILNET.ts.net
|
||
|
|
User YOUR_USER
|
||
|
|
```
|
||
|
|
|
||
|
|
Adjust the username and the tailnet domain. The proxy command will try mDNS first, then fall through to your Tailscale magic-DNS name (env `TAILSCALE_DOMAIN`).
|
||
|
|
|
||
|
|
## Publishing this device as `movil.local`
|
||
|
|
|
||
|
|
If you want the device to be reachable as `movil.local` from your LAN:
|
||
|
|
|
||
|
|
```bash
|
||
|
|
# One-shot foreground (to see errors):
|
||
|
|
python ~/.local/bin/mdns-publish.py
|
||
|
|
|
||
|
|
# Background (typical use, from ~/.bashrc):
|
||
|
|
nohup python ~/.local/bin/mdns-publish.py >>~/.cache/mdns.log 2>&1 &
|
||
|
|
disown
|
||
|
|
```
|
||
|
|
|
||
|
|
**Gotcha:** `zeroconf` (the pip package) is **not** part of a `pkg`-managed install. If you restore Termux from a `tar` backup, `zeroconf` will be missing from `$PREFIX/lib/python*/site-packages` and the script will silently fail with `ModuleNotFoundError`. Re-run `pip install zeroconf` after every restore.
|
||
|
|
|
||
|
|
## Logging, not silencing
|
||
|
|
|
||
|
|
The `.bashrc` auto-start lines in this repo (`config/bashrc.snippet`) deliberately log to a file instead of `/dev/null`. Silent failures are the single most painful class of bug after a restore — keep the logs.
|
||
|
|
|
||
|
|
## Tailscale
|
||
|
|
|
||
|
|
Tailscale on Termux runs **as the Android app**, not as a CLI inside Termux. You can't `tailscale up` from a shell. The app provides magic DNS for `*.YOUR-TAILNET.ts.net`, which Bionic-libc resolves fine (it's just a regular DNS query).
|
||
|
|
|
||
|
|
When you list hosts in `~/.ssh/config`, prefer:
|
||
|
|
1. `<host>.local` for fast LAN access
|
||
|
|
2. `<host>.YOUR-TAILNET.ts.net` for off-LAN
|
||
|
|
|
||
|
|
Never hardcode IPs — they rotate.
|