我有一个服务器,我们将调用hub-server.tld三个IP地址100.200.130.121,100.200.130.122和100.200.130.123。 我有三个不同的机器在防火墙后面,但是我想使用SSH将一台机器连接到每个IP地址。 例如:machine-one应在100.200.130.121的端口22上监听SSH,而machine-2应该在100.200.130.122上执行相同的操作,以此类推,以便在所有机器上可能相同的端口上执行不同的服务。
SSH的手册页中有-R [bind_address:]port:host:hostport
我已经启用了网关端口,但是当使用具有特定IP地址的-R
时,服务器仍然在所有接口上监听端口:
# ssh -NR 100.200.130.121:22:localhost:22 [email protected]
# netstat -tan | grep LISTEN tcp 0 0 100.200.130.121:2222 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 :::80 :::* LISTEN
有没有一种方法可以使SSH只转发特定IP地址上的连接到一台机器,这样我就可以同时在其他IP地址上侦听端口22,或者我将不得不使用iptables做些什么? 这里是我的SSHconfiguration中不是评论/默认的所有行:
Port 2222 Protocol 2 SyslogFacility AUTHPRIV PasswordAuthentication yes ChallengeResponseAuthentication no GSSAPIAuthentication no GSSAPICleanupCredentials no UsePAM yes AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT AcceptEnv LC_IDENTIFICATION LC_ALL AllowTcpForwarding yes GatewayPorts yes X11Forwarding yes ClientAliveInterval 30 ClientAliveCountMax 1000000 UseDNS no Subsystem sftp /usr/libexec/openssh/sftp-server
从sshd_config(5)
:
GatewayPorts
Specifies whether remote hosts are allowed to connect to ports forwarded for the client. By default, sshd(8) binds remote port forwardings to the loopback address. This prevents other remote hosts from connecting to forwarded ports. GatewayPorts can be used to specify that sshd should allow remote port forwardings to bind to non-loopback addresses, thus allowing other hosts to connect. The argument may be “no” to force remote port forwardings to be available to the local host only, “yes” to force remote port forwardings to bind to the wildcard address, or “clientspecified” to allow the client to select the address to which the forwarding is bound. The default is “no”.
你想把这个设置为clientspecified
而不是yes
。