APC Australia

Create a cheap, Pi-powered ad-blocker and file server

Les Pounder shows how to use the power of the new Raspberry Pi 3 B+ to create a file server and ad blocker in one compact device!

-

To celebrate the release of the new Raspberry Pi 3 B+, we’ll use it to create our own Samba server to store files and media for access across our home network. We’ll then use the same Pi to block ads and create a better browsing experience.

SAMBA FILE SERVER

First things first: Let’s make sure that we have the latest version of Raspbian. Download this from the Raspberry Pi website ( www.raspberryp­i.org) and then, using your favourite tool, flash the image to a blank micro SD card. When completed, eject the card and place it into your Pi, then connect your keyboard, mouse, screen, Ethernet and finally the power. Your Pi will boot up and, as this is the first boot, it’ll expand the filesystem to fully utilise the space on your SD card.

Soon, you’ll see the Raspbian desktop, so let’s update our Pi. Open a terminal; the icon is in the top left of the screen. In the terminal, type the following, line by line, and press Enter at the end of each line: $ sudo apt update $ sudo apt upgrade -y To ensure that we can always find the Pi on the network, let’s fix the IP address of our Pi. Right-click the networking icon and select ‘Wireless and Wired Network Settings’. In the Network Preference­s dialog, configure interface eth0. Tick ‘Automatica­lly configure empty options’ and then change the IPv4 Address to match that of your network. For example, our network uses 192.168.0.xxx so we chose to fix the IP address to 192.168.0.100. Click Apply and then Close. Now reboot the Pi to ensure that the IP address has been changed, and to check we can open a terminal and type. $ hostname -I With the terminal still open, let’s install the Samba package. Type the following and press Enter.

$ sudo apt install samba samba-common-bin

With everything installed, we now need to insert our USB storage device, which we shall use as our shared storage. Raspbian will automatica­lly mount the drive for us, but we need to know where it’s mounted. In the terminal, enter the following command: $ mount | grep /dev/sd Now, if there’s only one USB stick inserted we should see a device labelled /dev/sda1. This is our USB stick, so make a note of the device and where it’s mounted, typically in /media/pi/. Make a note of the full path to the drive. So we now have the device that’s our USB drive, and it has a directory that we wish to share using Samba. Let’s tell Samba where to find the drive. In the Terminal, type the following to edit the smb.conf file.

$ sudo nano /etc/samba/smb. conf

When the file loads, go to the bottom of the file and recreate the following lines: [share] Comment = Pi shared folder Path = /media/pi/<NAME OF DRIVE> Browseable = yes Writeable = Yes only guest = no create mask = 0777 directory mask = 0777 Public = yes Guest ok = yes

To save and exit the editor press ‘Ctrl-O’, then Enter, then ‘Ctrl-X’. Now let’s ensure that the default user, pi, is added as a Samba user. In the Terminal, type the following: $ sudo smbpasswd -a pi Next, to ensure that our Samba config is correct and ready to use, we need to tell Samba to restart, so in the Terminal, type:

$ sudo /etc/init.d/samba restart

With the installati­on complete, we now move to our Windows or Linux computer to test that we can find and use the Samba server.

On Ubuntu, we can use the file manager ( Nautilus) to connect via the Network shortcut. The name of our server RASPBERRYP­I should be visible. Click ‘share’ and when prompted enter the username “pi” and the password “raspberry” to access the server. The same process is similar for Windows 10 devices because the Network shortcut is also found in the File Manager applicatio­n.

Android users can also download Samba client apps from the app store and access the files just like their desktop counterpar­ts.

So now we have a single point where we can save our files and share them across the network — handy for large amount of media consumed by busy households!

SETTING UP PI HOLE

We all dislike adverts on web pages, but installing an ad blocker on every device is time-consuming. What if we created one device that filtered all of this for us? Pi-Hole is just that device. Running on our Raspberry Pi, Pi-Hole replaces our standard DNS server (normally our ISP unless we change it) with its own that filters out the ads. Oh, and it’s very easy to install, so let’s get started.

We need to open a Terminal and type the following command to download and run the install script:

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

Note that installati­on via this method carries a risk if being used with unknown sources. If in doubt, download the source code and examine it before use.

Pi-Hole installati­on is an automated process, and requires a minimum amount of input. But there’ll be times where we’re asked questions. One of these questions asks us to set up a static IP address — this is unnecessar­y because we already have a static IP created for the Samba server (if you haven’t set up a Samba server, then you can set the static IP address using Pi Hole, but make a note of the IP address.)

We’ll also be asked who our upstream DNS provider is. We can choose from a list: Google or OpenDNS are popular choices. Follow the rest of the installati­on steps and, when asked to install the web admin, select On. After a few minutes, installati­on will be complete and we’ll need to power down our Pi, remove all of the connection­s except for the Ethernet and power lead.

Power up the Pi and wait for it to boot — it takes around 30 seconds. On your Linux/Windows computer, go to your network settings. On Ubuntu, we can right-click the Network icon and select Edit Connection­s, click the interface that you wish to edit (Ethernet or Wi-Fi) and then click the Edit button. In the IPv4 Settings, change the DNS server to match the IP address of the Raspberry Pi. Click Save, then Close and then click the Network icon and then click Disconnect for the interface you have just configured.

Finally, reconnect to force the interface to connect using the Pi-Hole DNS server.

That’s it! We now have a transparen­t ad blocker on our network. It works across all devices, including Android where we can specify a static IP address and DNS server by a long press on the Wi-Fi AP name, select Modify Network, Advanced Options, and then entering the desired static IP and the DNS server (our Pi Hole device) address.

If you love stats, then Pi-Hole has them! If you open a browser to the IP address of the server, followed by ‘/admin’, you can see a dashboard interface that logs all of the queries blocked for your device. If you login using the password provided during the install, then you can see even more details.

So there we have it — two services using the power of the new Raspberry Pi 3 B+ — enhanced networking to keep our browser sessions free of ads, and our files saved in a convenient location.

 ??  ?? Our simple Samba server/ad blocker is powered via the new Pi3 B+, so we have a lean, energy efficient appliance for all of our home needs.
Our simple Samba server/ad blocker is powered via the new Pi3 B+, so we have a lean, energy efficient appliance for all of our home needs.
 ??  ?? Samba is cross platform, so Windows, Mac, Linux and mobile users can access one central location for their files.
Samba is cross platform, so Windows, Mac, Linux and mobile users can access one central location for their files.
 ??  ?? Once installed, Pi Hole offers a web interface that shows basic statistics, including how many adverts have been blocked.
Once installed, Pi Hole offers a web interface that shows basic statistics, including how many adverts have been blocked.

Newspapers in English

Newspapers from Australia