Reply
New Member
Posts: 18
Registered: ‎05-22-2016
Kudos: 37

[Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headless)

[ Edited ]

Greetings,

 

Thought I'd make a step-by-step tutorial for anyone looking for a straight forward installation of both the UniFi controller and Pi-hole without needing to hook up the Raspberry Pi to a monitor with keyboard and mouse (headless).


If you still have questions or if I forgot to explain some part you're stuck at, please post here so I can add this to the tutorial.

Dutch version: https://gathering.tweakers.net/forum/list_messages/1873125

 

What you will physically need

- Raspberry Pi 3 model B(+)

- Ethernet cable to connect it to an existing network

- capability to connect the MicroSD card to a computer via a card reader

 

Download the necessary tools and raspbian operating system image

1. Raspbian Stretch Lite (= without desktop interface) through the ZIP option (or torrent)

https://www.raspberrypi.org/downloads/raspbian/

Direct: https://downloads.raspberrypi.org/raspbian_lite_latest

 

2. Rufus to install the image to the MicroSD card

https://rufus.akeo.ie

Direct: https://github.com/pbatard/rufus/releases/download/v3.4/rufus-3.4.exe

 

3. Advanced IP Scanner to get the IP address

http://www.advanced-ip-scanner.com

Direct: http://www.advanced-ip-scanner.com/download/Advanced_IP_Scanner_2.5.3646.exe

 

4. If you are not using Windows 10, you can use PuTTY instead of the command prompt

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

Direct: https://the.earth.li/~sgtatham/putty/latest/w64/putty-64bit-0.70-installer.msi

 

Installing Raspbian on the MicroSD

Open up Rufus to install Raspbian.

  1. Make sure your MicroSD card is selected

  2. Press SELECT and select the downloaded raspbian-stretch-lite.zip
    Tip: you don’t have to extract the .zip

  3. Press START

  4. Accept the warning about removing all of the data on the MicroSD

    Rufus.png

  5. wait until the process is done.

 

Activate SSH

Activate SSH before starting the Raspberry Pi by adding a new text file to the main folder of the MicroSD card (boot partition).

Rename this text file to    ssh     and remove the .txt extension.

 

The MicroSD is ready now, insert it into your raspberry pi, connect an ethernet cable and turn on the Raspberry Pi.

 


Lookup the IP address

If you’re using Advanced IP Scanner, you can simply press SCAN and wait until the Raspberry Pi shows up.

 


Login via SSH and changing the password

  1. Open up the command prompt (cmd in start of windows)
    Tip: You should be able to paste commands by right clicking into the command prompt.

  2. Login with the SSH command
    Note: change the IP address with the IP address of your Raspberry Pi

    ssh 192.168.1.2 -l pi
  3. As we have not defined an SSH key, it will ask if we trust the host.

    The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
    ECDSA key fingerprint is SHA256:XXX.
    Are you sure you want to continue connecting (yes/no)? 
    
    yes
  4. When typing in the password, you will not see characters being displayed, simply type it and enter

    The default password is:
    
    raspberry


    I've added all the following commands into a simple script that I share through my Microsoft Onedrive account. By entering the following code right after you login into your Raspberry Pi with ssh you will not have to copy/paste all of these commands.
    You also get to choose the stable version of the UniFi controller that you'd like to install.

    If you wish to check the script before executing, check the onedrive link in the command below.

    wget --no-check-certificate "https://onedrive.live.com/download?cid=CC3B41A0D7E2BDD2&resid=CC3B41A0D7E2BDD2%21178166&authkey=AJ6AkZFDYf0CuEQ" -O install-unifi-pihole.sh && chmod +x install-unifi-pihole.sh && ./install-unifi-pihole.sh
    If you do not wish to use the script, just continue following the tutorial:

  5. First thing you should do is changing the default password, which is very easy to do.
    After entering the passwd command, it'll ask you to type the current and your new password twice.

    pi@raspberrypi:~ $ passwd
    Changing password for pi.
    (current) UNIX password:
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully


Update all existing packages

To make sure you have all the latest and greatest (firmware) updates and to clean up any unused/old ones, execute the following command

 

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get autoremove && sudo apt-get autoclean



Installation of the UniFi controller

Copy the download link of the UniFi controller for Debian.

You can go to the (beta) updates blog and copy the Debian download link at the bottom of the posts (UniFi Controller for Debian/Ubuntu).
https://community.ubnt.com/t5/UniFi-Updates-Blog/bg-p/Blog_UniFi

https://community.ubnt.com/t5/UniFi-Beta-Blog/bg-p/Blog_UniFi_Beta (you need beta access)

 

You can also add Ubiquiti’s source list, and install/update via apt-get.
I do recommend to always check the updates blog as it has vital information that may affect your setup when updating to a newer version.

 

  1. Use the link in the wget command to download the controller installation package.

    wget http://dl.ubnt.com/unifi/5.9.29/unifi_sysvinit_all.deb
  2. Install Java 8 as it’s not included with the light version of Raspbian.

    sudo apt-get -y install oracle-java8-jdk 
  3. Install UniFi and its dependencies.

    sudo dpkg -i unifi_sysvinit_all.deb; sudo apt-get install -f -y

Go to your UniFi controller via the IP address and port:

E.g: https://192.168.1.2:8443

You’ll want to set a reserved IP in the UniFi controller for the Raspberry Pi.

 

 

Installation of Pi-hole

Execute the following command and configure Pi-hole

 

curl -sSL https://install.pi-hole.net | bash
> Choose an interface:
(*) eth0  (= ethernet cable)

> Choose your DNS provider
Custom
1.1.1.1, 1.0.0.1

> Choose your adblocking providers
leave them enabled > IPv4 and/or IPv6
both > PiHole wants to set a static IP. Let it do its thing. I guess they haven’t heard of DHCP reservation/central management yet. > Install the Web admin interface and the web server

Change the password used to log into the web admin interface

 

pi@raspberrypi:~ $ pihole -a -p
Enter New Password (Blank for no password):
Confirm Password:
  [✓] New password set

 

Go to your Pi Hole web admin interface via the IP address and /admin:

E.g: http://192.168.1.2/admin

 

 

Updating the UniFi controller and Pi-hole with future updates

 

I've also made a simple script for updating your system, controller and pi-hole in one go. Simply enter ./update-unifi-pihole.sh in the future to use the script again without having to redownload it.

 

wget --no-check-certificate "https://onedrive.live.com/download?cid=CC3B41A0D7E2BDD2&resid=CC3B41A0D7E2BDD2%21178278&authkey=ANamQUHZPry4z5U" -O install-unifi-pihole.sh && chmod +x install-unifi-pihole.sh && ./install-unifi-pihole.sh

or keep following the tutorial:

 

If you want to install a new version of the UniFi controller you basically delete the old downloaded version, download the new and install it.
Tip: you can use Tab to complete commands/file-names etc.

rm unifi_sysvinit_all.deb
wget http://dl.ubnt.com/unifi/x.x.xx/unifi_sysvinit_all.deb
sudo dpkg -i unifi_sysvinit_all.deb


Updating Pi-hole is very simple

pihole -up

 

 

New Member
Posts: 1
Registered: ‎01-19-2017
Kudos: 1

Re: [Step-By-Step Tutorial] Raspberry Pi with UniFi controller and Pi-hole from scratch (headless)

Great Tutorial! Thanks!
If I may suggest an improvement; it just lacks the explanation on how/where to change the settings in the Unifi controller in order to force all clients to use Pi-Hole.
PS: It is fortunately quite easy to find; I used this one. Of the two options I gave all network devices the IP address of my Raspberri Pi as DNS Server.

Emerging Member
Posts: 55
Registered: ‎01-02-2018
Kudos: 9

Re: [Step-By-Step Tutorial] Raspberry Pi with UniFi controller and Pi-hole from scratch (headless)

Awesome job man! Thanks for putting this together! This will help a lot of people!

New Member
Posts: 18
Registered: ‎05-22-2016
Kudos: 37

Re: [Step-By-Step Tutorial] Raspberry Pi with UniFi controller and Pi-hole from scratch (headless)

I've added an install-script and an upgrade-script to the tutorial for people who do not wish to copy/paste all the commands.
I've tested both and they worked flawlessly on my Pi. Thumbsup


All you'll have to do with the script is:
1. copy/paste the line of commands to download and run the script
2. enter a new password for your raspberry pi
3. enter the (stable) unifi controller version you wish to install
4. press enter a couple of times for the initial configuration of pi-hole
5. enter a new password for the pi-hole web interface

 

Check the install script here on Onedrive: https://1drv.ms/u/s!AtK94tegQTvMiu92g9EVSXSQz6SJrQ

Check the upgrade script here on Onedrive: https://1drv.ms/u/s!AtK94tegQTvMiu8giMwtcnKuh9nYrg

New Member
Posts: 11
Registered: ‎06-26-2017
Kudos: 1
Solutions: 1

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

Really nice guide! Thank you. Worked as a charm

New Member
Posts: 1
Registered: ‎07-25-2016
Kudos: 1

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

Great man make things simple!

I'm new to linux, great I found this post.

New Member
Posts: 1
Registered: ‎01-19-2018
Kudos: 1

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

This worked like a charm.

 

I have one question however.

 

I set up the controller with a backup and now it doesn't work with "Cloud access".

Any idea what I need to do?

 

It only says "connecting" but nothing happens and I can't see it at "unifi.ubnt.com" when I log in.

 

 

New Member
Posts: 1
Registered: ‎07-20-2018
Kudos: 1

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

Wow!

 

This is great! Thank you very much!

 

I've set this up and it works like a charm.

 

I have one question: when I want to make a reboot or shutdown the combination, what is the best and safest way?

 

Should I log in with ssh and give a command reboot or halt?

 

Thanks.

 

New Member
Posts: 1
Registered: 2 weeks ago

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl


@johlun wrote:

This worked like a charm.

 

I have one question however.

 

I set up the controller with a backup and now it doesn't work with "Cloud access".

Any idea what I need to do?

 

It only says "connecting" but nothing happens and I can't see it at "unifi.ubnt.com" when I log in.

 

 


This happened to me too. I realized that the controller I installed the backup from was still running on my computer.

 

After closing the old controller I was able to access the new controller on my Raspberry Pi via cloud access with no problems.

New Member
Posts: 1
Registered: ‎06-26-2014
Kudos: 1

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

Great guide, thanks!

 

After instalation completed, I am unable to access the Unifi controller.. How do I access this?  I also wonder how I access remotely.  Sorry, noob question.  And VERY new to linux.

 

Thanks in advance!!

New Member
Posts: 18
Registered: ‎05-22-2016
Kudos: 37

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

[ Edited ]

"Should I log in with ssh and give a command reboot or halt?"

 

I usually just login with ssh and "sudo reboot now" and both the controller & Pi hole will start up again without problems.

 

 

"After instalation completed, I am unable to access the Unifi controller.. How do I access this?  I also wonder how I access remotely.  Sorry, noob question.  And VERY new to linux.

 

Thanks in advance!!"


You should be able to go to the IP address with the port 8443 in your web browser.
like: https://192.168.0.2:8443


If you want to access it from outside the network, you could setup cloud access.
https://help.ubnt.com/hc/en-us/articles/115012240067-UniFi-How-to-Enable-Cloud-Access-for-Remote-Man...

 

or setup a port forwarding rule in your USG via the controller.
You'll have to port-forward the 8443 port to the IP address of the controller.

Image 1.png

 

After that you'll need to know your WAN IP address.
You can easily find this by using a website like this one:
https://whatismyipaddress.com/

You can then use this IP address to access your controller.
example: https://123.123.123.123:8443
if you changed the "Port" to something else like: 20000 then you'll have to do: https://123.123.123.123:20000

 

If you have a dynamic WAN IP address like most people do (which means it can change), you should probably setup a DDNS.
You can set this up in the settings of the controller -> services -> Dynamic DNS.
You'll need an account on a website like "afraid": https://freedns.afraid.org/dynamic/

 Image 4.png

Image 3.png

 

When the DDNS is setup, you can go to your controller by doing:

https://hostname.domain: port

example: https://your-hostname-you-have-chosen-on-afraid.uk.to:20000

 

This will work because everytime your WAN IP changes, the "your-hostname-you-have-chosen-on-afraid.uk.to" will change to the new IP address.

New Member
Posts: 1
Registered: ‎06-14-2018

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl

Has anyone tried the Pi with the PoE module?

New Member
Posts: 18
Registered: ‎05-22-2016
Kudos: 37

Re: [Step-By-Step Tutorial/Guide] Raspberry Pi with UniFi controller and Pi-hole from scratch (headl


@itskv wrote:

Has anyone tried the Pi with the PoE module?


No, but It should work fine. There was an initial problem with it but they've recalled those bad ones.

Reply