This is the scenario.

My machine Host 1 Host 2

All three are Ubuntu machines. My machine and Host 1 both have public facing IPs.

Host 2 has a NAT IP and is accessible only from Host 1 through the NAT IP.

I have SSH access with sudo privileges on Host 1, Host 2 and my machine.

I have a service running on port 6550 on Host 2 and I would like to access this service from my machine.

What needs to be done?

Also, I know for a fact that there is another service running on port 8080 on Host 2, which is been exposed to the public through the IP of Host 1. i.e host2-nat-ip:8080 mapped to -> host1-public-ip:4567

  • Look into setting up an IPSec tunnel from your machine to Host 2. Assuming your SSH keys are all set up correctly, this should be reasonable straightforward. help.ubuntu.com/community/IPSecHowTo
    – Alex
    Oct 26 '16 at 12:43

I have SSH access with sudo privileges on Host 1, Host 2 and my machine.

If you can SSH from your machine to Host 2, you can use SSH port forwarding.

SSH's port forwarding feature can smuggle various types of Internet traffic into or out of a network. This can be used to avoid network monitoring or sniffers, or bypass badly configured routers on the Internet.

enter image description here

More complex applications are possible

enter image description here

An alternative is to use a tool like socat to set up a TCP relay on host1

socat TCP4-LISTEN:www TCP4:www.domain.org:www

installs a simple TCP port forwarder. With TCP4-LISTEN it listens on local port "www" until a connection comes in, accepts it, then connects to the remote host (TCP4) and starts data transfer.

You can substitute an arbitrary numeric port number in place of www (80). There are options to make this a persistent relay that handles multiple concurrent and consecutive connections.

  • i can't ssh from my m/c to host 2. i have to ssh into host1 first.
    – deepakkt
    Oct 26 '16 at 15:37
  • @deepakkt: Then you just have to use port-forwarding twice. See also amended answer. Oct 26 '16 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.