Last active
August 29, 2015 14:21
-
-
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
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 | |
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 |
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
IP_RANGE="192.168.1.<first>-192.168.1.<last>" | |
TARGET_IP="<target dns server>" |
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
Package: reroutedns | |
Architecture: arm | |
Priority: optional | |
Section: net | |
Version: 1.0 | |
OptionalUtility: 1.0.0.1+ | |
Maintainer: ASUS | |
Suggests: | |
Conflicts: | |
Enabled: yes |
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
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