-
Notifications
You must be signed in to change notification settings - Fork 0
/
lower-vpn-priority.sh
executable file
·40 lines (30 loc) · 1.1 KB
/
lower-vpn-priority.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
#set > ~/set_vars_script
set -e
shopt -s extglob
USAGE="lower-vpn-priority.sh [OPTIONS]
Options:
-p, --priority <value> Sets the new route priority to the given value (default: 101)
Must be executed as root"
DESCRIPTION="Lowers your VPNs default route priority to 101"
. "$(dirname "$BASH_SOURCE")/lib/parse_args.sh"
KEYWORDS=("-p" "--priority")
parse_args __USAGE "$USAGE" __DESCRIPTION "$DESCRIPTION" "$@"
priority="${KW_ARGS['--priority']-${KW_ARGS['-p']}}"
if [[ "$EUID" -ne 0 ]]
then
echo "ERROR: You need to be root. Try 'sudo lower-vpn-priority.sh'"
exit 1
fi
vpn_route="$(ip route list match default dev tun0)"
if [[ -z "$vpn_route" ]]
then
echo "ERROR: Could not find route to replace!"
exit 2
fi
ip route del $vpn_route
ip route add ${vpn_route/metric +([0-9])/metric ${priority:-101}} || {
echo "ERROR: Could not recreate vpn route! Your network device 'tun0' (hopefully your vpn) might not work correctly. If you encounter issues, try reconnecting.
Alternatively, execute the command 'sudo ip route add ${vpn_route/metric +([0-9])/metric 101}' yourself."
exit 3
}