1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 23:08:07 +00:00

Check IP info for outgoing interface

This commit is contained in:
Dan Schaper 2015-11-25 13:43:59 -08:00
parent 464003d674
commit 29ae66c6db

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements # Pi-hole: A black hole for Internet advertisements
# by Jacob Salmela # by Jacob Salmela
# Network-wide ad blocking via your Raspberry Pi # Network-wide ad blocking via your Raspberry Pi
@ -24,9 +24,11 @@ columns=$(stty -a | tr \; \\012 | egrep 'columns' | cut -d' ' -f3)
r=$(( rows / 2 )) r=$(( rows / 2 ))
c=$(( columns / 2 )) c=$(( columns / 2 ))
IPv4addr=$(ip -4 addr show | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/); ip = substr($0,RSTART,RLENGTH); print ip}' | sed '/^\s*$/d' | grep -v "127.0.0.1") # Find IP used to route to outside world
IPv4mask=$(ifconfig | awk -F':' '/inet addr/ && !/127.0.0.1/ {print $4}') IPv4info=$(ip route get 8.8.8.8)
IPv4gw=$(ip route show | awk '/default\ via/ {print $3}') IPv4dev=$(echo $IPv4info| awk '{print $5}')
IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}')
IPv4gw=$(echo $IPv4info | awk '{print $3}')
# IPv6 support to be added later # IPv6 support to be added later
#IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1) #IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1)
@ -117,7 +119,6 @@ getStaticIPv4Settings()
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
IP address: $IPv4addr IP address: $IPv4addr
Subnet mask: $IPv4mask
Gateway: $IPv4gw" $r $c) then Gateway: $IPv4gw" $r $c) then
# If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict.
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
@ -138,22 +139,17 @@ else
IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c $IPv4addr 3>&1 1>&2 2>&3) IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c $IPv4addr 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then if [[ $? = 0 ]];then
echo "Your static IPv4 address: $IPv4addr" echo "Your static IPv4 address: $IPv4addr"
# Ask for the subnet mask # Ask for the gateway
IPv4mask=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 netmask" --inputbox "Enter your desired IPv4 subnet mask" $r $c $IPv4mask 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then
echo "Your static IPv4 netmask: $IPv4mask"
# Ask for the gateway
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c $IPv4gw 3>&1 1>&2 2>&3) IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c $IPv4gw 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then if [[ $? = 0 ]];then
echo "Your static IPv4 gateway: $IPv4gw" echo "Your static IPv4 gateway: $IPv4gw"
# Give the user a chance to review their settings before moving on # Give the user a chance to review their settings before moving on
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
IP address: $IPv4addr IP address: $IPv4addr
Subnet mask: $IPv4mask
Gateway: $IPv4gw" $r $c)then Gateway: $IPv4gw" $r $c)then
# If the settings are correct, then we need to set the piholeIP # If the settings are correct, then we need to set the piholeIP
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script # Saving it to a temporary file us to retrieve it later when we run the gravity.sh script
echo $IPv4addr > /tmp/piholeIP echo ${IPv4addr%/*} > /tmp/piholeIP
# After that's done, the loop ends and we move on # After that's done, the loop ends and we move on
ipSettingsCorrect=True ipSettingsCorrect=True
else else
@ -167,12 +163,6 @@ else
exit exit
fi fi
else else
# Cancelling subnet mask settings window
ipSettingsCorrect=False
echo "User canceled."
exit
fi
else
# Cancelling IPv4 settings window # Cancelling IPv4 settings window
ipSettingsCorrect=False ipSettingsCorrect=False
echo "User canceled." echo "User canceled."
@ -188,7 +178,7 @@ setStaticIPv4()
{ {
# Append these lines to /etc/dhcpcd.conf to enable a static IP # Append these lines to /etc/dhcpcd.conf to enable a static IP
echo "interface $piholeInterface echo "interface $piholeInterface
static ip_address=$IPv4addr/24 static ip_address=$IPv4addr
static routers=$IPv4gw static routers=$IPv4gw
static domain_name_servers=$IPv4gw" | sudo tee -a $dhcpcdFile >/dev/null static domain_name_servers=$IPv4gw" | sudo tee -a $dhcpcdFile >/dev/null
} }
@ -224,15 +214,15 @@ sudo rm /var/www/master.zip 2>/dev/null
sudo touch /var/log/pihole.log sudo touch /var/log/pihole.log
sudo chmod 644 /var/log/pihole.log sudo chmod 644 /var/log/pihole.log
sudo chown dnsmasq:root /var/log/pihole.log sudo chown dnsmasq:root /var/log/pihole.log
sudo curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh sudo curl -o /usr/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh
sudo curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh sudo curl -o /usr/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh
sudo curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh sudo curl -o /usr/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh
sudo curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh sudo curl -o /usr/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh
sudo chmod 755 /usr/local/bin/gravity.sh sudo chmod 755 /usr/bin/gravity.sh
sudo chmod 755 /usr/local/bin/chronometer.sh sudo chmod 755 /usr/bin/chronometer.sh
sudo chmod 755 /usr/local/bin/whitelist.sh sudo chmod 755 /usr/bin/whitelist.sh
sudo chmod 755 /usr/local/bin/piholeLogFlush.sh sudo chmod 755 /usr/bin/piholeLogFlush.sh
sudo /usr/local/bin/gravity.sh sudo /usr/bin/gravity.sh
} }
######## SCRIPT ############ ######## SCRIPT ############