Redirect packages directed to port 5000 to another port

Posted by tdc on Ask Ubuntu See other posts from Ask Ubuntu or by tdc
Published on 2012-01-03T14:41:11Z Indexed on 2014/08/20 22:34 UTC
Read the original article Hit count: 219

Filed under:

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         

© Ask Ubuntu or respective owner

Related posts about iptables