IPv6アドレスを使用したSSH接続

Home PDF Audio

Hetzner Cloudの機械にIPv6を使って接続しようとしています。ssh 2a01:4f8:c17:2000::/64は機能しませんが、ssh root@2a01:4f8:c17:2000::1は機能します。

IPv6アドレスはHetzner Cloudコンソールからコピーしました。

~/.ssh/configファイルは、IPv4アドレスとIPv6アドレスに対して異なるプロキシルールを適用するように設定できます。この設定により、IPv4アドレスのプロキシコマンドを指定しながら、IPv6アドレスを異なる方法で処理できます。

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   

ssh root@192.168.1.3を実行すると、SSHクライアントが~/.ssh/configファイルの設定オプションを適用していることが次の出力に示されています。

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

SSH接続速度が著しく遅かったので、次のより簡単な設定に戻しました。

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 

ProxyCommand corkscrew localhost 7890 %h %pディレクティブを使用する場合、このプロキシコマンドはIPv6アドレスを正しく処理できない可能性があるため、IPv6アドレスを使用すると問題が発生します。

上記の設定はまだ機能していません。しかし、下記の設定は問題ありません。

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  

Back 2025.02.22 Donate