Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to use eboard to connect to the FICS servers (http://www.freechess.org), but it fails because port 5000 is blocked (company firewall). However, I can connect to the server through the telnet port (23):

telnet freechess.org 23
(succeeds)
telnet freechess.org 5000 
(fails)

Unfortunately the port number is hardcoded (see here: http://ubuntuforums.org/archive/index.php/t-1613075.html). I'd rather not have to hack the source code as the author of that thread ended up doing. Can I just forward the port on my local machine using iptables? I tried:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 5000 -j REDIRECT --to-port 23

and

sudo iptables -t nat -I OUTPUT --src 0/0 -p tcp --dport 5000 -j REDIRECT --to-ports 23

but these didn't work...

Note that:

$ sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere            tcp dpt:5000 redir ports 23

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
REDIRECT   tcp  --  anywhere             anywhere            tcp dpt:5000 redir ports 23 

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
share|improve this question
    
Use sudo iptables -t nat -L to list the nat table rules. –  Richm Jan 3 '12 at 15:29
    
Thanks - have updated the question –  tdc Jan 3 '12 at 15:38

1 Answer 1

up vote 4 down vote accepted

-j REDIRECT redirects to your own machine. If you want to redirect to a different port on the remote machine, use -j DNAT --to-destination :23

share|improve this answer
    
Awesome, that worked: sudo iptables -t nat -I OUTPUT --src 0/0 -p tcp --dport 5000 -j DNAT --to-destination :23 –  tdc Jan 3 '12 at 16:36
    
So how do you undo it? –  Will Oct 21 '12 at 3:11
    
@Will By removing the iptables rule again, with sudo iptables -t nat -D OUTPUT 1 where 1 is the position of the rule in the chain. –  tumbleweed Oct 21 '12 at 11:10
    
Thanks @tumbleweed I googled a little harder and found a good explanation here serverfault.com/questions/288729/… –  Will Oct 21 '12 at 19:18

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.