-
Notifications
You must be signed in to change notification settings - Fork 7
/
pihole_ipv6_check
executable file
·74 lines (51 loc) · 2.37 KB
/
pihole_ipv6_check
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
###########################################################################
# pihole_ipv6_check
# Checks the Pi-hole server's current IPv6 address and updates the
# IPv6 address configured in /etc/pihole/setupVars.conf if necessary.
# Fixes Pi-hole timeout issue reported at http://bit.ly/2EHWSFy.
# Part of https://github.com/stevejenkins/pihole-utils/
# Version 2.2 - Mar 24, 2019 - Steve Jenkins (stevejenkins.com)
# Rename script for uniformity
# Add repo link in script comments
# Version 2.1 - Jan 20, 2019 - Steve Jenkins (stevejenkins.com)
# User can select which adapter is used for IPv6 check
# Version 2.0 - Jan 20, 2019 - Steve Jenkins (stevejenkins.com)
# Changed local IPv6 check method to support wider range of Linux variants
# Version 1.1 - Feb 14, 2018 - Steve Jenkins (stevejenkins.com)
# Fixed awk statement for current Pi-hole configured address
# Modernized shell script expressions
# Added comments to script
# Version 1.0 - linuxpng (https://pastebin.com/Wd0Qyfyw)
# Original version of script
# USAGE
# You can run ./pihole_ipv6_check from the command line, or run it hourly by
# adding the following to your crontab:
# @hourly /usr/local/bin/pihole-utils/pihole_ipv6_check > /dev/null 2>&1 #Check Pi-hole IPv6 configuration
###########################################################################
# USER-CONTROLLED OPTIONS
PIHOLE_ADAPTER=eth1
###########################################################################
# Only used for debugging
# set -x
# Check host's current Global IPv6 address
current_ipv6=$(ip -6 addr show dev $PIHOLE_ADAPTER | awk '/inet6/{print $2}' | head -n 1 | awk -F'/' '{print $1}')
printf "\nCurrent adapter IPv6 address: $current_ipv6\n"
# Check IPv6 address configured in Pi-hole
pihole_ipv6=$(grep IPV6_ADDRESS < /etc/pihole/setupVars.conf | awk -F '=' '{print $2}')
printf "Pi-hole configured IPv6 address: $pihole_ipv6\n"
# Exit if IPv6 addresses match
if [ "$current_ipv6" = "$pihole_ipv6" ]; then
printf '\nIPv6 addresses match! No action required.\n'
exit 0
else
# Update the IPv6 address in setupVars.conf with the host's IPv6 address
printf '\nUpdating Pi-hole configuration...\n'
sed -i "s/IPV6_ADDRESS=.*/IPV6_ADDRESS=${current_ipv6}/g" /etc/pihole/setupVars.conf;
# Run pihole -g to pick up changes
printf '\nReloading Pi-hole...\n\n'
pihole -g
# All done!
printf '\nDone!\n'
exit 1
fi