* iptables DNAT algorithm -- another way?
@ 2014-12-12 23:55 John Miller
2014-12-13 0:50 ` Neal Murphy
0 siblings, 1 reply; 8+ messages in thread
From: John Miller @ 2014-12-12 23:55 UTC (permalink / raw)
To: netfilter
Hi folks,
We're running a server that scan local systems for installed SSL
certificates. Problem is, the tool truly means local -- RFC1918 private
ranges only, please. Being a university, we have quite a few things
located in public IP space that aren't necessarily world-accessible
(development servers and the like).
My solution thus far has been to use DNAT to trick our scanning program
into thinking it's using local addresses.
iptables -t nat -A OUTPUT -d 172.16.x.y -j DNAT \
--to-destination 129.64.x.y
Trouble is that I want a direct correspondence: the third and fourth
octets need to be the same for source and destination. I can certainly
set ranges for initial and final destination address, but the NAT
algorithm picks the destination at random. Is there a way to accomplish
this in iptables? With another netfilter tool? I'd like to avoid running
#!/bin/sh
for third_octet in {0..255}; do
for fourth_octet in {0..255}; do
iptables -t nat -A OUTPUT \
-d 172.16.${third_octet}.${fourth_octet} -j DNAT \
--to-destination 129.64.${third_octet}.${fourth_octet}
done
done
and ending up with 2^16 separate iptables rules.
John
--
John Miller
Systems Engineer
Brandeis University
johnmill@brandeis.edu
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: iptables DNAT algorithm -- another way?
2014-12-12 23:55 iptables DNAT algorithm -- another way? John Miller
@ 2014-12-13 0:50 ` Neal Murphy
2014-12-13 1:06 ` John Miller
2014-12-13 9:21 ` Pascal Hambourg
0 siblings, 2 replies; 8+ messages in thread
From: Neal Murphy @ 2014-12-13 0:50 UTC (permalink / raw)
To: netfilter
On Friday, December 12, 2014 06:55:21 PM John Miller wrote:
> Hi folks,
>
> We're running a server that scan local systems for installed SSL
> certificates. Problem is, the tool truly means local -- RFC1918 private
> ranges only, please. Being a university, we have quite a few things
> located in public IP space that aren't necessarily world-accessible
> (development servers and the like).
>
> My solution thus far has been to use DNAT to trick our scanning program
> into thinking it's using local addresses.
>
> iptables -t nat -A OUTPUT -d 172.16.x.y -j DNAT \
> --to-destination 129.64.x.y
This might point you in the right direction:
iptables -t nat -A PREROUTING -s 172.16.0.0/16 \
-j DNAT --to-destination 129.64.0.0-129.64.255.255
But I don't know if it provides predictable 1:1 mapping.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iptables DNAT algorithm -- another way?
2014-12-13 0:50 ` Neal Murphy
@ 2014-12-13 1:06 ` John Miller
2014-12-13 1:26 ` Neal Murphy
2014-12-13 9:21 ` Pascal Hambourg
1 sibling, 1 reply; 8+ messages in thread
From: John Miller @ 2014-12-13 1:06 UTC (permalink / raw)
To: neal.p.murphy; +Cc: netfilter
On Fri, Dec 12, 2014 at 7:50 PM, Neal Murphy <neal.p.murphy@alum.wpi.edu> wrote:
> On Friday, December 12, 2014 06:55:21 PM John Miller wrote:
>> Hi folks,
>>
>> We're running a server that scan local systems for installed SSL
>> certificates. Problem is, the tool truly means local -- RFC1918 private
>> ranges only, please. Being a university, we have quite a few things
>> located in public IP space that aren't necessarily world-accessible
>> (development servers and the like).
>>
>> My solution thus far has been to use DNAT to trick our scanning program
>> into thinking it's using local addresses.
>>
>> iptables -t nat -A OUTPUT -d 172.16.x.y -j DNAT \
>> --to-destination 129.64.x.y
>
> This might point you in the right direction:
>
> iptables -t nat -A PREROUTING -s 172.16.0.0/16 \
> -j DNAT --to-destination 129.64.0.0-129.64.255.255
Thanks for your response, Neal. These are for TCP streams that I'm
initiating, so I'm pretty sure the OUTPUT chain is what I want here.
As for the range in --to-destination, it's as you say: mappings aren't
predictable. Was hoping someone on the list knew the innards of the
DNAT target and whether there were other options besides
--to-destination. Alternatively, was wondering if the mangle table
might be able to do what I'm looking for. Definitely open to
suggestions!
John
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iptables DNAT algorithm -- another way?
2014-12-13 1:06 ` John Miller
@ 2014-12-13 1:26 ` Neal Murphy
0 siblings, 0 replies; 8+ messages in thread
From: Neal Murphy @ 2014-12-13 1:26 UTC (permalink / raw)
To: netfilter
On Friday, December 12, 2014 08:06:42 PM John Miller wrote:
> On Fri, Dec 12, 2014 at 7:50 PM, Neal Murphy <neal.p.murphy@alum.wpi.edu>
wrote:
> > On Friday, December 12, 2014 06:55:21 PM John Miller wrote:
> >> Hi folks,
> >>
> >> We're running a server that scan local systems for installed SSL
> >> certificates. Problem is, the tool truly means local -- RFC1918 private
> >> ranges only, please. Being a university, we have quite a few things
> >> located in public IP space that aren't necessarily world-accessible
> >> (development servers and the like).
> >>
> >> My solution thus far has been to use DNAT to trick our scanning program
> >> into thinking it's using local addresses.
> >>
> >> iptables -t nat -A OUTPUT -d 172.16.x.y -j DNAT \
> >>
> >> --to-destination 129.64.x.y
> >
> > This might point you in the right direction:
> >
> > iptables -t nat -A PREROUTING -s 172.16.0.0/16 \
> >
> > -j DNAT --to-destination 129.64.0.0-129.64.255.255
>
> Thanks for your response, Neal. These are for TCP streams that I'm
> initiating, so I'm pretty sure the OUTPUT chain is what I want here.
> As for the range in --to-destination, it's as you say: mappings aren't
> predictable. Was hoping someone on the list knew the innards of the
> DNAT target and whether there were other options besides
> --to-destination. Alternatively, was wondering if the mangle table
> might be able to do what I'm looking for. Definitely open to
> suggestions!
>
> John
Traditionally, DNAT must be done in the nat table in PREROUTING (change the
destination address before any routing decisions are made). Likewise, SNAT
must be done in the nat table in POSTROUTING (change the source address after
all routing decisions are made).
Things might've changed with recent versions of netfilter and iptables.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iptables DNAT algorithm -- another way?
2014-12-13 0:50 ` Neal Murphy
2014-12-13 1:06 ` John Miller
@ 2014-12-13 9:21 ` Pascal Hambourg
2014-12-13 19:52 ` John Miller
1 sibling, 1 reply; 8+ messages in thread
From: Pascal Hambourg @ 2014-12-13 9:21 UTC (permalink / raw)
To: neal.p.murphy; +Cc: netfilter
Hello,
Neal Murphy a écrit :
> On Friday, December 12, 2014 06:55:21 PM John Miller wrote:
>>
>> My solution thus far has been to use DNAT to trick our scanning program
>> into thinking it's using local addresses.
>>
>> iptables -t nat -A OUTPUT -d 172.16.x.y -j DNAT \
>> --to-destination 129.64.x.y
>
> This might point you in the right direction:
>
> iptables -t nat -A PREROUTING -s 172.16.0.0/16 \
> -j DNAT --to-destination 129.64.0.0-129.64.255.255
>
> But I don't know if it provides predictable 1:1 mapping.
It doesn't. You want to use NETMAP instead of DNAT.
> Traditionally, DNAT must be done in the nat table in PREROUTING (change the
> destination address before any routing decisions are made).
That's for incoming packets. For locally-generated outgoing packets, you
want to use the OUTPUT chain.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: iptables DNAT algorithm -- another way?
2014-12-13 9:21 ` Pascal Hambourg
@ 2014-12-13 19:52 ` John Miller
2014-12-13 21:30 ` Pascal Hambourg
0 siblings, 1 reply; 8+ messages in thread
From: John Miller @ 2014-12-13 19:52 UTC (permalink / raw)
Cc: netfilter
On Sat, Dec 13, 2014 at 4:21 AM, Pascal Hambourg <pascal@plouf.fr.eu.org> wrote:
> Hello,
>
> Neal Murphy a écrit :
>> On Friday, December 12, 2014 06:55:21 PM John Miller wrote:
>>>
>>> My solution thus far has been to use DNAT to trick our scanning program
>>> into thinking it's using local addresses.
>>>
>>> iptables -t nat -A OUTPUT -d 172.16.x.y -j DNAT \
>>> --to-destination 129.64.x.y
>>
>> This might point you in the right direction:
>>
>> iptables -t nat -A PREROUTING -s 172.16.0.0/16 \
>> -j DNAT --to-destination 129.64.0.0-129.64.255.255
>>
>> But I don't know if it provides predictable 1:1 mapping.
>
> It doesn't. You want to use NETMAP instead of DNAT.
Beautiful! That's exactly what I was looking for. Thank you!
Sounds like
iptables -t mangle -A OUTPUT -d 172.16.0.0/16 -j NETMAP --to 129.64.0.0/16
will do the trick.
John
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-12-14 3:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-12 23:55 iptables DNAT algorithm -- another way? John Miller
2014-12-13 0:50 ` Neal Murphy
2014-12-13 1:06 ` John Miller
2014-12-13 1:26 ` Neal Murphy
2014-12-13 9:21 ` Pascal Hambourg
2014-12-13 19:52 ` John Miller
2014-12-13 21:30 ` Pascal Hambourg
2014-12-14 3:30 ` John Miller
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.