Skip to content

Instantly share code, notes, and snippets.

@gibas
Created June 24, 2013 15:00
Show Gist options
  • Save gibas/5850685 to your computer and use it in GitHub Desktop.
Save gibas/5850685 to your computer and use it in GitHub Desktop.
Script for PF firewall (which is used in *BSD systems), to automaticly add to table DYNAMIC current IP of domains domains. In crontab you should have a line similar to: */5 * * * * /scripts/dyndns.sh
#!/bin/sh
TABLE="DYNAMIC";
HOSTS="your-dynamic-domain.dyndns.org your-second-domain.dyndns.org";
for HOST in $HOSTS; do
IP=`/usr/bin/host $HOST | cut -d " " -f 4`
IPOLD=`/sbin/pfctl -t $TABLE -T show | grep -v "ALTQ" | tr -d " "`
if [ "$IP" != "$IPOLD" ]; then
/sbin/pfctl -t $TABLE -T delete $IPOLD
echo "/sbin/pfctl -t $TABLE -T delete $IPOLD"
/sbin/pfctl -t $TABLE -T add $IP
echo "/sbin/pfctl -t $TABLE -T add $IP"
fi
done
/sbin/pfctl -t DYNAMIC -T expire 43200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment