Subject: Re: IP NAT & Dynamic IP addressing
To: Port Mac 68K <port-mac68k@NetBSD.ORG>
From: Mason Loring Bliss <mason@acheron.middleboro.ma.us>
List: port-mac68k
Date: 11/01/1997 22:59:27
On 11/1/97 at 1:58 PM -0800, you wrote:

> I _think_ you should be able to do it w/ a dynamic address, but it
> will need some fiddling. I have half of the solution in mind, but you'll
> need to play with it some (I've not set up NAT yet).

Tom T. Thai is working on a FAQ for this, I think, but in any event, IP-NAT with dynamic IP is pretty easy. Here's a script someone sent me... The only thing likely to need changing is the "inside" address:


address=`ifconfig ppp0 | tail -n 1 | awk '{print $2}'`
echo Current IP address is $address
echo Cleaning out IPNAT
ipnat -F
ipnat -C
ipf -E
echo Setting up IPNAT for IP address $address
echo "map ppp0 10.0.2.15/24 -> $address/32 portmap tcp/udp 10000:65000" | ipnat -f -
echo "map ppp0 10.0.2.15/24 -> $address/32" | ipnat -f -


I run this from within my ppp-up script to set up NAT after I'm assigned a PPP address.

Here's the complementary nat-down script:


#!/bin/sh
ipf -D
ipnat -C


Here's my ppp-up script, for kicks:


#!/bin/sh
# ppp-up - start pppd
#
PPPDIR=/etc/ppp
NUMBERLIST=$PPPDIR/ppp-numbers
LOGIN=$PPPDIR/ppp-login
CHATSCRIPT=$PPPDIR/ppp-chat
CONNECT=$PPPDIR/ppp-connect
#
#
if [ -f /var/run/ppp0.pid ]; then
  echo -n pppd is already running...
else
  echo -n Connecting...
  pppd /dev/tty01 38400 local crtscts connect "$CONNECT $NUMBERLIST $LOGIN $CHAT
SCRIPT"
  echo " Done."
  echo -n "Waiting for IP address"
  while [ `ifconfig ppp0 | tail -1 | cut -c 7-14` = "0.0.0.0" ]
  do
    sleep 8
    echo -n "."
  done
  echo "got one."
  echo "Setting up IP-NAT."
  /etc/ppp/nat
fi


...and ppp-down, for completeness:


#!/bin/sh
#
if [ -f /var/run/ppp0.pid ]; then
  echo -n killing pppd...
  kill `cat /var/run/ppp0.pid`
  echo done
  echo "Bringing down IP-NAT..."
  /etc/ppp/nat-down
else
  echo ppp already is down 1>&2
fi

-- 
Mason Loring Bliss...mason@acheron.middleboro.ma.us...www.webtrek.com/mason
"In the drowsy dark cave of the mind dreams build their nest with fragments
 dropped from day's caravan."--Rabindranath Tagore...awake ? sleep : dream;