Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 555, I want to get a connection to computer on port 555 (where I have my server).

Any idea?

share|improve this question

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
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

share|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 On windows it's called port tunell. – marc May 2 '10 at 19:31
I would have thought IP tables would work by telneting 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

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
share|improve this answer

Use redir instead of iptables:

share|improve this answer

Your Answer


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.