Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active April 7, 2019 07:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frgomes/544014b53e5384e00847da20b3e1da5b to your computer and use it in GitHub Desktop.
Save frgomes/544014b53e5384e00847da20b3e1da5b to your computer and use it in GitHub Desktop.
Debian - auto configure proxy when Network Manager connects an interface
#!/bin/bash
## see: http://github.com/frgomes/debian-bin/blob/master/bash_80proxy.sh
SCRIPT=/home/rgomes/bin/bash_80proxy.sh
## INTF is the network interface, either a wired one, wireless or any other type
INTF=enp8s0
## DEFAULT_PROXY contains the HTTP_PROXY to be defined when INTF is connected
DEFAULT_PROXY=http://127.0.0.1:3128/
if [ "$1" == $INTF ] ;then
source $SCRIPT
case "$2" in
up)
if [[ $( netstat -an | fgrep :3128 ) ]] ;then
unbound_local_zones_ifnet $INTF && sudo service unbound restart
proxy_on $DEFAULT_PROXY
else
unbound_local_zones && sudo service unbound restart
proxy_off
fi
;;
down)
unbound_local_zones && sudo service unbound restart
proxy_off
;;
esac
fi
@frgomes
Copy link
Author

frgomes commented Mar 4, 2017

Suppose you have a wireless connection with SSID called OpenWRT-5G.
In this supposed scenario, perform the following steps:

  1. Download this script onto /etc/NetworkManager/dispatcher.d so that it matches your SSID name;
  2. Adjust variable INTF so that it matches the name of your wireless interface;
  3. Adjust variable DEFAULT_PROXY so that it matches your network environment.
  4. Double check the logic of the up event, adapting it to your needs.

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