Use CloudFlare As a Free Dynamic DNS for Your BBS

Whether you plan on hosting your own site on your home ISP or running a BBS at home on a retro computer, you’ll run into the issue of having a domain name lead to your home’s IP address. There are a few paid services and just one or two free services that come with weekly renewals or the name is dropped. But there is another and free way to have your own domain name point to the correct IP address, CloudFlare.

How To: Setup a Dynamic DNS for BBS Using CloudFlare and a Raspberry Pi (or some other device running linux)

If you’re running your BBS from your personal ISP, you’ll probably run into an issue with your IP address changing, causing issue with pointing the domain to the BBS. There are a few paid services and a few free. If you use Name Cheap for your domain name registrar, you can setup and use a free dynamic DNS service. With the inclusion of the domain, you can setup a client that pings back to NameCheap to keep the IP address current.

However, with that said I’ll show you another way to setup and use a dynamic DNS for free, provided by CloudFlare. First you’ll need a CloudFlare account and second you’ll need to have CloudFlare become your name server. You can look online to find out how to do this but it’s a pretty easy setup process and within about 10 minutes your domain will be pointing to their name servers for lookup.

Visit your account on CloudFlare and under the Overview page, you’ll find your Account ID and Zone ID for the domain. Using these two IDs, enter them into the script below and run it on a raspberry pi or any linux machine. We’re running this script to obtain the A Record ID for the BBS domain.

#/usr/bin/env sh
#Script to fetch your CF "dynamic" A-record ID
#You need the Zone ID, Authorization key and A-record ID for your domain.
curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE ID HERE /dns_records?type=A"
-H "Host: api.cloudflare.com"     
-H "User-Agent: ddclient/3.9.0"     
-H "Connection: close"     
-H "X-Auth-Email: Your username/email address"     
-H "X-Auth-Key: ACCOUNT ID HERE"

Depending upon how many records you have for your domain, you’ll see a bunch of listings when you execute the script. You’ll want the record ID for the domain or sub-domain (like bbs.yourdomain.com) you created that you want to point to the server. With this information we’ll enter it into our finial script which should run on a cronjob to make sure the domain is updated with the most current IP address.

#/usr/bin/env sh
AUTH_EMAIL=CLOUDFLARE USERNAME
AUTH_KEY=ACCCOUNT ID
ZONE_ID=ZONE ID
A_RECORD_NAME="DOMAIN NAME FOR BBS"
A_RECORD_ID=RECORD ID

# Retrieve the last recorded public IP address
IP_RECORD="/tmp/ip-record"
RECORDED_IP=`cat $IP_RECORD`

# Fetch the current public IP address
PUBLIC_IP=$(curl --silent https:\/\/api.ipify.org) || exit 1

#If the public ip has not changed, nothing needs to be done, exit.
if [ "$PUBLIC_IP" = "$RECORDED_IP" ]; then
    exit 0
fi

# Otherwise, your Internet provider changed your public IP again.
# Record the new public IP address locally
echo $PUBLIC_IP > $IP_RECORD

# Record the new public IP address on Cloudflare using API v4
RECORD=$(cat <<EOF
{ "type": "A",
  "name": "$A_RECORD_NAME",
  "content": "$PUBLIC_IP",
  "ttl": 180,
  "proxied": false }
EOF
)
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$A_RECORD_ID" \
     -X PUT \
     -H "Content-Type: application/json" \
     -H "X-Auth-Email: $AUTH_EMAIL" \
     -H "X-Auth-Key: $AUTH_KEY" \
     -d "$RECORD"

Run and save this script, call it something like yourdomain.sh and then set a cronjob to run the script every hour. This will use the CloudFlare API and update the A record for the domain name every hour and insert your IP. You now have a free Dynamic domain service.[p]Get the shell scripts, find_record.sh and update_domain.sh


Posted

in

by

Tags: