Created
June 24, 2013 15:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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