mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Merge pull request #2492 from pi-hole/fix/IPv4_detection
IPv4 detection improvements.
This commit is contained in:
commit
d514608f91
1 changed files with 21 additions and 10 deletions
|
@ -465,21 +465,32 @@ resetRepo() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# We need to know the IPv4 information so we can effectively setup the DNS server
|
|
||||||
# Without this information, we won't know where to Pi-hole will be found
|
|
||||||
find_IPv4_information() {
|
find_IPv4_information() {
|
||||||
|
# Detects IPv4 address used for communication to WAN addresses.
|
||||||
|
# Accepts no arguments, returns no values.
|
||||||
|
|
||||||
# Named, local variables
|
# Named, local variables
|
||||||
local route
|
local route
|
||||||
|
local IPv4bare
|
||||||
|
|
||||||
# Find IP used to route to outside world by checking the the route to Google's public DNS server
|
# Find IP used to route to outside world by checking the the route to Google's public DNS server
|
||||||
route=$(ip route get 8.8.8.8)
|
route=$(ip route get 8.8.8.8)
|
||||||
# Use awk to strip out just the interface device as it is used in future commands
|
|
||||||
IPv4dev=$(awk '{for (i=1; i<=NF; i++) if ($i~/dev/) print $(i+1)}' <<< "${route}")
|
# Get just the interface IPv4 address
|
||||||
# Get just the IP address
|
# shellcheck disable=SC2059,SC2086
|
||||||
IPv4bare=$(awk '{print $7}' <<< "${route}")
|
# disabled as we intentionally want to split on whitespace and have printf populate
|
||||||
# Append the CIDR notation to the IP address
|
# the variable with just the first field.
|
||||||
IPV4_ADDRESS=$(ip -o -f inet addr show | grep "${IPv4bare}" | awk '{print $4}' | awk 'END {print}')
|
printf -v IPv4bare "$(printf ${route#*src })"
|
||||||
# Get the default gateway (the way to reach the Internet)
|
# Get the default gateway IPv4 address (the way to reach the Internet)
|
||||||
IPv4gw=$(awk '{print $3}' <<< "${route}")
|
# shellcheck disable=SC2059,SC2086
|
||||||
|
printf -v IPv4gw "$(printf ${route#*via })"
|
||||||
|
|
||||||
|
if ! valid_ip "${IPv4bare}" ; then
|
||||||
|
IPv4bare="127.0.0.1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Append the CIDR notation to the IP address, if valid_ip fails this should return 127.0.0.1/8
|
||||||
|
IPV4_ADDRESS=$(ip -oneline -family inet address show | grep "${IPv4bare}" | awk '{print $4}' | awk 'END {print}')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get available interfaces that are UP
|
# Get available interfaces that are UP
|
||||||
|
|
Loading…
Reference in a new issue