This is a basic checklist for now, We will update it in the future.
* Fork the repo and create your new branch based on the `development` branch.
* Commit Unix line endings
* If you want, try to keep to the theme of black holes/gravity. This can add some fun to your submission.
* Submit Pull Requests to the development branch only.
* Before Submitting your Pull Request, merge `development` with your new branch and fix any conflicts. (Make sure you don't break anything in development!)
* Be patient. We will review all submitted pull requests, but our focus is on stability.. please don't be offended if we reject your PR, or it appears we're doing nothing with it! We'll get around to it..
Designed For Raspberry Pi A+, B, B+, 2, 3B, and Zero (with an Ethernet/Wi-Fi adapter)
Works on most Debian and CentOS/RHEL based distributions!
Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/).
1. Install Raspbian
2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!)
## Pi-hole Is Free, But Powered By Your Donations
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "Free, but powered by donations")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate")
If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer
Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/).
- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037)
- [Sky-Hole](http://dlaa.me/blog/post/skyhole)
- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/)
- [unRaid-hole](https://github.com/spants/unraidtemplates/blob/master/Spants/unRaid-hole.xml#L13)--[Repo and more info](http://lime-technology.com/forum/index.php?PHPSESSID=c0eae3e5ef7e521f7866034a3336489d&topic=38486.0)
- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d)
- [MakeUseOf: Adblock Everywhere, The Pi-hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/)
- [Lifehacker: Turn Your Pi Into An Ad Blocker With A Single Command](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)!
- [Pi-hole on TekThing](https://youtu.be/8Co59HU2gY0?t=2m)
- [Pi-hole on Security Now! Podcast](http://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s)
- [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/)
- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/)
## Partnering With Optimal.com
Pi-hole will be teaming up with [Rob Leathern's subscription service to avoid ads](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d). This service is unique and will help content-creators and publishers [still make money from visitors who are using an ad ablocker](http://techcrunch.com/2015/12/17/the-new-optimal/).
Send a one-time donation or sign up for Optimal.com's service using our link below to provide us with a small portion of the monthly fee.
The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads.
## Get Help Or Connect With Us On The Web
A more detailed explanation of the installation can be found [here](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0).
- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
## Gravity
The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)).
## Technical Details
## Whitelist and blacklist
Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details
The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads.
### Gravity
The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)).
## Web Interface
The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at:
`http://192.168.1.x/admin/index.php`
The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at:
`http://192.168.1.x/admin/index.php` or `http://pi.hole/admin`
Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details ![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png)
## API
A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON:
```JSON
```json
{
"domains_being_blocked": "136708",
"dns_queries_today": "18108",
"ads_blocked_today": "14648",
"ads_percentage_today": "80.89"
"domains_being_blocked": "136708",
"dns_queries_today": "18108",
"ads_blocked_today": "14648",
"ads_percentage_today": "80.89"
}
```
The same output can be acheived on the CLI by running `chronometer.sh -j`
![Web](http://i.imgur.com/m114SCn.png)
The same output can be achieved on the CLI by running `chronometer.sh -j`
## Real-time Statistics
You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh).
![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg)
You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg)
## Help
- See the [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) entry for more details
- There is also an [FAQ section on pi-hole.net](http://pi-hole.net)
## Pi-hole Projects
- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py)
- [Get LED alerts for each blocked ad](http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/)
- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html)
- [x86 Docker container that runs Pi-hole](https://hub.docker.com/r/diginc/pi-hole/)
- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037)
- [Sky-Hole](http://dlaa.me/blog/post/skyhole)
- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/)
- [unRaid-hole](https://github.com/spants/unraidtemplates/blob/master/Spants/unRaid-hole.xml#L13)--[Repo and more info](http://lime-technology.com/forum/index.php?PHPSESSID=c0eae3e5ef7e521f7866034a3336489d&topic=38486.0)
- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d)
- [MakeUseOf: Adblock Everywhere, The Pi-hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/)
- [Lifehacker: Turn Your Pi Into An Ad Blocker With A Single Command](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)!
- [Pi-hole on TekThing](https://youtu.be/8Co59HU2gY0?t=2m)
- [Pi-hole on Security Now! Podcast](http://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s)
- [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/)
- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/)
## Other Operating Systems
This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install only works for a clean install of Raspiban right now since that is how the project originated.
This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install is only for a clean install of a Debian based system, such as the Raspberry Pi.
# Combination of serveral host files on the internet (warning some facebook domains are also blocked but you can go to facebook.com). See https://github.com/mat1th/Dns-add-block for more information.
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#rootcheck
if[[$EUID -eq 0]];then
echo"::: You are root."
else
echo"::: sudo will be used."
# Check if it is actually installed
# If it isn't, exit because the install cannot complete
if[ -x "$(command -v sudo)"];then
exportSUDO="sudo"
else
echo"::: Please install sudo or run this script as root."
exit1
fi
fi
function helpFunc()
{
echo"::: Immediately blacklists one or more domains in the hosts file"
echo":::"
echo":::"
echo"::: Usage: pihole -b domain1 [domain2 ...]"
echo"::: Options:"
echo"::: -d, --delmode Remove domains from the blacklist"
echo"::: -nr, --noreload Update blacklist without refreshing dnsmasq"
echo"::: -f, --force Force updating of the hosts files, even if there are no changes"
echo"::: -q, --quiet output is less verbose"
echo"::: -h, --help Show this help dialog"
echo"::: -l, --list Display your blacklisted domains"
exit1
}
if[[$#=0]];then
echo"Immediately blacklists one or more domains in the hosts file"
echo" "
echo"Usage: blacklist.sh domain1 [domain2 ...]"
echo" "
echo"Options:"
echo" -d, --delmode Remove domains from the blacklist"
echo" -nr, --noreload Update blacklist without refreshing dnsmasq"
echo" -f, --force Force updating of the hosts files, even if there are no changes"
echo" -q, --quiet output is less verbose"
exit1
helpFunc
fi
#globals
blacklist=/etc/pihole/blacklist.txt
adList=/etc/pihole/gravity.list
basename=pihole
piholeDir=/etc/$basename
adList=$piholeDir/gravity.list
blacklist=$piholeDir/blacklist.txt
reload=true
addmode=true
force=false
versbose=true
verbose=true
domList=()
domToRemoveList=()
piholeIPfile=/tmp/piholeIP
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
# 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)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev| awk '{print $4}'| awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
if[[ -f $piholeIPfile]];then
# 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)
#rm $piholeIPfile
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
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}')
piholeIP=${piholeIPCIDR%/*}
fi
modifyHost=false
# After setting defaults, check if there's local overrides
if[[ -r $piholeDir/pihole.conf ]];then
echo"::: Local calibration requested..."
. $piholeDir/pihole.conf
fi
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
function HandleOther(){
function HandleOther(){
#check validity of domain
validDomain=$(echo$1| perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
validDomain=$(echo"$1"| perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if[ -z "$validDomain"];then
echo$1 is not a valid argument or domain name
else
echo"::: $1 is not a valid argument or domain name"
else
domList=("${domList[@]}"$validDomain)
fi
}
@ -66,13 +100,12 @@ function PopBlacklistFile(){
#check blacklist file exists, and if not, create it
if[[ ! -f $blacklist]];then
touch $blacklist
fi
for dom in "${domList[@]}"
do
if$addmode;then
AddDomain $dom
fi
for dom in "${domList[@]}";do
if"$addmode";then
AddDomain "$dom"
else
RemoveDomain $dom
RemoveDomain "$dom"
fi
done
}
@ -83,69 +116,66 @@ function AddDomain(){
grep -Ex -q "$1"$blacklist||bool=true
if$bool;then
#domain not found in the blacklist file, add it!
if$versbose;then
if$verbose;then
echo -n "::: Adding $1 to blacklist file..."
fi
echo$1 >> $blacklist
echo"$1" >> $blacklist
modifyHost=true
echo" done!"
else
if$versbose;then
echo"::: $1 already exists in blacklist.txt! No need to add"
if$verbose;then
echo"::: $1 already exists in $blacklist! No need to add"
fi
fi
}
function RemoveDomain(){
bool=false
grep -Ex -q "$1"$blacklist||bool=true
if$bool;then
#Domain is not in the blacklist file, no need to Remove
if$versbose;then
if$verbose;then
echo"::: $1 is NOT blacklisted! No need to remove"
fi
else
#Domain is in the blacklist file, add to a temporary array
if$versbose;then
if$verbose;then
echo"::: Un-blacklisting $dom..."
fi
domToRemoveList=("${domToRemoveList[@]}"$1)
modifyHost=true
fi
domToRemoveList=("${domToRemoveList[@]}"$1)
modifyHost=true
fi
}
function ModifyHostFile(){
function ModifyHostFile(){
if$addmode;then
#add domains to the hosts file
if[[ -r $blacklist]];then
numberOf=$(cat $blacklist| sed '/^\s*$/d'| wc -l)
plural=;[["$numberOf" !="1"]]&&plural=s
echo":::"
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
echo"No adlists.list file found... using adlists.default!" >> $DEBUG_LOG
printf":::\tNo adlists.list file found... using adlists.default!\n"
fi
# Continuously append the pihole.log file to the pihole_debug.log file
function dumpPiHoleLog {
trap'{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT
echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)"
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#rootcheck
if[[$EUID -eq 0]];then
echo"::: You are root."
else
echo"::: sudo will be used."
# Check if it is actually installed
# If it isn't, exit because the install cannot complete
if[ -x "$(command -v sudo)"];then
exportSUDO="sudo"
else
echo"::: Please install sudo or run this script as root."
exit1
fi
fi
function helpFunc()
{
echo"::: Immediately whitelists one or more domains in the hosts file"
echo":::"
echo"::: Usage: pihole -w domain1 [domain2 ...]"
echo":::"
echo"::: Options:"
echo"::: -d, --delmode Remove domains from the whitelist"
echo"::: -nr, --noreload Update Whitelist without refreshing dnsmasq"
echo"::: -f, --force Force updating of the hosts files, even if there are no changes"
echo"::: -q, --quiet output is less verbose"
echo"::: -h, --help Show this help dialog"
echo"::: -l, --list Display your whitelisted domains"
exit1
}
if[[$#=0]];then
echo"Immediately whitelists one or more domains in the hosts file"
echo" "
echo"Usage: whitelist.sh domain1 [domain2 ...]"
echo" "
echo"Options:"
echo" -d, --delmode Remove domains from the whitelist"
echo" -nr, --noreload Update Whitelist without refreshing dnsmasq"
echo" -f, --force Force updating of the hosts files, even if there are no changes"
echo" -q, --quiet output is less verbose"
exit1
helpFunc
fi
#globals
whitelist=/etc/pihole/whitelist.txt
adList=/etc/pihole/gravity.list
basename=pihole
piholeDir=/etc/$basename
adList=$piholeDir/gravity.list
whitelist=$piholeDir/whitelist.txt
reload=true
addmode=true
force=false
versbose=true
verbose=true
domList=()
domToRemoveList=()
piholeIPfile=/tmp/piholeIP
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
# 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)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev| awk '{print $4}'| awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
if[[ -f $piholeIPfile]];then
# 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)
#rm $piholeIPfile
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
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}')
piholeIP=${piholeIPCIDR%/*}
fi
modifyHost=false
# After setting defaults, check if there's local overrides
if[[ -r $piholeDir/pihole.conf ]];then
echo"::: Local calibration requested..."
. $piholeDir/pihole.conf
fi
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
function HandleOther(){
function HandleOther(){
#check validity of domain
validDomain=$(echo$1| perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
validDomain=$(echo"$1"| perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
if[ -z "$validDomain"];then
echo"::: $1 is not a valid argument or domain name"
else
else
domList=("${domList[@]}"$validDomain)
fi
}
@ -65,13 +99,13 @@ function PopWhitelistFile(){
#check whitelist file exists, and if not, create it
if[[ ! -f $whitelist]];then
touch $whitelist
fi
fi
for dom in "${domList[@]}"
do
do
if$addmode;then
AddDomain $dom
AddDomain "$dom"
else
RemoveDomain $dom
RemoveDomain "$dom"
fi
done
}
@ -79,45 +113,45 @@ function PopWhitelistFile(){
function AddDomain(){
#| sed 's/\./\\./g'
bool=false
grep -Ex -q "$1"$whitelist||bool=true
if$bool;then
#domain not found in the whitelist file, add it!
if$versbose;then
echo -n "::: Adding $1 to whitelist.txt..."
if$verbose;then
echo -n "::: Adding $1 to $whitelist..."
fi
echo$1 >> $whitelist
echo"$1" >> $whitelist
modifyHost=true
if$versbose;then
if$verbose;then
echo" done!"
fi
else
if$versbose;then
echo"::: $1 already exists in whitelist.txt, no need to add!"
if$verbose;then
echo"::: $1 already exists in $whitelist, no need to add!"
fi
fi
}
function RemoveDomain(){
bool=false
grep -Ex -q "$1"$whitelist||bool=true
if$bool;then
#Domain is not in the whitelist file, no need to Remove
if$versbose;then
if$verbose;then
echo"::: $1 is NOT whitelisted! No need to remove"
fi
else
#Domain is in the whitelist file, add to a temporary array and remove from whitelist file
#if $versbose; then
#if $verbose; then
#echo "::: Un-whitelisting $dom..."
#fi
domToRemoveList=("${domToRemoveList[@]}"$1)
modifyHost=true
fi
modifyHost=true
fi
}
function ModifyHostFile(){
function ModifyHostFile(){
if$addmode;then
#remove domains in from hosts file
if[[ -r $whitelist]];then
@ -126,36 +160,39 @@ function ModifyHostFile(){
plural=;[["$numberOf" !="1"]]&&plural=s
echo":::"
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
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
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.
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them."$r$c
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.
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them."$r$c
}
verifyFreeDiskSpace(){
# 50MB is the minimum space needed (45MB install (includes web admin bootstrap/jquery libraries etc) + 5MB one day of logs.)
whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space""\nYour system appears to be low on disk space. pi-hole recomends a minimum of $requiredFreeBytes Bytes.\nYou only have $existingFreeBytes Free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n"$r$c
echo"$existingFreeBytes is less than $requiredFreeBytes"
echo"Insufficient free space, exiting..."
exit1
fi
}
chooseInterface(){
# Turn the available interfaces into an array so it can be used with a whiptail dialog
# Ask if the user wants to use DHCP settings as their static IP
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
Gateway: $IPv4gw"$r$c) then
IP address: $IPv4addr
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.
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.
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."$r$c
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."$r$c
#piholeIP is saved to a permanent file so gravity.sh can use it when updating
$SUDOecho"${IPv4addr%/*}" > /etc/pihole/piholeIP
# Nothing else to do since the variables are already set above
else
# Otherwise, we need to ask the user to input their desired settings.
# 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?
IP address: $IPv4addr
Gateway: $IPv4gw"$r$c)then
# 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. piholeIP is saved to a permanent file so gravity.sh can use it when updating
$SUDOecho"${IPv4addr%/*}" > /etc/pihole/piholeIP
$SUDOecho"$piholeInterface" > /tmp/piholeINT
# After that's done, the loop ends and we move on
ipSettingsCorrect=True
else
# Cancelling gateway settings window
# If the settings are wrong, the loop continues
ipSettingsCorrect=False
echo"::: Cancel selected. Exiting..."
exit1
fi
else
# Cancelling IPv4 settings window
# Cancelling gateway settings window
ipSettingsCorrect=False
echo"::: Cancel selected. Exiting..."
exit1
fi
else
# Cancelling IPv4 settings window
ipSettingsCorrect=False
echo"::: Cancel selected. Exiting..."
exit1
fi
done
# End the if statement for DHCP vs. static
# End the if statement for DHCP vs. static
fi
}
setDHCPCD(){
# Append these lines to dhcpcd.conf to enable a static IP
echo"::: interface $piholeInterface
echo"## interface $piholeInterface
static ip_address=$IPv4addr
static routers=$IPv4gw
static domain_name_servers=$IPv4gw" | $SUDO tee -a $dhcpcdFile >/dev/null
static domain_name_servers=$IPv4gw" | $SUDO tee -a /etc/dhcpcd.conf >/dev/null
}
setStaticIPv4(){
# Tries to set the IPv4 address
if grep -q $IPv4addr$dhcpcdFile;then
# address already set, noop
:
if[[ -f /etc/dhcpcd.conf ]];then
# Debian Family
if grep -q "$IPv4addr" /etc/dhcpcd.conf;then
echo"::: Static IP already configured"
else
setDHCPCD
$SUDO ip addr replace dev "$piholeInterface""$IPv4addr"
echo":::"
echo"::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'"$r$c"$prePopulate" 3>&1 1>&2 2>&3)
if[[$?=0]];then
piholeDNS1=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$1}')
piholeDNS2=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$2}')
if ! valid_ip "$piholeDNS1"||[ ! "$piholeDNS1"];then
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP""One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2"$r$c
if[[$piholeDNS1=="$strInvalid"]];then
piholeDNS1=""
fi
if[[$piholeDNS2=="$strInvalid"]];then
piholeDNS2=""
fi
DNSSettingsCorrect=False
else
if(whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2"$r$c)then
# If it isn't, exit because the install cannot complete
if[[$(dpkg-query -s sudo)]];then
# Check if it is actually installed
# If it isn't, exit because the install cannot complete
if[ -x "$(command -v sudo)"];then
exportSUDO="sudo"
else
else
echo"::: Please install sudo or run this script as root."
exit1
fi
exit1
fi
fi
piholeIPfile=/tmp/piholeIP
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
adListFile=/etc/pihole/adlists.list
adListDefault=/etc/pihole/adlists.default
whitelistScript=/opt/pihole/whitelist.sh
blacklistScript=/opt/pihole/blacklist.sh
if[[ -f $piholeIPfile]];then
# 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)
rm $piholeIPfile
#rm $piholeIPfile
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
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%/*}
fi
@ -48,22 +51,20 @@ if [[ -f $piholeIPv6file ]];then
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " "'{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi
# Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables
basename=pihole
piholeDir=/etc/$basename
adList=$piholeDir/gravity.list
blacklist=$piholeDir/blacklist.txt
whitelist=$piholeDir/whitelist.txt
latentWhitelist=$piholeDir/latentWhitelist.txt
#blacklist=$piholeDir/blacklist.txt
#whitelist=$piholeDir/whitelist.txt
#latentWhitelist=$piholeDir/latentWhitelist.txt
justDomainsExtension=domains
matterandlight=$basename.0.matterandlight.txt
supernova=$basename.1.supernova.txt
eventHorizon=$basename.2.eventHorizon.txt
accretionDisc=$basename.3.accretionDisc.txt
eyeOfTheNeedle=$basename.4.wormhole.txt
#eyeOfTheNeedle=$basename.4.wormhole.txt
# After setting defaults, check if there's local overrides
if[[ -r $piholeDir/pihole.conf ]];then
@ -71,22 +72,6 @@ if [[ -r $piholeDir/pihole.conf ]];then
# 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
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
# Otherwise, just create gravity.list as normal using IPv4
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)