【问题标题】:How to send request through an SSH host如何通过 SSH 主机发送请求
【发布时间】:2019-01-14 05:03:27
【问题描述】:

简介

我在一台机器A中,有一个名为B中间机器(Jump Server),还有一个'外部'机器C。因为我不能直接连接C,但是我可以ssh登录到B

现在我会先ssh登录到B,然后从B发送请求,例如:

$ ssh myname@<ip_B> -p <port_B>
myname@<ip_B>'s password:
Last login: Tue Aug  7 10:14:21 2018 from ...

登录B后,我使用curl发帖。

[myname@<ip_B>]$ curl -X POST http://<ip_C>:<port_C>/<route> -F 'my_post_key=my_post_value'

问题

  • 我想知道我是否可以使用 B 作为 SSH 主机并使用 curl 直接从 A 发送我的请求?
  • 由于我使用的是Postman,Postman 中是否有解决方案?

【问题讨论】:

    标签: curl ssh postman


    【解决方案1】:

    你可以使用隧道,像这样:

    $ ssh -N -L 8080:machine-C:80 machine-B
    

    -L 选项将通过 ma​​chine- 从端口 8080 (ma​​chine-A) 到 ma​​chine-C 中的端口 80 进行本地端口转发B

    然后从机器-A

    $ curl -H "host: example.com" 0:8080
    

    如果 ma​​chine-C 托管多个站点,您可能需要传递 host 标头。

    隧道开通后,您可以在邮递员中使用127.0.0.1:8080

    【讨论】:

    • 第一个 ssh 命令也在 machine-A 上运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-01
    • 2017-04-30
    • 2017-10-09
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2023-01-03
    相关资源
    最近更新 更多