Skip to content

Instantly share code, notes, and snippets.

@alpsayin
Last active February 19, 2019 08:12
Show Gist options
  • Save alpsayin/97321866816bc097fca9b185920c0fed to your computer and use it in GitHub Desktop.
Save alpsayin/97321866816bc097fca9b185920c0fed to your computer and use it in GitHub Desktop.
#!/bin/sh
### Setup Instructions
#you need root, need I say it?
#disable DNSMASQ by commenting out the below line in /etc/NetworkManager/NetworkManager.conf
# dns=dnsmasq
#if it's different for any reason, establish the usual resolvconf link with
# ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
#so that ls -l /etc/resolv.conf is as below
# /etc/resolv.conf -> /run/resolvconf/resolv.conf
#probably a good idea to run `resolvconf -u` at this point
#for this script to work you need to have below 2 lines in your /etc/dhcp/dhclient.conf
# prepend domain-name-servers 127.0.2.1
# supersede domain-name-servers 127.0.2.1
### Usage instructions
#run this script as su if CaptivePortal is giving you trouble
#dnscrypt is disabled, get into captiveportal, log in, and try neverssl.com
#once you have internet, run this script as su again
#profit
#that said if you're on a public hotspot with captivePortal, it's probably a good idea to have a VPN
enabled=`grep '^prepend domain-name-servers' /etc/dhcp/dhclient.conf | grep 127.0.2.1`
enabled=`grep '^supersede domain-name-servers' /etc/dhcp/dhclient.conf | grep 127.0.2.1`
enabled_result="$?"
disabled=`grep '#prepend domain-name-servers' /etc/dhcp/dhclient.conf | grep 127.0.2.1`
disabled=`grep '#supersede domain-name-servers' /etc/dhcp/dhclient.conf | grep 127.0.2.1`
disabled_result="$?"
if [ $enabled_result -eq 0 ]
then
echo "was enabled"
sed -i 's/^prepend domain-name-servers/#&/' /etc/dhcp/dhclient.conf
sed -i 's/^supersede domain-name-servers/#&/' /etc/dhcp/dhclient.conf
echo "disabled now"
elif [ $disabled_result -eq 0 ]
then
echo "was disabled"
sed -i 's/#*prepend domain-name-servers/prepend domain-name-servers/' /etc/dhcp/dhclient.conf
sed -i 's/#*supersede domain-name-servers/supersede domain-name-servers/' /etc/dhcp/dhclient.conf
echo "enabled now"
else
echo "not included"
fi
#echo $enabled
#echo $disabled
#systemctl restart NetworkManager
dhclient wlan0
#nslookup alpsayin.com
#dig alpsayin.com
dnscrypt-proxy --resolve alpsayin.com
@alpsayin
Copy link
Author

alpsayin commented Dec 19, 2018

Annoyed by CaptivePortalLogin giving you a hard time when you're set for Dnscyrpt-Proxy ?

Quick toggle script to default things to the original dns server to get through the captive-portal and re-enable

This script is useful if you're using dnscrypt proxy and CaptivePortalLogins are giving you a hard time. Bit shit though because this makes you disconnect and reconnect again. There should be a better way of updating DNS servers. Potentially through resolv.conf but I also dont wanna touch that. Seems dhclient wlan0 does just that.
-Assumes that dnsmasq is disabled in /etc/NetworkManager/NetworkManager.conf as #dns=dnsmasq
-Assumes dnscrypt-proxy2 configured with no listen-addresses and so running on 127.0.2.1
-Assumes resolv.conf is updated automatically by dhclient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment