How to Install Linux and Pi-hole to any Android Device

Instead of turning your old smartphone into e-waste give it new life as a network level ad-blocking device.

A. Nagatani 永谷
8 min readSep 8, 2021
Computer text menu being displayed on a smartphone screen in the dark.
Photo by Kelvin Valerio from Pexels

Table of Contents

DisclaimerOverviewHardware you will needSoftware you will useHands on    1. Installing Busybox    2. Installing linux-deploy    3. Connect with SSH to your android device    4. Update your sources list    5. Installing pi-hole    6. Set your devices to use pihole    7. Fix the admin web-page not load    8. Conclusion

Disclaimer

This guide is aimed at beginners to homelab, it’s goal is to give a full experience of what is like to install Pi-hole in a dedicated device and add it to your home network.

There is a few things to keep in mind, this process will work just like as it would work if you were to install Pi-hole to a raspberry pi, this guide is applicable to all android devices, but due to the wide variety of android devices out there your mileage may vary.

The last thing to consider is the security of your Android device, a device using the latest Android-kernel is desired, if you choose to use a device with an outdated kernel this could represent a vulnerability point in your network.

For the purpose of learning this should be fine, but if you intend running a Pi-hole device on the long run then I strongly suggest that you use a proper device such as a Raspberry Pi Zero-W.

Overview

To say briefly the whole idea is to install and run a Linux OS(Debian) on your Android device and from that Linux installation, install and run pi-hole.

Hardware you will need

  • Any android device. Android device must be rooted.
  • A micro SD card, this is not a must have and you can run directly from the internal storage of your android device if you have enough space, my internal memory isn’t big enough so I will be using an old and low quality 8GB micro sd card, this is not even a class 10 card but it will work.
  • A Terminal to run all the commands, I said “terminal” because you could use the same android device to do this but of course the experience of doing so is not great, so I will be connecting to the android device using SSH from my main computer to run all the commands with the comfort of a big screen and my nice *not virtual* keyboard.

Software you will use

Hands On

1. Installing Busybox

Install Busybox from the Playstore to your Android device, this app is not Busybox itself and is just an installer, so open the app and press “Install”, we will be using the default settings so no further change is necessary here.

2. Installing linux-deploy

Install Linux-deploy from the Playstore to your Android device, now we will have to set up a few different settings.

First on the TOP LEFT tap on the burger menu and go to settings, there is a few interesting configurations that we can set here, turn on the “Autostart”, under the Environment tap on “PATH variable” and enter the location where Busybox is installed, if you used the default settings it should be /system/xbin and then tap on “Update ENV”. Under “Services” turn on the “TELNET” option. That is all for this menu.

Go back to the main screen of Linux-deploy and on the TOP RIGHT corner there is a 3-dot menu, under this menu you can use the “STATUS” option to check your system info such as your architecture.

On the BOTTOM RIGHT there is another menu, here is where we will configure our Linux installation, go ahead and tap on it.

This is the Properties I will be using:

* DistributionDebian* Architecturearm64 (chose the one appropriate to your device)* Distribution SuiteBuster* Installation typeFile* Installation path/storage/52017–38B6/debian.img (*this is the path to my external SD card, you will have to check your own path with a file manager.)*The default option ${EXTERNAL_STORAGE}/linux.img will create the linux img on your internal memory, if this is what you want leave as it is.* Image sizeAutomatic calculation* File systemext4* User nameandroid(you can and should change this, this is the username you will use to login on your linux system as well through ssh)* User password*********(you must change this, this is the password you will use to login on your linux system as well through ssh)* Locationen_US.UTF-8 (this is optional and you can either leave the default ‘C’ or change to your own locale)* INITEnable: TRUE(just check it)* Init Systemsysv* SSHEnable: TRUE(*I’m using the default settings but if you run into any trouble with android you might need to change the ssh port, the default is 22 if this does not work just use 2222)* Pulse audio and GUINot enabled, leave it unchecked we are not going to need it.**Every other properties not mentioned here was left to its default configuration.**

Now go back to the main screen and click on the 3-dot menu located on the TOP RIGHT corner and press “Install”. This will take awhile so wait until is finished.

When you see the last line shown as <<<deploy your installation is complete and now you have successfully installed Linux on your android device congratulations!

On the BOTTOM LEFT corner press “START” to start running your Linux distribution from your android device and we are ready to start using SSH and there is nothing more to configure on the android device.

3. Connect with SSH to your android device

Open the terminal of your choice, this could be CMD if you are on windows, ConnectBot if you are using the same android device or any default terminal if you are on mac or any Linux distro. And type the following SSH command to start the secure connection:

ssh username@IPaddress

The username is the one you set in the previous configuration and the IP address is the same showed on the top of Linux-deploy. As an example the final command should look like something like this:

ssh android@192.168.2.1

If you are not using the default ssh port the command will be:

ssh username@IPaddress -p port

Where the port will be the port you chose in the previous configuration.

Your terminal may prompt if you want to add the hostkey to your files the first time, type yes and continue.

It will then ask for your password, type it then enter and you are now connected to your android device, every command you enter on your terminal now will be ran on the Linux distribution installed on your android device.

4. Update your sources list

By default the sources list installed should be:

deb http://ftp.debian.org/debian/ buster main contrib non-freedeb-src http://ftp.debian.org/debian/ buster main contrib non-free

I will be adding the security and updates channel to it, so on your terminal run the following command:

sudo nano /etc/apt/sources.list

replace the contents of the file with:

deb http://deb.debian.org/debian buster main contrib non-freedeb-src http://deb.debian.org/debian buster main contrib non-freedeb http://deb.debian.org/debian-security/ buster/updates main contrib non-freedeb-src http://deb.debian.org/debian-security/ buster/updates main contrib non-freedeb http://deb.debian.org/debian buster-updates main contrib non-freedeb-src http://deb.debian.org/debian buster-updates main contrib non-free

On your keyboard use ctrl + shift+ O to save the changes, it will ask you the filename you want to save, just press enter. Now to exit nano press ctrl + shift + X

Now let’s check if our Linux system is up to date, run the command:

sudo apt update

and then:

sudo service lighttpd restartsudo service pihole-FTL restartpihole restartdnssudo apt upgrade

Now we are ready to start installing pi-hole.

5. Installing pi-hole

Install curl with the command:

sudo apt install curl

Before running the installer login as root with the command:

su

And then run the pihole One-Step Automated Install

curl -sSL https://install.pi-hole.net | bash

When the pihole installer ask you about “Choose An Interface” pick wlan0

All the other configurations will be set to the default. You can just click “Ok” or continue and follow the steps until the end, this is a standard Pihole installation.

After the installation is complete I recommend you change the pihole admin page password with the command:

pihole -a p

Set whatever password you like.

Pihole is now installed and you can exit root mode with the command:

exit

Now pihole is installed and running, you can check that with

pihole status

6. Set your devices to use pihole

Now to start using pihole set your device use the pihole ip address(the same address you used to SSH) as the DNS server, I prefer to do this on my router so every device connected to my network will use it without having to set manually on each device.

This will be different depending on your router. I will set my router to use as a DNS server the IP address from my pihole and I will leave blank the second DNS server form in my router settings.

You should also configure in your router an static IP address to your pihole, so it will have the same address every time it connects to your network.

After that is done pihole should be running and you already using it, but there is a few clean ups we have to do.

7. Fix the admin web-page not loading

You can access your pihole admin page with the address

http://<IP_ADDPRESS_OF_YOUR_PI_HOLE>/admin/

or

http:/pi.hole/admin

(when using Pi-hole as your DNS server), if you followed this guide until now you will probably not be able to connect to this admin page, this is because our web-server doesn’t have the right permissions yet, we will change that with the following commands on the terminal with the SSH connection:

sudo usermod -a -G aid_net_bt_admin,aid_net_bt,aid_inet,aid_net_raw,aid_net_admin rootsudo usermod -a -G aid_net_bt_admin,aid_net_bt,aid_inet,aid_net_raw,aid_net_admin piholesudo usermod -a -G aid_net_bt_admin,aid_net_bt,aid_inet,aid_net_raw,aid_net_admin www-data

After that is done restart your services with the commands:

sudo service lighttpd restartsudo service pihole-FTL restartpihole restartdns

Your Admin Webpage should be working now.

Conclusion

That’s it, now you have successfully installed a Linux distribution and Pihole to your Android device, this is just the first step into a brand new world for you, Pihole is just one of many services that you can host yourself to improve your overall internet experience, privacy and security of your own home network.

If you would like to expand this topic even more you could try to implement your own VPN server with Wireguard, or maybe your own firewall with PfSense or even upgrade your device and start using a Raspberry Pi to do those things for you.

--

--