SSH connection using IPv6 address
I’m trying to connect to a machine in Hetzner Cloud using IPv6. ssh 2a01:4f8:c17:2000::/64
doesn’t work, but ssh root@2a01:4f8:c17:2000::1
does.
The IPv6 address was copied from the Hetzner Cloud console.
The ~/.ssh/config
file can be configured to apply different proxy rules for IPv4 and IPv6 addresses. This setup allows you to specify a proxy command for IPv4 addresses while handling IPv6 addresses differently.
Host 192.168.1.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Host *.*.*.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
ProxyCommand corkscrew localhost 7890 %h %p
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
When running ssh root@192.168.1.3
, the following output shows the SSH client applying configuration options from the ~/.ssh/config
file:
debug1: Reading configuration data /Users/lzwjava/.ssh/config
debug1: /Users/lzwjava/.ssh/config line 1: Applying options for 192.168.1.*
debug1: /Users/lzwjava/.ssh/config line 5: Applying options for *.*.*.*
debug2: add_identity_file: ignoring duplicate key ~/.ssh/id_rsa
debug1: /Users/lzwjava/.ssh/config line 10: Applying options for *
debug2: add_identity_file: ignoring duplicate key ~/.ssh/id_rsa
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.1.3 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/lzwjava/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/lzwjava/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: channel_clear_timeouts: clearing
debug1: Executing proxy command: exec corkscrew localhost 7890 192.168.1.3 22
The SSH connection speed was noticeably slow, so I reverted to the following simpler configuration:
Host 192.168.1.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
ProxyCommand corkscrew localhost 7890 %h %p
The issue arises when using IPv6 addresses with the ProxyCommand corkscrew localhost 7890 %h %p
directive, as this proxy command may not handle IPv6 addresses correctly.
The configuration above is still not working. However, the one below is fine.
Host 192.168.1.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Host !192.*.*.*
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
ProxyCommand corkscrew localhost 7890 %h %p
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa