Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is my situation:

Two computer under the same router, 192.168.1.101 and 192.168.1.102

This is what I like to do: On 192.168.1.101, while accessing port 22 with localhost, it directs the traffic to 192.168.1.102 port 22.

In another word, I would like to forward whatever traffic from localhost to another local IP.

Is there any solution for what I need?

share|improve this question
6  
It might help to know what you are trying to achieve, knowing your OS would help, too. –  Baarn Jul 1 '12 at 19:15
    
netcat ... but you'd have to disable ssh on 1.101. What ARE you trying to do? –  lornix Jul 2 '12 at 12:07
    
You're misusing the term localhost. Sounds like you think it's the locally assigned internet accessible IP address. It isn't. The loopback network (127.0.0.0) which will contain your localhost (127.0.0.1) is used for all IP communications that are supposed to happen within that box you call a computer. This is one of those questions, which if you have to ask it, you don't understand enough to be messing around with it. –  Fiasco Labs Jan 13 '13 at 5:26

2 Answers 2

Not sure if that is a smart thing to do. A lot of services intended to run on the local machine use either 127.0.0.1 (which would be no problem with your change) or localhost (in which case your change would mess things up) to connect to other services on the same machine. And a lot of other packages comes configured this way.

If the purpose is to have the same name to connect crosswise, regardless on which machine you are, I'd rather recommend to use a different name for this. Instead of "localhost" you could e.g. use "crosshost" - and with that follow the hints given by Indrek: Check for your hosts file (on Linux/Unix and probably also Mac it is /etc/hosts, on Windows it is C:\Windows\System32\drivers\etc\hosts (without extension -- so take care here, Windows usually already has some other hosts.* file in that directory). Do NOT comment out the 127.0.0.1 localhost line, nor modify it -- leave it as is. Just add a line

192.168.1.101 crosshost

on the 192.168.1.102 machine, and similarly with the other address on the other machine. Now you can e.g. ssh crosshost to connect to one machine from the other, or copy files over with scp filename.ext crosshost:/path/to/put, or whatever you intended.

share|improve this answer

Don't redefine the meaning of localhost. You'll break things in surprising ways.

Instead, look at the -L and -R options in ssh(1). They make it easy to redirect a port on the local machine to the IP address and port of a remote machine. Plus the tunnel is secured by SSH.

Note that these tunnels are not necessarily specific to ssh/shell traffic. It can be for arbitrary traffic.

share|improve this answer

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.