Yesterday I was reading about Pi-hole for DNS sinkhole and was tempted to install Pi-hole for my home network. Luckily I have a Raspberry-Pi lying around since 2014 and now I want to put it to a good use. Follow the steps here to install Pi-hole on a Raspberry-Pi.
Flash an OS on a SD car for Raspberry-Pi
I picked a spare 16GB SD (also called SDXC) card and chose Raspbian (Debian for ARM and packaged for Raspbery-Pi). There’s another official OS you can choose: NOOBS. Feel free to try other options as well on the official RPi web page.
In spirit of experimentation, I decided to download both “Raspbian Buster with desktop” (shiny GUI) and “Raspbian Buster Lite” (headless version with black screen only).
The official RPi guide suggests using balenaEtcher for flashing an image on your SD card. I used macOS to do flashing and it was a painless process. Remember to back up any data dear to you before flashing your SD card.
If you feel geeky, you can use dd
on both macOS and Linux to do raw copy the image to your SD card.
Wire up your Raspberry-Pi
I possess an older model of Raspberry-Pi that does not have wifi on board. If you use Model 4, you can cut off the LAN cable part and set up wifi connecting by following this guide.
- Power source: USB to microUSB
- OS and data: SD card (see above)
- Inputs: USB Keyboard and USB mouse. I used Logitech USB dongle to save a USB port and cut the wires
- Output: A male-to-male HDMI cable to connect with a TV or display
- Networking: LAN cable (RJ45)
- Extras: Check the official guide, but I don’t need audio for my case (we are setting up Pi-hole, remember?)
Make sure to connect all wires and plug the flashed SD card with OS into the Raspberry-Pi. Only then turn on the power. Keep eyes peeled at your TV/display and wait for the glorious moment:
If you chose to use a headless version of Raspbian, you will see this screen instead:
There’s quite some work to do after you have successfully launched the OS.
Change default password or add new users
The default login is pi
and the password is raspberry
. The desktop version will prompt you to change automatically. If you are using the headless version, type passwd
and type old password and type new password twice. For security reasons, you must change the default password immediately and do not enable SSH before doing so!
You might as well disable the sudoer pi
and replace with your user name. Check the official guide, or you know, it’s Linux, so just search for tips how to add sudo users.
Enable SSH server and make it run at startup
Everyone knows the default credentials for a fresh Raspbian image, that’s why SSH is not running by default. Now you have changed the default password, and ready for launching SSH:
sudo systemctl enable ssh.service
sudo systemctl start ssh.service
sudo systemctl status ssh.service
To make sure SSH server runs every time RPi starts up, run the command:
sudo touch /boot/ssh
With SSH server running, how do you connect? Read next.
Discover the IP of your Raspberry-Pi
Apart from the default password, RPi also comes with the default host name raspberrypi
which is reachable via the alias raspberrypi.local
. Now you can SSH to your RPi using this default FQDN:
ssh pi@raspberrypi.local
Feel free to ping for IP address:
ping raspberrypi.local
The IP address of your RPi will usually have this format: 192.169.1.###
.
You also can do a blind scan of whole network:
nmap -sn 192.168.1.0/24
For more tips about discovery, check the official guide.
Change default hostname
There are 2 more default things you should change:
- The file
/etc/hostname
. Change its entry to your own host name. I changed to mine:
mypi-is-cool-3011
- The file
/etc/hosts
. Change this line
127.0.1.1 raspberrypi
to
127.0.1.1 mypi-is-cool-3011
Now you should reboot your RPi:
sudo reboot
Credit to this interesting link.
Keep the OS up-to-date
Having the latest version of your OS and packages can shield you from attacks and can boost performance as well. You can do that with two commands:
sudo apt update
sudo apt upgrade
Now help yourself a coffee. The headless version may take 30 mins and the desktop version can take up to 1 hour or longer. I’m using older RPi with 512MB of RAM, so you may be luckier with newer version of RPi.
Finally: Install Pi-hole
Just follow the installation guide at https://github.com/pi-hole/pi-hole/#one-step-automated-install and you will be fine!
On my RPi it took 15 mins because my RPi is guide ancient. If all goes well, you should be able to see the admin panel via IP address:
or (your chosen host name)
http://mypi-is-cool-3011.local/admin
I’m still thinking whether should I disable my router’s DHCP and use Pi-hole’s DHCP server. At least I made some changes in DNS section:
Follow the official Pi-hole guide to get the most benefits out of it. Have fun and stay safe browsing online! I highly recommend reading a blog post from Troy Hunt on Pi-hole. If you are happy with Pi-hole, consider donating to them as I did!
Bonus: How to shutdown your Raspberry-Pi
In case you decided to shutdown your Raspberry-Pi, run the command:
sudo shutdown -P
and it will power down after 1 minute. If you prefer quick death to your RPi, run:
sudo shutdown -P 0
and it will shutdown immediately.