HowTo Safely Use DD-UP to update your DynDNS.Org IP Address
E-Mail Questions to Dean Weimer

General Overview
Expectations / Requirements
The Work

General Overview

What is DD-UP?
DD-UP is a program to update your Free DynDNS account.
What does "Safely Use" Mean?
"Safely Use" means that this script will not attempt to update your DynDNS account unless your IP Address has changed since it was last ran.
However, this script does not take into account the 30 day life of a dynamic host record without an update.

Expectations / Requirements

Expectations:
Please read the DynDNS.Org Acceptable Use Policy.
This HowTo, assumes that you are familiar with the workings of FreeBSD's PPP, and of Shell scripts, in order to make any minor changes that may be necessary to the example script files contained in this HowTo.
This script requires:
That you are connecting to the internet with PPP.
That you have a valid account with DynDNS.org.
That you have DD-UP 3.0.1 installed and configured.
That you have at least one Dynamic Host configured in your account.

The Work

First you need to decide where you want to put the files that we will be creating. I found that it was best for me to put them in the "/etc/ppp/" directory since the script needs to run after PPP has connected to your isp.

For starters, lets create a file that will be read by the script, to contain your Dynamic Host(s). I chose to call this file "hosts". If you only have one simply put that host name in the file.

MySubDomain.DynDNS.Org

On the other hand, if you have more than one host, separate the entries with ","s.

MySubDomain1.DynDNS.Org,MySubDomain2.HomeIP.Net

Now if you ever change your Dynamic host, or add a new one, you just simply need to edit this file accordingly.

Now we need to create the script that does all of the work, I choose to call this script "isp.up". First we are going to make a test script that will let us know if it is getting the correct IP Address, before we actually have it update our Dynamic host record.

#!/bin/sh
#
PATH=/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:/bin

# File Names
OLDIPFILE="/etc/ppp/ip.old"
IPFILE="/etc/ppp/ip"
HOSTSFILE="/etc/ppp/hosts"

# Save Old IP Address to check for change
mv $IPFILE $OLDIPFILE

# Update IP Address File with current IP Address
numips=`ifconfig tun0 | grep -c "inet "`
lastnum=$(($numips+2))
ifconfig tun0 | grep -n "inet " | grep "$lastnum:" | awk '{print $3}' > $IPFILE

# Run The Test
 # Retreive Host(s) names from "hosts" file
HOSTS=`cat $HOSTSFILE`

if [ -f $IPFILE ] # Checks to make sure a file was created with the 
                  # current ip Address in it
  then # If so retrieve the current IP from file 
    IP=`cat $IPFILE`
    echo $IP # Display Current IP Address to see if it is working so far
    if [ -f $OLDIPFILE ] # Now Check to see If there is a saved old IP 
                         # Address
      then # If so check to see if the New & Old IP Addresses are 
           # different
        echo `cat $OLDIPFILE` # Display Old IP From file
        if [ $(awk -F. '{print $1}' $IPFILE) -ne $(awk -F. '{print $1}' $OLDIPFILE) -o $(awk -F. '{print $2}' $IPFILE) -ne $(awk -F. '{print $2}' $OLDIPFILE) -o $(awk -F. '{print $3}' $IPFILE) -ne $(awk -F. '{print $3}' $OLDIPFILE) -o $(awk -F. '{print $4}' $IPFILE) -ne $(awk -F. '{print $4}' $OLDIPFILE) ]
          then # If so update your Dynamic Host Record(s)
            echo "ddup --host "$HOSTS" --ip "$IP # Show the command 
                                                 # that would run if 
                                                 # this wasn't a test.
        fi
     else # If no Old IP was saved, assume new IP address and update 
          # your Dynnamic Host Record(s)
       echo "ddup --host "$HOSTS" --ip "$IP # Show the command that 
                                            # would run of this wasn't 
                                            # a test.
    fi
 else # If no current ip address is stored, assume something went wrong 
      # and attempt to update using DynDNS.org's web script to retreive IP 
      # Address.
   echo "ddup --host "$HOSTS # Show the command that would run if this 
                             # wasn't a test.
fi

Now we need to set the permissions of the file to allow it to execute. To do this use "chmod 0700 isp.up".
You will want to try different scenarios with this, by disconnecting and reconnecting, to see if it does in fact work right. The echo command will show what it is doing, so you can verify if it does what you want.
When you are satisfied with your testing, replace the file with the finished file. So that it executes the commands instead of displaying them.

#!/bin/sh
#
PATH=/usr/bin:/usr/sbin:/usr/local/sbin:/sbin:/bin

# File Names
OLDIPFILE="/etc/ppp/ip.old"
IPFILE="/etc/ppp/ip"
HOSTSFILE="/etc/ppp/hosts"

# Save Old IP Address to check for change
mv $IPFILE $OLDIPFILE

# Update IP Address File with current IP Address
numips=`ifconfig tun0 | grep -c "inet "`
lastnum=$(($numips+2))
ifconfig tun0 | grep -n "inet " | grep "$lastnum:" | awk '{print $3}' > $IPFILE

# Run The Test
 # Retreive Host(s) names from "hosts" file
HOSTS=`cat $HOSTSFILE`

if [ -f $IPFILE ] # Checks to make sure a file was created with the 
                  # current ip Address in it
  then # If so retrieve the current IP from file 
    IP=`cat $IPFILE`
    if [ -f $OLDIPFILE ] # Now Check to see If there is a saved old IP 
                         # Address
      then # If so check to see if the New & Old IP Addresses are 
           # different
        if [ $(awk -F. '{print $1}' $IPFILE) -ne $(awk -F. '{print $1}' $OLDIPFILE) -o $(awk -F. '{print $2}' $IPFILE) -ne $(awk -F. '{print $2}' $OLDIPFILE) -o $(awk -F. '{print $3}' $IPFILE) -ne $(awk -F. '{print $3}' $OLDIPFILE) -o $(awk -F. '{print $4}' $IPFILE) -ne $(awk -F. '{print $4}' $OLDIPFILE) ]
          then # If so update your Dynamic Host Record(s)
            ddup --host $HOSTS --ip $IP
        fi
     else # If no Old IP was saved, assume new IP address and update 
          # your Dynnamic Host Record(s)
       ddup --host $HOSTS --ip $IP
    fi
 else # If no current ip address is stored, assume something went wrong 
      # and attempt to update using DynDNS.org's web script to retreive IP 
      # Address.
   ddup --host $HOSTS
fi

Alright Now we have a working script that updates our DynDNS Dynamic Host(s) if our ip address has changed. Now wouldn't it be great if this would run automatically.
Well heres how to accomplish that.

First, when do we want it to run? After our IP Address has changed, of course. Now how do we know when that has happened? The answer here is we don't, so we have to check when it is most probable. That means whenever a connection is made to our isp. Fortunately this functionality is built into the PPP that FreeBSD uses.

So we create a file called "ppp.linkup" this file uses the same format as the ppp.conf file.

default:
 set mode interactive
 !bg /etc/ppp/isp.up
 set mode ddial

Now in this example, I only have one connection that I use to connect to the internet, so I am using the "default:" section. If you have more than one profile, and don't want it to run under all of them, then put it in the section labeled the same as the profile section in your ppp.conf.
Also in this example I am using the "ddial" mode, which keeps the connection up all of the time, you can replace this with "auto" if that is the mode you prefer. However, if you are running PPP interactively remove the "set mode interactive" and the "set mode ddial" lines from this file.

To Explain what is happening here:
The line "!bg /etc/ppp/isp.up" executes the script that we just created, in the background.
The line "set mode interactive" is necessary, since PPP wont run scripts unless it is in interactive mode.
The "set mode ddial" line returns my PPP mode back to ddial after the script has finished executing.

Now you have a script that should correctly update your Dynamic Host Records, whenever you connect, but only if your IP Address has changed.