我无法在端口9922上设置ssd。在端口22上的标准configuration一切正常。 然后我通过将这一行添加到sshd_config文件中将端口更改为9922:
Port 9922
我可以通过端口22连接到局域网中的服务器,而不会出现问题。 切换到端口9922后,我得到以下ouptput:
# ssh -vvv -p 9922 [email protected] 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 #
任何想法缺less什么?
目标机器上的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 #
虽然停止防火墙并不是一个聪明的想法,但我会build议启动防火墙,并允许input端口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
你可以在你的sshd.conf中有多个Port行,例如
Port 22 Port 2222 #Protocol 2,1 Protocol 2 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress ::
我通常会这样做,因为我将在备用端口上打开外部防火墙/ NAT,但希望内部系统打到传统端口22上的服务器。
请确保在任何configuration文件更改后重新启动ssh守护进程( service sshd restart )。
如果你nmap -p 9922 192.168.26.153会发生什么? 它显示端口是否打开?
在你的SSH客户端debugging输出错误应该是“连接超时”而不是“无路由到主机”。 你和目标系统之间有什么关系?
对我来说是Selinux和防火墙的组合,我发现解决scheme是这样做的:
如已经提出的那样,放松Selinux:
semanage port -a -t ssh_port_t -p tcp 9922
之后,甚至改变防火墙权限:
sudo firewall-cmd --zone=public --add-port=9922/tcp --permanent sudo firewall-cmd --reload
这两个更改使我可以使用新的ssh-port访问服务器