http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html

Remote port forwarding

Now comes the second part of this tutorial, which is remote port forwarding. This is again best to explain with an example.

Say that you’re developing a Rails application on your local machine, and you’d like to show it to a friend. Unfortunately your ISP didn’t provide you with a public IP address, so it’s not possible to connect to your machine directly via the internet.

Sometimes this can be solved by configuring NAT (Network Address Translation) on your router, but this doesn’t always work, and it requires you to change the configuration on your router, which isn’t always desirable. This solution also doesn’t work when you don’t have admin access on your network.

To fix this problem you need to have another computer, which is publicly accessible and have SSH access to it. It can be any server on the internet, as long as you can connect to it. We’ll tell SSH to make a tunnel that opens up a new port on the server, and connects it to a local port on your machine.

$ ssh -R 9000:localhost:3000 user@example.com

The syntax here is very similar to local port forwarding, with a single change of -L for -R. But as with local port forwarding, the syntax remains the same.

First you need to specify the port on which th remote server will listen, which in this case is 9000, and next follows localhost for your local machine, and the local port, which in this case is 3000.

There is one more thing you need to do to enable this. SSH doesn’t by default allow remote hosts to forwarded ports. To enable this open /etc/ssh/sshd_config and add the following line somewhere in that config file.

GatewayPorts yes

Make sure you add it only once!

$ sudo vim /etc/ssh/sshd_config

And restart SSH

$ sudo service ssh restart

After this you should be able to connect to the server remotely, even from your local machine. The way this would work is that you would first create an SSH tunnel that forwards traffic from the server on port 9000 to your local machine on port 3000. This means that if you connect to the server on port 9000 from your local machine, you’ll actually make a request to your machine through the SSH tunnel.

最新文章

  1. 批量处理sql 数据存入xml类型列
  2. [Oracle](不会的是三炮)把状态列表作为存储过程参数这件小事
  3. Cinder 组件详解 - 每天5分钟玩转 OpenStack(47)
  4. web的三种监听器
  5. PHP_ArrayList
  6. easyui-lang-zh_CN.js导入后还是英文提示
  7. css hack 大全
  8. 【Android】广播BrocastReceiver
  9. [原]bochs+dos6.22汇编环境
  10. 洛谷 [p2294] [HNOI2005] 狡猾的商人
  11. JavaScript继承详解
  12. Flask入门之flask-wtf表单处理
  13. Selenium webdriver定位iframe里面元素
  14. node 调试相关
  15. Python语言学习之C++调用python
  16. OpenDCIM-19.01操作手册
  17. maven pom.xml(公司版)
  18. 解决LNMP环境无法显示所有WordPress主题及无法编辑主题页面
  19. OPNET仿真软件资料合集
  20. spring mvc 404页面制作

热门文章

  1. 20145329 《网络对抗技术》 逆向及Bof基础实验
  2. 20172305 2018-2019-1 《Java软件结构与数据结构》第三周学习总结
  3. linux下 ip指令
  4. ref用于类类型
  5. zeptojs库解读1之整体框架
  6. linux中find与rm实现查找并删除目录或文件
  7. python 生成zip压缩包
  8. python 行列式计算
  9. torchnet package (1)
  10. Leetcode 52