* 2 ips, same port, forward to original ip but different port
@ 2008-11-05 1:38 Fu-Tung Cheng
2008-11-05 9:42 ` Pascal Hambourg
0 siblings, 1 reply; 3+ messages in thread
From: Fu-Tung Cheng @ 2008-11-05 1:38 UTC (permalink / raw)
To: netfilter
Hi,
Here is my current rule set. I've tried other combinations of settings but with no more luck than the current rule set.
$IPTABLES -A FORWARD -p tcp --destination-port 80 -j ACCEPT
$IPTABLES -t nat -A PREROUTING -j REDIRECT -p tcp --destination-port
80 --to-ports 12080
Now what I need to happen is that requests coming into ip1:80 goto
ip1:12080 and ip2:80 goto ip2:12080. What seems to be happening is
that all requests coming into 80 are going to ip1:12080.
Any pointers gladly accepted.
Thank you,
Fu-Tung
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: 2 ips, same port, forward to original ip but different port
2008-11-05 1:38 2 ips, same port, forward to original ip but different port Fu-Tung Cheng
@ 2008-11-05 9:42 ` Pascal Hambourg
2008-11-05 18:32 ` Fu-Tung Cheng
0 siblings, 1 reply; 3+ messages in thread
From: Pascal Hambourg @ 2008-11-05 9:42 UTC (permalink / raw)
To: netfilter
Fu-Tung Cheng a écrit :
>
> $IPTABLES -A FORWARD -p tcp --destination-port 80 -j ACCEPT
> $IPTABLES -t nat -A PREROUTING -j REDIRECT -p tcp --destination-port
> 80 --to-ports 12080
>
> Now what I need to happen is that requests coming into ip1:80 goto
> ip1:12080 and ip2:80 goto ip2:12080. What seems to be happening is
> that all requests coming into 80 are going to ip1:12080.
If I understand correctly, you want to change only the destination port,
not the destination address. But the iptables manpage says that the
REDIRECT target replaces the destination address with the primary
address of the incoming interface, so it may not be suitable for your
purpose.
You can use the DNAT target instead. Either :
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to :12080
will translate the destination port 80 into 12080 regardless of the
destination address and without changing it,
or :
iptables -t nat -A PREROUTING -d $ip1 -p tcp --dport 80 \
-j DNAT --to $ip1:12080
iptables -t nat -A PREROUTING -d $ip2 -p tcp --dport 80 \
-j DNAT --to $ip2:12080
will translate only ip1:80 into ip1:12080 and ip2:80 into ip2:12080.
PS: What is the purpose of the first rule in the FORWARD chain ?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: 2 ips, same port, forward to original ip but different port
2008-11-05 9:42 ` Pascal Hambourg
@ 2008-11-05 18:32 ` Fu-Tung Cheng
0 siblings, 0 replies; 3+ messages in thread
From: Fu-Tung Cheng @ 2008-11-05 18:32 UTC (permalink / raw)
To: netfilter; +Cc: Pascal Hambourg
Thank you!!
You understood correctly. I wanted any incoming on 80 to be forwarded on the same interface to 12080.
> If I understand correctly, you want to change only the
> destination port, not the destination address. But the
> iptables manpage says that the REDIRECT target replaces the
> destination address with the primary address of the incoming
> interface, so it may not be suitable for your purpose.
>
> You can use the DNAT target instead. Either :
>
> iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT
> --to :12080
>
> will translate the destination port 80 into 12080
> regardless of the destination address and without changing
> it,
>
Not sure what I thought that was supposed to do. I just copied a couple rules for forwarding from some tutorial and those were included and didn't think to really question them. I need to spend some more time with the man pages. I think my big problem was that I thought iptables -F would flush all chains but instead it was likely only flushing the default chain and not the nat chain.
> PS: What is the purpose of the first rule in the FORWARD
> chain ?
Thanks again,
Fu-Tung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-11-05 18:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-05 1:38 2 ips, same port, forward to original ip but different port Fu-Tung Cheng
2008-11-05 9:42 ` Pascal Hambourg
2008-11-05 18:32 ` Fu-Tung Cheng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox