Linux Netfilter discussions
 help / color / mirror / Atom feed
* DNAT on loopback
@ 2013-08-28 14:10 Serge Kosyrev
  2013-08-31 10:33 ` Pascal Hambourg
  0 siblings, 1 reply; 2+ messages in thread
From: Serge Kosyrev @ 2013-08-28 14:10 UTC (permalink / raw)
  To: netfilter

Good day folks!

Is it possible to DNAT locally-originated, locally-destined packets to a
non-local destination?

The use-case is port forwarding to a locally-routed VM guest.
For externally originating access the following is adequate:

iptables -t nat -A PREROUTING -d external.iface.ip -p tcp --dport 80 -j DNAT --to-destination target.ip.add.ress

A logical complement for locally originating accesses would have been:

iptables -t nat -A OUTPUT     -d 127.0.0.0/16      -p tcp --dport 80 -j DNAT --to-destination target.ip.add.ress

..but all I can observe is silent packet disappearance, which I presume
takes place during routing decision-making immediately following the
processing by the OUTPUT chain of the nat table.

So, is it possible at all, or should I go the userspace port forwarding way?


regards,
Samium Gromoff

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: DNAT on loopback
  2013-08-28 14:10 DNAT on loopback Serge Kosyrev
@ 2013-08-31 10:33 ` Pascal Hambourg
  0 siblings, 0 replies; 2+ messages in thread
From: Pascal Hambourg @ 2013-08-31 10:33 UTC (permalink / raw)
  To: Serge Kosyrev; +Cc: netfilter

Hello,

Serge Kosyrev a écrit :
> 
> Is it possible to DNAT locally-originated, locally-destined packets to a
> non-local destination?

Sometimes, but not alway.

> The use-case is port forwarding to a locally-routed VM guest.
> For externally originating access the following is adequate:
> 
> iptables -t nat -A PREROUTING -d external.iface.ip -p tcp --dport 80 -j DNAT --to-destination target.ip.add.ress
> 
> A logical complement for locally originating accesses would have been:
> 
> iptables -t nat -A OUTPUT     -d 127.0.0.0/16      -p tcp --dport 80 -j DNAT --to-destination target.ip.add.ress
> 
> ..but all I can observe is silent packet disappearance, which I presume
> takes place during routing decision-making immediately following the
> processing by the OUTPUT chain of the nat table.

Yes, packets are discarded because the output interface is non-loopback
and the source address is within 127.0.0.0/8, which is restrited to
loopback. Unfortunately you can only change the source address in
POSTROUTING, which comes too late.

> So, is it possible at all, or should I go the userspace port forwarding way?

It is possible if the original source adress is not within 127.0.0.0/8.

For local destinations the default source adresse is the same as the
destination, but some applications allow to specify a different address.

However why don't you use the same destination address external.iface.ip
as in the PREROUTING rule, so that the default source adress would not
be a loopback address ?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-31 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-28 14:10 DNAT on loopback Serge Kosyrev
2013-08-31 10:33 ` Pascal Hambourg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox