3 # Usage: run to trust or untrust dns. public wifi sometimes needs to
4 # trust dns initially to log in.
7 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
9 source /a
/bin
/bash-bear-trap
/bash-bear
11 script_name
="${BASH_SOURCE[0]}"
12 script_name
="${script_name##*/}"
14 # removes malware and adult content
15 servers
=(1.1.1.3 1.0.0.3 2606:4700:4700::1113 2606:4700:4700::1003)
17 servers
=(1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001)
20 servers
=(8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844)
24 m
() { printf "%s\n" "$*"; "$@"; }
25 e
() { printf "%s\n" "$@"; }
27 local tmp tmpdir dest
="$1"
28 local base
="${dest##*/}"
33 tmp
=$
(rsync
-ic $tmpdir/"$base" "$dest")
41 # i symlinked the script to another name to make it work different
51 if [[ -e /etc
/NetworkManager
/conf.d
/dns.conf
]]; then
52 rm -fv /etc
/NetworkManager
/conf.d
/dns.conf
53 if [[ $
(systemctl is-active NetworkManager
) == active
]]; then
54 m systemctl restart NetworkManager
58 # https://github.com/jonathanio/update-systemd-resolved
59 # suggests this will help prevent leakage into a vpn interface
60 cat >/etc
/systemd
/resolved.conf.d
/untrusted-network.conf
<<EOF
64 # https://wiki.archlinux.org/index.php/Systemd-resolved#Manually
65 cat >/etc
/systemd
/resolved.conf.d
/untrusted-network.conf
<<EOF
72 i
/etc
/NetworkManager
/conf.d
/dns.conf
<<'EOF'
75 systemd-resolved=false
78 if $ir && [[ $
(systemctl is-active NetworkManager
) == active
]]; then
79 m systemctl restart NetworkManager
83 dhclient_restart
=false
85 if ! grep -qP '\bdomain-name-servers\b' /etc
/dhcp
/dhclient.conf
; then
86 sed -i 's/^ *request/request domain-name-servers,/' /etc
/dhcp
/dhclient.conf
88 e
$0: dhclient_restart
=true
92 # wait for networkmanager to come back
93 for ((i
=0; i
<10; i
++)); do
94 if read -r _ _ _ _ gateway_if _
< <(ip route get
8.8.8.8); then
101 if [[ $gateway_if ]]; then
102 # we could do this, but dhclient is still running and will use its old settings
103 # from dependencies of ifupdown,
104 # from man dhclient-script
105 # from /etc/dhcp/dhclient-enter-hooks.d/resolved
106 # rm -f /run/systemd/resolved.conf.d/*$gateway_if*
109 if $dhclient_restart && grep -Pq "^ *auto ($gateway_if|.* $gateway_if( |$))" /etc
/network
/interfaces
; then
114 # At least on systemd 237 ifupdown it sets a global and this is not
115 # needed. we are way past that, but I dont think it hurts.
116 resolvectl revert
$gateway_if
118 e
$0: no gateway_if found
121 m systemctl restart systemd-resolved
125 # just for curiosity i did a
126 # wrapper around dhclient, then ifdown eth0; ifup eth0:
128 # Tue Mar 9 18:29:05 EST 2021
129 # args -4 -v -r -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0
140 # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
141 # IFUPDOWN_eth0=pre-down
143 # Tue Mar 9 18:29:07 EST 2021
144 # args -1 -4 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0
155 # PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
156 # IFUPDOWN_eth0=post-up