I need to redirect a port to another one, but also close the original port for external users.
Until now, I've done that by blocking the original port with iptables, and a small utility called portfwd to redirect it (portfwd.sourceforge.net)
Works well, but portfwd takes up memory for each port redirection (1 instance / redirection) and it uses processor resources.
Doing it with iptables works using this command as long as both sourcePort and destPort are open:
/sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport sourcePort -j REDIRECT --to-ports destPort
If the following command is added to prevent direct access to destPort from outside, it also blocks the redirected access.
/sbin/iptables -A INPUT -p tcp --dport destPort -j DROP
I then tried this, but it did not work any better:
/sbin/iptables -A INPUT -p tcp --sport sourcePort --dport destPort -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport destPort -j DROP
---
So, my question is, how can direct external access to the destination port be blocked while not preventing it from the source port ?
Code:
That works :
sourcePort ----+
|
destPort ----+---- service (from both ports)
That's what I would like
sourcePort ----+
|
destPort --X +---- service (from sourcePort only)
but that's what I get :
sourcePort ----+
|
destPort ----+--X - service (inaccessible)
Any ideas ?