1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-11-18 06:08:21 +00:00

Block ads over IPv6

I’m pretty sure this works well.  Maybe someone else can try it out.
This commit is contained in:
Salmela 2015-12-31 20:26:05 -06:00
parent 8ffa5e9357
commit d646612a25
2 changed files with 36 additions and 23 deletions

View File

@ -36,10 +36,6 @@ IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1
IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}')
# IPv6 support to be added later
#IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1)
#IPv6linkLocal=$(ip addr show | awk '/inet/ && /scope\ link/ && /fe80/ {print $2}' | cut -d'/' -f1)
availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1) availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1)
dhcpcdFile=/etc/dhcpcd.conf dhcpcdFile=/etc/dhcpcd.conf
@ -65,6 +61,9 @@ welcomeDialogs()
# Display the welcome dialog # Display the welcome dialog
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" $r $c whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" $r $c
# Support for a part-time dev
whiptail --msgbox --backtitle "Plea" --title "Free and open source" "The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" $r $c
# Explain the need for a static address # Explain the need for a static address
whiptail --msgbox --backtitle "Initating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly. whiptail --msgbox --backtitle "Initating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
@ -116,7 +115,9 @@ done
useIPv6dialog() useIPv6dialog()
{ {
whiptail --msgbox --backtitle "Coming soon..." --title "IPv6 not yet supported" "I need your help for IPv6. Consider donating at: http://pi-hole.net/donate" $r $c piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
whiptail --msgbox --backtitle "IPv6..." --title "$piholeIPv6 will be used to block ads." $r $c
sudo touch /etc/pihole/.useIPv6
} }
getStaticIPv4Settings() getStaticIPv4Settings()
@ -263,6 +264,17 @@ installCron
sudo /usr/local/bin/gravity.sh sudo /usr/local/bin/gravity.sh
} }
displayFinalMessage(){
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using:
$IPv4addr
$piholeIPv6
If you set a new IP address, you should restart the Pi.
The install log is in /etc/pihole." $r $c
}
######## SCRIPT ############ ######## SCRIPT ############
# Start the installer # Start the installer
welcomeDialogs welcomeDialogs
@ -288,16 +300,10 @@ fi
# Decide is IPv6 will be used # Decide is IPv6 will be used
if [[ "$useIPv6" = true ]];then if [[ "$useIPv6" = true ]];then
# If only IPv6 is selected, exit because it is not supported yet useIPv6dialog
if [[ "$useIPv6" = true ]] && [[ "$useIPv4" = false ]];then
useIPv6dialog
exit
else
useIPv6dialog
fi
else else
useIPv6=false useIPv6=false
echo "IPv6 will NOT be used. Consider a donation at pi-hole.net/donate" echo "IPv6 will NOT be used."
fi fi
# Install and log everything to a file # Install and log everything to a file
@ -306,11 +312,7 @@ installPihole | tee $tmpLog
# Move the log file into /etc/pihole for storage # Move the log file into /etc/pihole for storage
sudo mv $tmpLog $instalLogLoc sudo mv $tmpLog $instalLogLoc
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using this IP: $IPv4addr. displayFinalMessage
If you set a new IP address, it should work fine, but you may want to reboot the Pi at some point.
The install log is in /etc/pihole." $r $c
sudo service dnsmasq start sudo service dnsmasq start
sudo service lighttpd start sudo service lighttpd start

View File

@ -11,15 +11,20 @@
# (at your option) any later version. # (at your option) any later version.
piholeIPfile=/tmp/piholeIP piholeIPfile=/tmp/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
if [[ -f $piholeIPfile ]];then if [[ -f $piholeIPfile ]];then
if [[ -f $piholeIPv6file ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat $piholeIPfile)
rm $piholeIPfile rm $piholeIPfile
else else
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
piholeIP=${piholeIPCIDR%/*} piholeIP=${piholeIPCIDR%/*}
fi fi
# Ad-list sources--one per line in single quotes # Ad-list sources--one per line in single quotes
@ -208,7 +213,13 @@ function gravity_unique() {
function gravity_hostFormat() { function gravity_hostFormat() {
# Format domain list as "192.168.x.x domain.com" # Format domain list as "192.168.x.x domain.com"
echo "** Formatting domains into a HOSTS file..." echo "** Formatting domains into a HOSTS file..."
cat $piholeDir/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"' " $0}' > $piholeDir/$accretionDisc # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols
if [[ -n $piholeIPv6 ]];then
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' > $piholeDir/$accretionDisc
else
# Otherwise, just create gravity.list as normal using IPv4
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' > $piholeDir/$accretionDisc
fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp $piholeDir/$accretionDisc $adList cp $piholeDir/$accretionDisc $adList
} }