All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert White <rwhite@pobox.com>
To: zrm <zrm@trustiosity.com>, oyvind@dynator.no, netfilter@vger.kernel.org
Subject: Re: Full NAT forward and source routing - possible without packet marking?
Date: Sat, 1 Jul 2017 23:50:21 +0000	[thread overview]
Message-ID: <6773e78c-f0e6-508d-0a72-d5880705756d@pobox.com> (raw)
In-Reply-To: <ea023673-d0c6-f8d8-0399-203a71e7fa62@trustiosity.com>

On 07/01/2017 10:17 PM, zrm wrote:
> On 07/01/2017 04:26 PM, Robert White wrote:
>> So, for instance, once you DNAT the incoming packet you _don't_ want to
>> SNAT it.
> 
> What about hairpin NAT?

As stated, you really want to do local services by adjusting the DNS
unless it's impossible.

Sure, you can do hairpin NAT, but it's usually just a bad design since
it doubles the network traffic on the one interface.

So I understand that there are some odd corner cases that you just
cannot fix, such as lying to a black-box appliance, but it's a technique
that you _can_ do, but that you have virtually no _good_ reason to ever do.


IF you must you want to restrict the hell out of the SNAT so that it
only applies to packets that are making that hairpin turn, rather than
masquerading/snat all the traffic.

So really, if you are in control of the router and the DNS, or you
intercept the DNS requests with a REDIRECT rule at the router, you can
inject the correct local address anyway and you don't need to hairpin.

If you want to put the service at a common public IP address and leave
it that way, putting your server on a dogleg/spur is already a much
better idea anyway.

Why?

Because if you have a public service (say a web browser) you don't
_want_ it on your local segment. One of the goals (that people often
forget) of a firewall is to protect yourself, so if the server is in the
free local segment then a compromise of the server is effectively a
compromise of the router.

If the server(s) are on a dogleg then compromising the server can only
give the attacker access to the other servers on the dogleg (if you did
your rules right). A server that the public can touch by any means
should be isolated from the rest of your private network.

For instance, a public-facing web server should never be allowed to make
outgoing connections to the rest of your infrastructure. The dogleg
rules should, for example, block every form of egress from that server
to your real properties or the internet in general.

By example, the typical web server exploit causes the web server to make
an ssh or telnet connection, or an outbound web request so that the
escalated privilege can be used for some purpose. It might also involve
putting a web snoop of some sort into the server to watch the incidental
traffic for passwords and such.

So an actually secure setup would, for example, prevent the web server
box from initiating questionable traffic, and would isolate your local
SMB type traffic from the wire entirely.

So if you have to haripin for some reason, then you should dogleg
instead. Period. It's a half-arsed solution to an inherently bad design.

A commodity home router doesn't usually offer the necessary hardware to
dogleg, but commodity home routers are not designed for Real Services
Safety™. Anything you can put a network card in can be built to never
need to hairpin anything.

So hairpin routing is a bad idea that is popular for bad reasons.

The rendezvous server example is fixed by a dogleg, but it's also fixed
by having both addresses listed for the server and just NAKing (via
REJECT) the public address if its received on the private interface,
causing the secondary address to be used. Of course, because of your
smart routing the local address should have been chosen for its lower
metric to start with, but that's another topic.

HOWEVER

If you do hairpin, you still don't need to mark any packets or anything.
You just use the SNAT/MASQUERADE rule with highly restricted matches
just for the hairpin server.

An example culled from the internet:

-A PREROUTING -d 89.179.245.232/32 -p tcp -m multiport --dports
22,25,80,443 -j DNAT --to-destination 192.168.2.10
-A POSTROUTING -s 192.168.2.0/24 -o ppp0 -j MASQUERADE
-A POSTROUTING -s 192.168.2.0/24 -d 192.168.2.10/32 -p tcp -m multiport
--dports 22,25,80,443 -j MASQUERADE

Notice how the last rule range matches the source, but exactly matches
the hairpin target both by exact address and specific ports. Normal
non-hairpin traffic simply doesn't get SNAT at all.

And still, and again, the connection tracking does all the necessary
heavy lifting work with no particularly complex nonsense.

It's ugly and insecure, IMHO of course, to leave that server on your
general use network like that for the reasons already stated. Spending
forty bucks on an extra network card would be _much_ safer and more
efficient.

  reply	other threads:[~2017-07-01 23:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-30 13:55 Full NAT forward and source routing - possible without packet marking? Øyvind Kaurstad
2017-07-01 10:05 ` Pascal Hambourg
2017-07-01 20:26 ` Robert White
2017-07-01 22:17   ` zrm
2017-07-01 23:50     ` Robert White [this message]
2017-07-03 18:07       ` Hairpin NAT " zrm
2017-07-04  1:14         ` Robert White
2017-07-04  5:48           ` K
2017-07-04  7:07             ` Neal P. Murphy
2017-07-04 10:21               ` Robert White
2017-07-04 20:53           ` Pascal Hambourg
2017-07-04 21:20             ` Neal P. Murphy
2017-07-05  5:28             ` Robert White
2017-07-08 19:54           ` zrm
2017-07-08 21:55             ` Robert White
2017-07-02  7:29   ` Full NAT forward and source routing " Pascal Hambourg
2017-07-02 10:33     ` Robert White
2017-07-02 11:19       ` Pascal Hambourg
2017-07-02 15:58         ` Øyvind Kaurstad
2017-07-02 17:10           ` Pascal Hambourg
2017-07-02 23:20             ` Øyvind Kaurstad
2017-07-02 21:10           ` Robert White
2017-07-02 23:09             ` Øyvind Kaurstad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6773e78c-f0e6-508d-0a72-d5880705756d@pobox.com \
    --to=rwhite@pobox.com \
    --cc=netfilter@vger.kernel.org \
    --cc=oyvind@dynator.no \
    --cc=zrm@trustiosity.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.