Linux Netfilter discussions
 help / color / mirror / Atom feed
From: John Miller <johnmill@brandeis.edu>
To: netfilter@vger.kernel.org
Subject: iptables DNAT algorithm -- another way?
Date: Fri, 12 Dec 2014 18:55:21 -0500	[thread overview]
Message-ID: <548B8069.4020802@brandeis.edu> (raw)

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


             reply	other threads:[~2014-12-12 23:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-12 23:55 John Miller [this message]
2014-12-13  0:50 ` iptables DNAT algorithm -- another way? 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

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=548B8069.4020802@brandeis.edu \
    --to=johnmill@brandeis.edu \
    --cc=netfilter@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox