最近讀研入組,組里服務器是IPv6地址,不知道為什么校園網連不上,ping6都ping不通,試過網上博客的各種方法了,最后總是顯示:
1 ping6: UDP connect: No route to host
於是萬能的大師兄說:給你搭一個IPv4的跳板機,你先連接到跳板,然后再連服務器!
非常高興,記錄一下兩種腳本的使用方法。
方法一:使用bash/shell腳本
IPv4登陸:
首先添加秘鑰信任,在本地PC執行: ssh-copy-id -i ~/.ssh/id_rsa.pub your_name@xx.xxx.x.xx
直接執行: ssh your_name@xx.xxx.x.xx
IPv6(跳轉機):
首先添加秘鑰信任,在本地PC執行: ssh-copy-id -i ~/.ssh/id_rsa.pub your_name@xx.xxx.x.xx
直接執行: ssh your_name@xx.xxx.x.xx
現在到了跳板機這里了。
在跳板機添加密鑰信任,在跳板機執行: ssh-copy-id -i ~/.ssh/id_rsa.pub your_name@xxxx:xxxx:xx:xxxx:xxxx:xxxx:xxxx:xxxx
直接執行: ssh your_name@xxxx:xxxx:xx:xxxx:xxxx:xxxx:xxxx:xxxx
之后登陸,只需輸入 ssh your_name@xx.xxx.x.xx "ssh your_name@xxxx:xxxx:xx:xxxx:xxxx:xxxx:xxxx:xxxx"
方法二:使用expect交互腳本
IPv4登陸:
在根目錄下新建腳本sshlogin: vim sshlogin
按i進入insert模式,粘貼:
1 #!/usr/bin/expect 2 3 set PORT 22 4 set HOST xx.xxx.x.xx 5 set USER your_name 6 set PASSWORD xxxxxxxxx 7 8 spawn ssh $USER@$HOST 9 expect { 10 "yes/no" {send "yes\r";exp_continue;} 11 "*password:*" { send "$PASSWORD\r" } 12 } 13 14 interact
新建profile,command類型,執行內容為expect 你的sshlogin文件地址,如下:
之后直接打開這個profile就行了
IPv6(跳轉機):
在新建了IPv4 profile的基礎上,ssh your_name@xxxx::xxxx::xxxx::xxxx::xxxx::xxxx
輸入密碼,即可。