Ssh

ssh:沒有到主機的路由

  • April 5, 2017

我無法在埠 9922 上設置 ssd。使用埠 22 上的標準配置一切正常。然後我通過將此行添加到 thssshd_config文件將埠更改為 9922:

Port 9922

我可以毫無問題地通過埠 22 連接到 LAN 中的伺服器。切換到埠 9922 後,我得到以下輸出:

# ssh -vvv -p 9922 root@192.168.26.153
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.26.153 [192.168.26.153] port 9922.
debug1: connect to address 192.168.26.153 port 9922: No route to host
ssh: connect to host 192.168.26.153 port 9922: No route to host
#

nmap -p 9922 192.168.26.153給出:

# nmap -p 9922 192.168.26.153

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2012-06-11 08:09 CEST
Interesting ports on 192.168.26.153:
PORT     STATE    SERVICE
9922/tcp filtered unknown
MAC Address: 4A:34:E7:11:9F:22 (Unknown)

Nmap finished: 1 IP address (1 host up) scanned in 0.184 seconds
#

任何想法缺少什麼?

ifconfig在目標機器上給出:

eth0      Link encap:Ethernet  Hardware Adresse 4A:34:E7:11:9F:22  
         inet Adresse:192.168.26.153  Bcast:192.168.26.255  Maske:255.255.255.0
         inet6 Adresse: fe80::4834:e7ff:fe11:9f22/64 G?ltigkeitsbereich:Verbindung
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:2723010 errors:0 dropped:0 overruns:0 frame:0
         TX packets:552 errors:0 dropped:0 overruns:0 carrier:0
         Kollisionen:0 Sendewarteschlangenl?nge:1000 
         RX bytes:561183811 (535.1 MiB)  TX bytes:52703 (51.4 KiB)
         Interrupt:24 

lo        Link encap:Lokale Schleife  
         inet Adresse:127.0.0.1  Maske:255.0.0.0
         inet6 Adresse: ::1/128 G?ltigkeitsbereich:Maschine
         UP LOOPBACK RUNNING  MTU:16436  Metric:1
         RX packets:0 errors:0 dropped:0 overruns:0 frame:0
         TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
         Kollisionen:0 Sendewarteschlangenl?nge:0 
         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

並且route -n

# route -n
Kernel IP Routentabelle
Ziel            Router          Genmask         Flags Metric Ref    Use Iface
192.168.10.0    192.168.26.1    255.255.255.0   UG    0      0        0 eth0
192.168.26.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.26.4    0.0.0.0         UG    0      0        0 eth0
# 

iptables -L返回:

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 
ACCEPT     icmp --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh 
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
# 

雖然停止防火牆不是一個聰明的主意,但我建議啟動防火牆並允許傳入埠 9922

/sbin/iptables -A INPUT -p tcp –dport 9922 -j ACCEPT

您可能必須在您的伺服器上啟用 SELinux。如果您不需要它,可以setenforce 0通過修改/etc/selinux/config文件暫時禁用或永久禁用它。

如果你想使用 SELinux,讓它允許sshd綁定到埠 9922:

semanage port -a -t ssh_port_t -p tcp 9922

引用自:https://serverfault.com/questions/397470