Skip to content

Instantly share code, notes, and snippets.

@jsvennevid
Last active August 29, 2015 14:21
Show Gist options
  • Save jsvennevid/3f1de9f0e6e4f1ff50ef to your computer and use it in GitHub Desktop.
Save jsvennevid/3f1de9f0e6e4f1ff50ef to your computer and use it in GitHub Desktop.
Small script that I use to remap DNS queries on certain portions of my internal network on my ASUSWRT-based router
#!/bin/sh
APPS_MOUNTED_PATH=`nvram get apps_mounted_path`
APPS_INSTALL_FOLDER=`nvram get apps_install_folder`
APPS_INSTALL_PATH=$APPS_MOUNTED_PATH/$APPS_INSTALL_FOLDER
CONFIG="$APPS_INSTALL_PATH/etc/reroutedns.conf"
. "$CONFIG"
COMMAND="PREROUTING -t nat -m iprange --src-range $IP_RANGE -p udp --dport 53 -j DNAT --to-destination $TARGET_IP"
echo $COMMAND
interrupt()
{
exit 0
}
cleanup()
{
echo "cleanup"
iptables -D $COMMAND
}
trap interrupt SIGINT SIGTERM
trap cleanup EXIT
while true ; do
iptables -C $COMMAND 2> /dev/null
if [ $? -eq 1 ]; then
iptables -A $COMMAND
fi
sleep 30 &
wait
done
IP_RANGE="192.168.1.<first>-192.168.1.<last>"
TARGET_IP="<target dns server>"
Package: reroutedns
Architecture: arm
Priority: optional
Section: net
Version: 1.0
OptionalUtility: 1.0.0.1+
Maintainer: ASUS
Suggests:
Conflicts:
Enabled: yes
APPS_MOUNTED_PATH=`nvram get apps_mounted_path`
APPS_INSTALL_FOLDER=`nvram get apps_install_folder`
APPS_INSTALL_PATH=$APPS_MOUNTED_PATH/$APPS_INSTALL_FOLDER
case "$1" in
start|force-reload|restart)
killall -SIGTERM reroutedns
cd /opt/bin
./reroutedns &
;;
stop)
killall -SIGTERM reroutedns
;;
*)
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment