On my Redhat 9 system, if I do this (lines wrapped to fit):
iptables -t nat -A PREROUTING -p tcp --sport 0:65535 --dport 81 -j
REDIRECT --to-port 80
iptables -t nat -A OUTPUT -p tcp --sport 0:65535 --dport 81 -j
REDIRECT --to-port 80
and then do this:
telnet 1.2.3.4 81
I end up connected to the web server on localhost, just like I'd expect.
However, on SuSE 9.1 and SuSE 9.2, it accepts the iptables commands just
fine, and things look fine when I list things with "iptables -t nat -vL".
However, "telnet 1.2.3.4 81" tries to actually connect to 1.2.3.4, port
81. The iptables stuff has no effect whatsoever, as far as I can see.
If, however, from a second machine, I try to connect to port 81 on the
first machine, then it does end up at the first machine's web server.
So, it looks like the rules are only applying to packets from outside,
not from packet originating on the first machine.
(All other chains in all other tables are empty, and all the other
tables have default policy of accept).
SuSE does have a later version of iptables.
Which is the correct behavior? The one that is on the older Redhat
system, or the one on the SuSE system?
If SuSE is correct, then what is the correct way to accomplish this now?
All I could find with a bit of Googling was (1) a bunch of sites with
examples essentially the same as mine, and (2) a complaint from someone
on SuSE 9.1 who is seeing the same thing I'm seeing.
--
--Tim Smith
|