Configuration Template
CONFIG
# Base configuration: define the alias and the default authentication method
Host custom-alias
User your-username
PreferredAuthentications publickey
IdentityFile "path/to/your/private_key"
# Internal network route: detect whether the internal network is reachable via ping
Match host custom-alias exec "ping -n 1 -w 100 internal.ip >nul 2>&1"
HostName internal.ip
Port internal_port
# External network route: fallback when the internal network is unreachable
Match host custom-alias
HostName external.ip
Port external_port
Usage Steps
Replace the configuration values
custom-alias: set an alias that's easy to rememberyour-username: replace with your login usernamepath/to/your/private_key: replace with the path to your private key fileinternal.ip: replace with the internal IP addressinternal_port: replace with the internal portexternal.ip: replace with the external IP addressexternal_port: replace with the external port
Connection command
BASHssh custom-alias
How It Works
- The SSH client receives a connection request for
custom-alias - It checks the Match conditions in order:
- First it runs the ping command to test connectivity to the internal network
- If the internal network is reachable, the internal configuration is used
- If the internal network is unreachable, the external configuration is used
- It connects using whichever configuration applies
Notes
- Windows system paths use backslashes
\ - Linux/Mac system paths use forward slashes
/ - ping command arguments:
- Windows:
ping -n 1 -w 100 - Linux/Mac:
ping -c 1 -W 1
- Windows:
- Make sure the configuration file has the correct permissions (600 is recommended on Linux/Mac)