This Document is actively being developed as a part of ongoing Raspberry Pi OS learning efforts. Chapters will be added periodically.
This is the multi-page printable view of this section. Click here to print.
Raspberry Pi OS How-to Documents
1 - How to Create a NAS Server with a Raspberry Pi 4
In today’s digital world, the need for centralized storage solutions is growing. Whether you want to store media files, backups, or documents, a Network Attached Storage (NAS) server offers a convenient way to access files across devices on a local network or even remotely. While commercial NAS devices are available, they can be expensive. Fortunately, with a Raspberry Pi 4, you can build your own budget-friendly NAS server.
In this detailed guide, we’ll walk you through the process of setting up a NAS server using a Raspberry Pi 4. By the end, you’ll have a fully functional NAS that can be accessed from various devices in your home or office.
What is a NAS Server?
A Network Attached Storage (NAS) server is a specialized device connected to a network, providing centralized data storage and file sharing across devices. With a NAS, multiple users can access and share data seamlessly over the network. NAS servers are commonly used for:
Media streaming (movies, music, photos)
Backup storage for computers and mobile devices
File sharing within a home or office network
Remote access to files from anywhere in the world Creating a NAS server with a Raspberry Pi 4 is cost-effective, energy-efficient, and customizable, making it ideal for personal use or small-scale business environments.
Why Raspberry Pi 4?
The Raspberry Pi 4 is an excellent candidate for a NAS server due to its improved hardware compared to earlier models. Key features include:
Quad-core 64-bit processor: Provides better performance for handling network traffic and file management.
Up to 8GB RAM: Ample memory for managing multiple users and file operations.
Gigabit Ethernet port: Enables fast and stable file transfer across your local network.
USB 3.0 ports: Essential for connecting external storage devices such as hard drives or SSDs, providing high-speed data access. The Raspberry Pi 4 also runs on low power, which is ideal for a NAS server that might need to stay online 24/7.
What You Will Need
Before starting, make sure you have the following components ready:
Raspberry Pi 4 (4GB or 8GB model recommended for better performance)
MicroSD card (16GB or more) for the Raspberry Pi’s operating system
External USB hard drive or SSD (to store your files)
USB 3.0 powered hub (optional but recommended if using multiple hard drives)
Raspberry Pi 4 power supply (official or high-quality third-party)
Ethernet cable to connect the Pi to your router
Keyboard, mouse, and monitor for initial setup (optional if using headless configuration)
Raspberry Pi OS (Debian-based, previously known as Raspbian) Now, let’s proceed with the step-by-step process to create your NAS server.
Step 1: Set Up Raspberry Pi 4
1.1 Install Raspberry Pi OS
Download the latest Raspberry Pi OS from the official Raspberry Pi website.
Use software like Raspberry Pi Imager or Balena Etcher to write the OS image to your MicroSD card.
Insert the MicroSD card into your Raspberry Pi 4 and power it on. If using a keyboard, mouse, and monitor, proceed with the standard installation. If setting up headless (without peripherals), you can enable SSH access before inserting the SD card by creating an empty file named
ssh
in the boot partition of the SD card.
1.2 Update and Upgrade
Once Raspberry Pi OS is installed and running, it’s important to update your system. Open a terminal window and enter the following commands:
sudo apt update
sudo apt upgrade
This ensures that you have the latest software updates and security patches.
Step 2: Install and Configure Samba for File Sharing
We will use Samba to enable file sharing across different devices. Samba is a popular software suite that allows file and print sharing between Linux and Windows devices.
2.1 Install Samba
To install Samba, run the following command:
sudo apt install samba samba-common-bin
2.2 Create a Directory for File Storage
Create a folder where you will store your shared files. For example, let’s create a folder named shared
in the /home/pi
directory:
mkdir /home/pi/shared
2.3 Configure Samba
Next, we need to edit Samba’s configuration file to specify the settings for file sharing. Open the configuration file using a text editor:
sudo nano /etc/samba/smb.conf
Scroll to the bottom of the file and add the following configuration:
[Shared]
comment = Shared Folder
path = /home/pi/shared
browseable = yes
writeable = yes
only guest = no
create mask = 0777
directory mask = 0777
public = no
This configuration will create a shared folder that’s accessible over the network. The permissions allow read and write access to the folder.
2.4 Create Samba User
To secure your NAS server, create a Samba user who can access the shared files. Use the following command to add a user (replace pi
with your username if necessary):
sudo smbpasswd -a pi
You’ll be prompted to set a password for the user. Once done, restart the Samba service to apply the changes:
sudo systemctl restart smbd
Step 3: Mount External Hard Drive
A NAS server typically relies on an external hard drive to store files. Let’s mount your external drive to the Raspberry Pi 4.
3.1 Identify the External Drive
First, plug your external hard drive into one of the USB 3.0 ports on the Raspberry Pi 4. To find the drive’s name, run:
sudo fdisk -l
Look for your external hard drive in the list (it’s typically named /dev/sda1
or similar).
3.2 Mount the Drive
Create a mount point for the drive:
sudo mkdir /mnt/external
Mount the drive to this directory:
sudo mount /dev/sda1 /mnt/external
To make the mount permanent (i.e., mounted automatically at boot), you need to add the drive to the /etc/fstab
file. Open the file:
sudo nano /etc/fstab
Add the following line at the bottom:
/dev/sda1 /mnt/external auto defaults 0 0
Save and exit. Now, your external drive will be mounted automatically on startup.
Step 4: Configure Access to NAS from Other Devices
4.1 Access NAS from Windows
On a Windows computer, open File Explorer and type the Raspberry Pi’s IP address in the address bar, like so:
\\192.168.X.XXX
You will be prompted to enter your Samba username and password. After authentication, you’ll have access to the shared folder.
4.2 Access NAS from macOS
On a macOS device, open Finder, press Cmd + K
, and enter the Raspberry Pi’s IP address like this:
smb://192.168.X.XXX
You’ll be asked for the Samba credentials, and once authenticated, the shared folder will be accessible.
Step 5: Optional - Set Up Remote Access
If you want to access your NAS server remotely, outside your home or office network, you can set up remote access via OpenVPN or WireGuard. Additionally, dynamic DNS (DDNS) can help you manage your NAS server’s IP address if it changes periodically.
Step 6: Optimize Your NAS Setup
While the basic setup is complete, there are several optimizations and improvements you can make:
Add more storage: Connect additional external drives to expand your storage capacity. You can even set up a RAID configuration for redundancy.
Automatic backups: Use software like rsync to automate backups to your NAS.
Media streaming: Install media server software like Plex or Emby on your Raspberry Pi for streaming videos and music to your devices. Conclusion
Building a NAS server with a Raspberry Pi 4 is a cost-effective and powerful way to create a personal cloud for storing and sharing files across your home or office network. With Samba, you can easily access files from Windows, macOS, or Linux devices, making it a flexible solution for your storage needs.
By following this guide, you’ll have a fully functional NAS server that can be further customized with additional storage, automated backups, or media streaming capabilities. Whether for personal use or a small business, a Raspberry Pi 4 NAS server offers performance, scalability, and convenience at an affordable price.
2 - How to Install Zabbix 7.0 on Raspberry Pi 4 OS 12 Bookworm
If you’re looking to monitor networks, servers, or IoT devices at home or in a small office, Zabbix 7.0 LTS on a Raspberry Pi 4 can be an efficient and affordable solution. This guide provides a step-by-step approach to installing Zabbix 7.0 LTS on Raspberry Pi 4 running OS 12 Bookworm.
With its long-term support (LTS), Zabbix 7.0 is a reliable monitoring platform that works well with the latest Raspberry Pi OS. Let’s dive in and set up this powerful monitoring tool!
Prerequisites
Before we start, make sure you have the following:
- Raspberry Pi 4 with at least 4GB of RAM (the 8GB version is preferable for optimal performance).
- Raspberry Pi OS 12 Bookworm (the latest OS version).
- Internet connection to download Zabbix packages.
- Static IP address assigned to your Raspberry Pi to maintain a stable monitoring environment.
Step 1: Set Up Raspberry Pi OS 12 Bookworm
If you haven’t already set up your Raspberry Pi with OS 12 Bookworm, start by installing the latest OS version.
- Download Raspberry Pi Imager from the official Raspberry Pi website.
- Insert your microSD card into your computer, and use the Imager tool to flash Raspberry Pi OS 12 Bookworm onto the card.
- Boot your Raspberry Pi with the new OS, and complete the initial setup process, ensuring it’s connected to the internet.
For remote management, you can enable SSH by navigating to Settings > Interfaces and turning on SSH.
Step 2: Update System Packages
Before installing Zabbix, it’s essential to update the system packages.
sudo apt update && sudo apt upgrade -y
This command will update all the installed packages to their latest versions, ensuring the system is ready for Zabbix.
Step 3: Install and Configure the LAMP Stack
Zabbix requires a LAMP stack (Linux, Apache, MySQL, PHP) to function. Let’s install each component one by one.
1. Install Apache
Apache is the web server that Zabbix will use to display its monitoring interface.
sudo apt install apache2 -y
Once installed, start and enable Apache:
sudo systemctl start apache2
sudo systemctl enable apache2
Verify Apache is running by visiting the IP address of your Raspberry Pi in a browser. You should see the default Apache welcome page.
2. Install MySQL (MariaDB)
Zabbix uses a database to store monitoring data. MariaDB is an open-source alternative to MySQL and works well on Raspberry Pi.
sudo apt install mariadb-server mariadb-client -y
Secure your MariaDB installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and remove unnecessary users.
3. Create the Zabbix Database and User
Log in to MySQL and set up a database for Zabbix:
sudo mysql -u root -p
Run the following commands inside the MySQL prompt:
CREATE DATABASE zabbixdb CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
CREATE USER 'zabbixuser'@'localhost' IDENTIFIED BY 'strongpassword';
GRANT ALL PRIVILEGES ON zabbixdb.* TO 'zabbixuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace strongpassword
with a secure password. This creates a database (zabbixdb
) and a user (zabbixuser
) for Zabbix.
4. Install PHP and Required Modules
Zabbix needs specific PHP modules to work correctly. Install these using the following command:
sudo apt install php php-mysql php-xml php-bcmath php-mbstring php-gd php-ldap php-zip php-xmlreader -y
Adjust PHP settings in the configuration file:
sudo nano /etc/php/8.2/apache2/php.ini
Find and set the following parameters:
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
date.timezone = "YOUR_TIMEZONE"
Replace YOUR_TIMEZONE
with your actual time zone, e.g., America/New_York
. Save and close the file.
Step 4: Install Zabbix 7.0 LTS
- Download the Zabbix repository package:
wget https://repo.zabbix.com/zabbix/7.0/debian/pool/main/z/zabbix-release/zabbix-release_7.0-1+bookworm_all.deb
- Install the downloaded package:
sudo dpkg -i zabbix-release_7.0-1+bookworm_all.deb
sudo apt update
- Now, install the Zabbix server, frontend, and agent:
sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent -y
Step 5: Configure Zabbix Database Connection
- Import the initial schema and data into the Zabbix database:
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -u zabbixuser -p zabbixdb
- Configure Zabbix to connect to the database. Open the Zabbix server configuration file:
sudo nano /etc/zabbix/zabbix_server.conf
- Find and set the following parameters:
DBName=zabbixdb
DBUser=zabbixuser
DBPassword=strongpassword
Replace strongpassword
with the password you set earlier.
Step 6: Start and Enable Zabbix Services
- Start the Zabbix server and agent:
sudo systemctl start zabbix-server zabbix-agent apache2
- Enable the services to start automatically on boot:
sudo systemctl enable zabbix-server zabbix-agent apache2
Verify the services are running:
sudo systemctl status zabbix-server zabbix-agent apache2
Step 7: Complete Zabbix Frontend Setup
- Open a web browser and navigate to
http://<Raspberry_Pi_IP>/zabbix
. - Follow the setup wizard to complete the configuration.
- Step 1: Welcome screen, click Next.
- Step 2: Ensure all prerequisites are met.
- Step 3: Database configuration. Enter the database name, user, and password.
- Step 4: Zabbix server details. Default values are typically sufficient.
- Step 5: Confirm configuration.
- After the setup, log in to the Zabbix front end using the default credentials:
- Username:
Admin
- Password:
zabbix
Step 8: Configure Zabbix Agent
The Zabbix agent collects data from the Raspberry Pi. Modify its configuration to monitor the server itself:
sudo nano /etc/zabbix/zabbix_agentd.conf
Find and adjust the following:
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=RaspberryPi4
Save and close the file, then restart the Zabbix agent:
sudo systemctl restart Zabbix-agent
Step 9: Testing and Monitoring
- add the Raspberry Pi as a host from the Zabbix dashboard.
- Configure triggers, graphs, and alerts to monitor CPU, memory, disk usage, and other metrics.
With Zabbix 7.0 LTS successfully installed on Raspberry Pi OS 12 Bookworm, you can monitor your network and devices with a lightweight, efficient setup!
FAQs
- Can Zabbix run efficiently on Raspberry Pi 4?
- Yes, especially with 4GB or 8GB RAM. For small networks, Zabbix is very effective on Raspberry Pi.
- Do I need a static IP for Zabbix?
- While not mandatory, a static IP makes it easier to access your Zabbix server consistently.
- What if I encounter PHP errors during setup?
- Ensure PHP modules are correctly installed and PHP settings are optimized in
php.ini
.
- How secure is Zabbix on a Raspberry Pi?
- Basic security involves securing the MySQL instance and ensuring the server is behind a firewall. For internet exposure, consider adding SSL.
- Can I use Zabbix to monitor IoT devices?
- Zabbix is highly compatible with IoT monitoring and can track metrics via SNMP or custom scripts.
3 - How to Install BIND9 DNS Server on Raspberry Pi OS
Raspberry Pi is a versatile, cost-effective device widely used for various projects, from home automation to learning new technologies. One such project involves setting up a Domain Name System (DNS) server. A DNS server translates domain names (e.g., example.com
) into IP addresses, enabling easier and more user-friendly web navigation. By running your own DNS server on Raspberry Pi OS, you can manage your network more efficiently, enhance privacy, and improve performance by caching frequent DNS queries.
This guide walks you through installing and configuring a DNS server on Raspberry Pi OS Debian 12 Bookworm using BIND9, one of the most popular and reliable DNS server software packages.
Prerequisites
Before diving into the installation process, ensure you have the following:
- A Raspberry Pi running Raspberry Pi OS Debian 12 Bookworm.
- A stable internet connection.
- Access to the terminal with
sudo
privileges. - Basic understanding of Linux commands.
Step 1: Update and Upgrade Your System
To start, ensure your Raspberry Pi OS is up-to-date. Open a terminal and run:
sudo apt update && sudo apt upgrade -y
This command updates the package lists and installs the latest versions of the available software. Keeping your system updated ensures compatibility and security.
Step 2: Install BIND9 DNS Server
The BIND9 package is readily available in the Debian repository. Install it using:
sudo apt install bind9 -y
Once the installation is complete, verify that the BIND9 service is running:
sudo systemctl status bind9
You should see the service status as active (running)
.
Step 3: Configure the BIND9 Server
The configuration of BIND9 involves editing a few files to define how the server will function. Here are the essential steps:
3.1 Edit the Main Configuration File
The primary configuration file for BIND9 is located at /etc/bind/named.conf.options
. Open it using a text editor like nano
:
sudo nano /etc/bind/named.conf.options
Uncomment and modify the following lines to set up a basic caching DNS server:
options {
directory "/var/cache/bind";
recursion yes; // Enables recursive queries
allow-query { any; }; // Allow queries from any IP address
forwarders {
8.8.8.8; // Google DNS
8.8.4.4;
};
dnssec-validation auto;
listen-on-v6 { any; }; // Allow IPv6 connections
};
Save the file by pressing CTRL+O
, followed by Enter
, and then CTRL+X
to exit.
3.2 Configure a Local Zone (Optional)
If you want to create a custom DNS zone for internal use, edit the /etc/bind/named.conf.local
file:
sudo nano /etc/bind/named.conf.local
Add the following lines to define a zone:
zone "example.local" {
type master;
file "/etc/bind/db.example.local";
};
Next, create the zone file:
sudo cp /etc/bind/db.local /etc/bind/db.example.local
sudo nano /etc/bind/db.example.local
Update the placeholder content with your local DNS entries. For example:
$TTL 604800
@ IN SOA example.local. admin.example.local. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS example.local.
@ IN A 192.168.1.100 ; IP of the Raspberry Pi
www IN A 192.168.1.101 ; Example local web server
Save and close the file. Then, check the configuration for errors:
sudo named-checkconf
sudo named-checkzone example.local /etc/bind/db.example.local
If no errors are reported, the configuration is correct.
Step 4: Adjust Firewall Settings
To ensure your DNS server is accessible, allow DNS traffic through the firewall. Use ufw
(Uncomplicated Firewall) to manage rules:
sudo ufw allow 53/tcp
sudo ufw allow 53/udp
sudo ufw reload
If ufw
is not installed, you can add rules using iptables
or another preferred firewall management tool.
Step 5: Restart and Enable the DNS Server
Restart the BIND9 service to apply the changes:
sudo systemctl restart bind9
Enable it to start automatically on boot:
sudo systemctl enable bind9
Step 6: Test the DNS Server
To confirm your DNS server is functioning correctly, use the dig
command (part of the dnsutils
package). First, install the package if it’s not already present:
sudo apt install dnsutils -y
Then, query your DNS server:
dig @localhost example.local
The output should include an ANSWER SECTION with the IP address you configured in the zone file.
Step 7: Configure Clients to Use the DNS Server
Finally, set up devices on your network to use the Raspberry Pi DNS server. On most operating systems, you can specify the DNS server in the network settings:
- Use the Raspberry Pi’s IP address (e.g.,
192.168.1.100
) as the primary DNS server. - Test the setup by visiting websites or resolving local domains.
Troubleshooting Tips
Check Service Logs: If the DNS server doesn’t work as expected, review logs using:
sudo journalctl -u bind9
Verify Port Availability: Ensure no other service is using port 53:
sudo netstat -tuln | grep :53
Restart Services: If you make configuration changes, restart BIND9 to apply them:
sudo systemctl restart bind9
Correct File Permissions: Ensure zone files have the correct permissions:
sudo chown bind:bind /etc/bind/db.example.local
Conclusion
Setting up a DNS server on Raspberry Pi OS Debian 12 Bookworm using BIND9 is a rewarding project that enhances your network’s functionality and performance. By following this guide, you’ve created a versatile DNS server capable of caching queries, hosting local zones, and supporting both IPv4 and IPv6.
This setup can serve as a foundation for further customization, such as integrating DNS-over-HTTPS (DoH) for enhanced privacy or creating more complex zone configurations. With your Raspberry Pi-powered DNS server, you have full control over your network’s DNS traffic.
4 - How to Install dnsmasq DNS Server on Raspberry Pi OS
Setting up a Domain Name System (DNS) server on your Raspberry Pi running Raspberry Pi OS Debian 12 Bookworm can significantly enhance your network’s efficiency by reducing lookup times and improving overall connectivity. This comprehensive guide will walk you through the process of installing and configuring dnsmasq
, a lightweight DNS forwarder ideal for small-scale networks.
Prequisites
Before we begin, ensure you have the following:
- Raspberry Pi: Model 2, 3, or 4.
- Operating System: Raspberry Pi OS Debian 12 Bookworm.
- Network Connection: A stable internet connection via Ethernet or Wi-Fi.
- Static IP Address: It’s recommended to assign a static IP to your Raspberry Pi to ensure consistent network identification.
Step 1: Update Your System
Start by updating your package lists and upgrading existing packages to their latest versions. Open a terminal and execute:
sudo apt update
sudo apt upgrade -y
This ensures that your system has the latest security patches and software updates.
Step 2: Install dnsmasq
dnsmasq
is a lightweight DNS forwarder and DHCP server designed for small networks. Install it using:
sudo apt install dnsmasq -y
Step 3: Configure dnsmasq
After installation, you’ll need to configure dnsmasq
to function as your DNS server. Follow these steps:
Backup the Original Configuration: It’s good practice to keep a backup of the original configuration file.
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
Edit the Configuration File: Open the
dnsmasq
configuration file in a text editor:sudo nano /etc/dnsmasq.conf
Modify the Following Settings:
Prevent Forwarding of Plain Names: Uncomment the
domain-needed
line to avoid forwarding incomplete domain names.domain-needed
Block Private IP Reverse Lookups: Uncomment the
bogus-priv
line to block reverse lookups for private IP ranges.bogus-priv
Specify Upstream DNS Servers: Add your preferred upstream DNS servers. For example, to use Google’s DNS servers:
server=8.8.8.8 server=8.8.4.4
Set Cache Size: Increase the cache size to improve performance.
cache-size=1000
Save and Exit: After making the changes, save the file by pressing
CTRL + X
, thenY
, and pressEnter
.
Step 4: Restart and Enable dnsmasq
To apply the changes, restart the dnsmasq
service:
sudo systemctl restart dnsmasq
Enable dnsmasq
to start on boot:
sudo systemctl enable dnsmasq
Step 5: Configure Network Manager for a Static IP
With the release of Raspberry Pi OS Bookworm, networking is managed by NetworkManager. To assign a static IP address:
List Network Interfaces: Identify your network connection name.
nmcli connection show
Look for the interface, typically named
Wired connection 1
for Ethernet or your Wi-Fi SSID.Set Static IP Address: Replace
CONNECTION_NAME
with your actual connection name.sudo nmcli connection modify "CONNECTION_NAME" ipv4.addresses 192.168.1.100/24 ipv4.method manual
Set Gateway and DNS: Assuming your router’s IP is
192.168.1.1
:sudo nmcli connection modify "CONNECTION_NAME" ipv4.gateway 192.168.1.1 sudo nmcli connection modify "CONNECTION_NAME" ipv4.dns "192.168.1.1,8.8.8.8"
Apply Changes: Bring the connection down and up to apply changes.
sudo nmcli connection down "CONNECTION_NAME" && sudo nmcli connection up "CONNECTION_NAME"
Step 6: Test the DNS Server
To verify that your Raspberry Pi is correctly resolving DNS queries:
Install
dnsutils
: If not already installed, to use thedig
command.sudo apt install dnsutils -y
Perform a Test Query: Use the
dig
command to test DNS resolution.dig example.com @localhost
Check the output for a valid response and note the query time. Subsequent queries should be faster due to caching.
Step 7: Configure Client Devices
To utilize your Raspberry Pi as the DNS server, configure other devices on your network to use its static IP address as their primary DNS server. This setting is typically found in the network configuration section of each device.
Conclusion
By following this guide, you’ve successfully transformed your Raspberry Pi running Debian 12 Bookworm into a lightweight and efficient DNS server using dnsmasq
. This setup allows your network to benefit from faster domain lookups, a reduced dependency on external DNS servers, and improved overall network performance.
Key benefits of this configuration include:
- Local Caching: Frequently accessed domains are cached, speeding up subsequent requests.
- Customizability: You can add custom DNS records or override specific domain names for your local network.
- Reduced Bandwidth: Cached responses reduce the need for repeated queries to external DNS servers.
To further enhance your setup, consider the following:
- Monitoring Logs: Check
/var/log/syslog
fordnsmasq
logs to monitor DNS queries and ensure everything is running smoothly. - Security Enhancements: Implement firewall rules using
ufw
oriptables
to restrict access to the DNS server to devices within your local network. - Advanced DNS Features: Explore additional
dnsmasq
options, such as DHCP integration or filtering specific domains.
With this DNS server in place, your Raspberry Pi not only becomes a central hub for managing network queries but also a powerful tool for improving your network’s efficiency. Whether for personal use or small-scale enterprise projects, this setup ensures a robust and reliable DNS service. Happy networking!