Skip to content

Instantly share code, notes, and snippets.

@socram8888
Last active December 11, 2021 19:10
Show Gist options
  • Save socram8888/1aca91b19cb6251a68184056a7c2c482 to your computer and use it in GitHub Desktop.
Save socram8888/1aca91b19cb6251a68184056a7c2c482 to your computer and use it in GitHub Desktop.
DNS over Tor sysvinit script using stunnel
#!/bin/sh
### BEGIN INIT INFO
# Provides: dns-tor
# Required-Start: $remote_fs $network tor
# Required-Stop: $remote_fs $network tor
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: DNS over Tor
# Description: Domain Name Resolution over Tor
### END INIT INFO
NAME=dns-tor
DAEMON=/usr/bin/socat
PIDFILE=/run/$NAME.pid
DESC="DNS over Tor"
USER=nobody
LISTENADDR=127.84.111.114
LISTENPORT=53
SOCKSADDR=127.0.0.1
SOCKSPORT=9050
TORSERVICE=dns4torpnlfs2ifuz2s2yf3fc7rdmsbhm6rw75euj35pac6ap25zgqad.onion
TORPORT=253
test -x "$DAEMON" || exit 0
. /lib/lsb/init-functions
start() {
start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- \
UDP4-LISTEN:$LISTENPORT,bind=$LISTENADDR,reuseaddr,fork,su=$USER SOCKS4A:$SOCKSADDR:$TORSERVICE:$TORPORT,socksport=$SOCKSPORT
}
stop() {
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --remove-pidfile --exec $DAEMON
}
end_msg() {
local code=$1
log_end_msg $code
exit $code
}
case "$1" in
status)
status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME"
exit $?
;;
start)
log_daemon_msg "Starting $DESC" "$NAME"
start
end_msg $?
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
stop
end_msg $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
stop && start
end_msg $?
;;
*)
echo "Usage: $NAME {start|stop|restart|force-reload|status}" >&2
exit 3
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment