Search code examples
sshssh-tunnel

Forward server HTTP traffic to handle in another device via SSH Tunnel


I'm developing some webhook required direct access public domain to internal machine, thinking use SSH tunnel to forward data, or got alternative solution?

Hosting server & development machine are in same network

 192.168.1.2/24 (Hosting server)

2nd machine is virtual mapping using forticlient firewall without static or dynamic IP in visible in hosting server, so is 1 way initial communication right now.

In this case possible to setup SSH tunnel forward all traffic from 192.168.1.2:80 to handle in development machine port 8080?

How to ssh syntax look like?

Thanks.


Solution

  • This could be done by setting up an SSH tunnel to the remote machine:

    ssh -L localhost:80:localhost:8080 development-system
    

    Every request to port 80 on the hosting-server is now forwarded to port 8080 on the development-system.

    Please note, that the port 80 on the hosting-server could only be used, when you start the SSH command as root. Also note that the port 80 is only accessible from the hosting-server. To access the port 80 on the hosting-server from everywhere use the following:

    ssh -L 80:localhost:8080 development-system
    

    Be sure that you want that.

    A good introduction to the topic could be found at