
我嘗試使用設定 git 並將其用於 github,然後當我按照幫助文件進行操作時,但是當我設定 ssh 密鑰部分的第 5 步:測試一切,當我使用此命令時:我收到錯誤:ssh -T [email protected]
ssh:連接到主機 github.com 連接埠 22:沒有到主機的路由
然後我使用了這個指令:
ssh -vT [email protected]
這是我得到的:
OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011
debug1: Reading configuration data /home/jacos/.ssh/config
debug1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: connect to address 207.97.227.239 port 22: No route to host
ssh: connect to host github.com port 22: No route to host
我用谷歌搜尋了一段時間,發現我必須檢查 iptables 是否阻止了連接埠。結果如下:
~$ sudo /sbin/iptables -L -n
[sudo] password for jacos:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:67
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:67
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:53
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:53
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 0.0.0.0/0 10.42.43.0/24 state RELATED,ESTABLISHED
ACCEPT all -- 10.42.43.0/24 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
我嘗試了吉爾斯建議的命令:
tcptraceroute github.com 22
這是我得到的:
Selected device eth0, address 222.20.58.XX(sorry...I masked part of my ip), port 33281 for outgoing packets
Tracing the path to github.com (207.97.227.239) on TCP port 22 (ssh), 30 hops max
1 222.20.58.254 0.891 ms 0.850 ms 0.693 ms
2 zxq-xs-h3c7510e.hust.edu.cn (115.156.255.137) 1.253 ms 1.569 ms 2.837 ms
3 zxq-xs-rjs8606.hust.edu.cn (115.156.255.130) 0.729 ms 0.678 ms 0.629 ms
4 115.156.255.174 0.794 ms 6.279 ms 16.569 ms
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *
12 * * *
13 * * *
14 * * *
15 * * *
16 * * *
17 * * *
18 * * *
19 * * *
20 * * *
21 * * *
22 * * *
23 * * *
24 * * *
25 * * *
26 * * *
27 * * *
28 * * *
29 * * *
30 * * *
Destination not reached
好像路由停在115.156.255.174,不知道在哪裡。
我不明白這意味著什麼。會不會阻塞22埠?
對了,我可以上網,訪問github.com。我使用的是 Ubuntu 11.10。
有人能幫忙嗎?謝謝!
答案1
你的INPUT
鏈條接受一切。您還沒有展示您的OUTPUT
鏈條,但我假設它也接受所有內容。這意味著您和 Github 之間的連線被阻止。您學校的防火牆可能會阻止到連接埠 22 的傳出連線。
您可以透過安裝來更好地了解資料包在哪裡被攔截TCP追蹤路由 並運行
tcptraceroute github.com 22
。
請學校的管理員開啟連接埠 22,或至少(如果他們不願意)將連接埠 22 開啟github.com
。您對網路的使用是一種嚴肅的使用,應該允許學生這樣做。
如果管理員不讓步,並且您使用代理連接到網絡,您也許能夠讓代理來中繼流量(它可能會也可能不會工作,具體取決於代理的配置方式)。看是否可以透過 80 連接埠進行 SSH?
順便說一句,您的INPUT
鏈允許所有傳入流量,因為您只有ACCEPT
規則和ACCEPT
策略。典型的規則集將阻止未經審查的連接埠上的傳入 UDP 流量,並阻止未經審查的連接埠上的傳入 TCP 連線:
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 123 -j ACCEPT
iptables -P INPUT DROP