AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 809983
Accepted
bux
bux
Asked: 2016-10-20 05:29:13 +0800 CST2016-10-20 05:29:13 +0800 CST 2016-10-20 05:29:13 +0800 CST

ssh 远程端口转发:连接被拒绝

  • 772

尝试建立远程 ssh 端口转发:

在我的远程主机上,/etc/ssh/sshd_config

GatewayPorts 客户端指定

在我的本地计算机上:

ssh -g -R 1234:0.0.0.0:8000 me@my-remote-host

通过调试,我们可以阅读:

debug1: Authentication succeeded (publickey).
Authenticated to s1.bux.fr ([178.32.223.76]:22).
debug1: Remote connections from LOCALHOST:1234 forwarded to local address 0.0.0.0:8000
debug2: fd 3 setting TCP_NODELAY
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: remote forward success for: listen 1234, connect 0.0.0.0:8000
debug1: All remote forwarding requests processed

在远程主机上,我们可以联系到 1234 端口(WSGIServer/0.2 CPython/3.4.3是本地机器的 8000 端口):

# http :1234
HTTP/1.0 302 Found
Content-Type: text/html; charset=utf-8
Date: Wed, 19 Oct 2016 13:26:00 GMT
Location: /accounts/login/
Server: WSGIServer/0.2 CPython/3.4.3
Vary: Cookie
X-Frame-Options: SAMEORIGIN

我们可以查看打开的端口:

# netstat -tupln | grep 1234
tcp        0      0 127.0.0.1:1234          0.0.0.0:*               LISTEN      14460/1         
tcp6       0      0 ::1:1234                :::*                    LISTEN      14460/1

但是,从世界上的另一台机器上,我无法联系my-remote-host:1324:

# http my-remote-host:1234

http: error: ConnectionError: HTTPConnectionPool(host='my-remote-host', port=1234): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0xb6b2fbec>: Failed to establish a new connection: [Errno 111] Connection refused',)) while doing GET request to URL: http://my-remote-host:1234/

my-remote-host 上没有防火墙:

# iptables -L
[sudo] password for bux: 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
fail2ban-sshd  tcp  --  anywhere             anywhere             multiport dports ssh
fail2ban-ssh  tcp  --  anywhere             anywhere             multiport dports ssh

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain fail2ban-ssh (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

Chain fail2ban-sshd (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere

如何找到它阻塞的地方?

port-forwarding
  • 3 3 个回答
  • 32324 Views

3 个回答

  • Voted
  1. Best Answer
    Arjun sharma
    2016-10-20T06:28:51+08:002016-10-20T06:28:51+08:00
    tcp   0   0 127.0.0.1:1234    0.0.0.0:*               LISTEN   14460/1         
    

    在 netstat 的输出中可以很好地看出问题。您的远程计算机正在侦听 127.0.0.1:1234,该地址仅可用于来自该计算机的本地连接。

    要使 ssh -g(网关选项)起作用,您必须指定通配符地址或可从外部客户端访问的某些接口地址,例如:

    ssh -g -R 0.0.0.0:1234:0.0.0.0:8000 me@my-remote-host
    
    • 10
  2. bux
    2016-10-20T06:13:03+08:002016-10-20T06:13:03+08:00

    找到的解决方案是https://superuser.com/questions/588591/how-to-make-ssh-tunnel-open-to-public:

    我们必须像这样设置绑定地址:

    ssh -R 0.0.0.0:1234:0.0.0.0:8000 me@my-remote-host
    
    • 5
  3. Ipor Sircer
    2016-10-20T05:40:04+08:002016-10-20T05:40:04+08:00

    来自man ssh:

     -g      Allows remote hosts to connect to local forwarded ports.  If used
             on a multiplexed connection, then this option must be specified
             on the master process.
    

    -L用于本地转发和远程转发-R。不适用于远程。-g

    • 0

相关问题

  • 为 Cisco ASA 5510 上的端口 443/80 创建 NAT 规则和安全策略

  • 慢速路由问题

  • 通过其子网内的公共 IP 连接到默认主机是否会导致任何问题?

  • 端口镜像作为 Windows 服务

  • 使用 iptables 和 dhcpd 进行端口转发

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve