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.

I have a development server, which is only accessible from 127.0.0.1:8000, not 192.168.1.x:8000. As a quick hack, is there a way to set up something to listen on another port (say, 8001) so that from the local network I could connect 192.168.1.x:8001 and it would tunnel the traffic between the client and 127.0.0.1:8000?

share|improve this question
1  
netcat can do this. –  Andy Apr 1 '11 at 5:25
add comment

3 Answers 3

up vote 7 down vote accepted

Using ssh is the easiest solution.

ssh -g -L 8001:localhost:8000 -f -N user@remote-server.com

This forwards the local port 8001 on your workstation to the localhost address on remote-server.com port 8000. -g means allow other clients on my network to connect to port 8001 on my workstation. Otherwise only local clients on your workstation can connect to the forwarded port. -N means all I am doing is forwarding ports, don't start a shell. -f means fork into background after a successful SSH connection and log-in. Port 8001 will stay open for many connections, until ssh dies or is killed. If you happen to be on Windows, the excellent SSH client PuTTY can do this as well. Use 8001 as the local port and localhost:8000 and the destination and add a local port forwarding in settings. You can add it after a successful connect with PuTTY.

share|improve this answer
add comment

Using the traditional nc is the easiest solution:

nc -l -p 8001 -c "nc 127.0.0.1 8000"

This version of nc is in the netcat-traditional package on Ubuntu. (You have to update-alternatives or call it nc.traditional.)

Note that in contrast to ssh this is not encrypted. Keep that in mind if you use it outside one host.

share|improve this answer
add comment
mkfifo a
mkfifo b
nc 127.0.0.1 8000 < b > a & #openbsd netcat
nc -l 0.0.0.0 8001 < a > b &
share|improve this answer
add comment

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.