Any idea how I can create a "virtual" listening port on my Ubuntu computer porting for remote IP?

I mean, something like this.

When I write telnet 127.0.0.1 555, I want to get a connection to computer 192.168.0.21 on port 555 (where I have my server).

Any idea?

link|improve this question

0% accept rate
feedback

2 Answers

I think iptables is what you're looking for and it should already be installed with Ubuntu.

It may take a bit of trial and error but something like the commands below should do the trick:

iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 555 -j DNAT --to 192.168.0.21:555
iptables -A INPUT -p tcp -m state --state NEW --dport 555 -i eth1 -j ACCEPT

A more detailed explanation of what these commands do can be found here.

Another method is to use a program called rinetd which is available in Ubuntu via synaptic.

Redirects TCP connections from one IP address and port to another. rinetd is a single-process server which handles any number of connections to the address/port pairs specified in the file /etc/rinetd.conf.

There's a nice guide on how to use it here

link|improve this answer
But it won't bind local port. I'm looking for "port tunneling" I don't want access that port from LAN but from local machine. On computer where i want forward it, i want say telnet localhost 555 and it should connect me to remote computer called 192.168.0.21. On windows it's called port tunell. steelbytes.com/?mid=18 – marc May 2 '10 at 19:31
I would have thought IP tables would work by telneting 127.0.0.1:55 but you could also try a program called rinetd which can redirect ports too. I've added details to the answer above. – John Rabotnik May 2 '10 at 19:58
feedback

http://www.frozentux.net/iptables-tutorial/chunkyhtml/x4033.html

You think this should be enough by now, and it really is, unless considering one final aspect to this whole scenario. What if the firewall itself tries to access the HTTP server, where will it go? As it looks now, it will unfortunately try to get to its own HTTP server, and not the server residing on $HTTP_IP. To get around this, we need to add a DNAT rule in the OUTPUT chain as well. Following the above example, this should look something like the following:

iptables -t nat -A OUTPUT --dst $INET_IP -p tcp --dport 80 -j DNAT --to-destination $HTTP_IP
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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