LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Iptables problem (https://www.linuxquestions.org/questions/linux-networking-3/iptables-problem-647061/)

mpapet 06-04-2008 05:53 PM

Iptables problem
 
I'm trying to forward all traffic from port 172.18.1.40:50006 (eth0) to 172.18.1.40:5432 (postgresql)

My rules work from another machine on the LAN just fine. e.g. a telnet client connects to postgresql server on 50006. However trying to telnet from the machine hosting the postgresql server gets "connection refused." I've added the FORWARD (useless?) rules to try to get it to work on the local machine, but no go. Here are my rules. They are the only ones on the system.

#This rule maps hp's SIM postgre to the postgre default
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 50006 -j REDIRECT --to-port 5432
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 50006 -j REDIRECT --to-port 5432

iptables -t nat -A PREROUTING -p tcp -i lo --dport 50006 -j REDIRECT --to-port 5432
iptables -t nat -A PREROUTING -p udp -i lo --dport 50006 -j REDIRECT --to-port 5432

#Must accept the traffic from 50006
iptables -A FORWARD -p tcp -m state --state NEW,ESTABLISHED,RELATED -o 172.18.1.40 --dport 5432 -j ACCEPT
iptables -A FORWARD -p udp -m state --state NEW,ESTABLISHED,RELATED -o 172.18.1.40 --dport 5432 -j ACCEPT
iptables -A FORWARD -p tcp -m state --state NEW,ESTABLISHED,RELATED -o 127.0.0.1 --dport 50006 -j ACCEPT
iptables -A FORWARD -p tcp -m state --state NEW,ESTABLISHED,RELATED -o 172.18.1.40 --dport 50006 -j ACCEPT


Any advice is welcome.

mpapet 06-05-2008 12:46 PM

I discovered I had two problems and some faulty assumptions about how iptables could/would route traffic.

The port forwarding stanzas are not viable for 127.0.0.1. Apparently the kernel rejects these outright because they are non-routable addresses... or something like that.... If you have more precise language, please feel free to contribute.

It also appears that because this is happening on-host instead of from a remote host, iptables stanzas won't work.

The right application to use is rinetd. Available and easily configured in Debian's repositories.


All times are GMT -5. The time now is 07:33 PM.