Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

NOTE: I'm not explaining why I want to do this. But here is the requirement.

There are 4 hosts. Host A, Host B, Host C, Host D

  1. Host A is running some application which can be accessed at port 8001
  2. I forwarded port 8001 of Host A to 8002 of Host B.
  3. Host B is accessible only using Host C.

So, again, I forwarded port 8002 of Host B to 8003 of Host C.

Now, from Host D...when I say: https://HostC:8003 -- it should take me to the application running on Host A. But I'm not able to do that.

But what I could do was, I forwarded port 22 of Host A to port 7777 of Host B. Then, from Host C, I ran:

$ ssh Host B -p 7777 -L 6666:localhost:8001

Doing this, ssh Host B -p 7777, took me to a command line on Host A. Hence port 8001 of Host A was directly forwarded to 6666 of Host C.

Now, from Host D, https://Host C:8001 worked! But, I want to do it using the former way.

  • How can I do that?
  • What am I missing here?
share|improve this question
1  
"I forwarded port 8001 of Host A to 8002 of Host B." You probably mean that the other way round. (And "I forwarded port 8002 of Host B to 8003 of Host C", too.) –  Hauke Laging Feb 27 at 13:45
    
you work the other way around, forward port xxx of Host C to port yyy of host B forward port yyy of host B to host A on port sss then you will be able to connect from d to a –  Kiwy Feb 27 at 13:46
    
You have not explained how you do the port forward. I guess you rewrite the target address without adapting the source address so that A answers directly to D which obviously doesn't work. –  Hauke Laging Feb 27 at 13:48
    
Yes, you need to provide the exact commands you're using. By default, the ssh arguments -L and -R listen on localhost only. We can't tell if this is the case without seeing what you're doing. –  Patrick Feb 27 at 13:58

1 Answer 1

You want to do it the other way round (reverse of your set-up).

Host D -> Host C:8003
          forwards to --> Host B:8002
                           forwards to --> Host A:8001 -> Your application

You only have 1 ssh forward to establish.

On hostC

ssh -L 8003:hostA:8001 user@hostB

then to test on hostD by accessing hostC:8003

share|improve this answer
    
Is there a simple iptable rule that i can run for destination nat from Host C -- so that whenever request comes to port 8003 of Host C, it will get redirected to 8002 of Host B. Is that possible? –  Being Gokul Feb 27 at 14:12
    
I'm not an iptable expert sorry, maybe that's a new question. First make sure it works as you want with ssh. –  X Tian Feb 27 at 14:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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