This guide turns a Raspberry Pi 4 into a Plex Media Server and a NAS for Windows. You use Raspberry Pi OS Lite (64-bit, Bookworm), an external USB hard drive, a static IP, the UFW firewall and Samba. You can copy all commands directly.
Steps: 1. System preparation, 2. Network and security, 3. External hard drive (NTFS, fstab), 4. Plex Media Server, 5. NAS with Samba, 6. Automatic updates and overclocking, 7. Access from Windows.
Use the official Raspberry Pi Imager to install the operating system onto your SD card.
| Setting | Value |
|---|---|
| Operating System | Raspberry Pi OS Lite (64-bit) |
| Hostname | your-hostname |
| SSH | Enabled |
| Username | your-username |
| Password | your-password |
Insert the SD card into the Pi, connect your hard drives and network cable, and plug in the power. Open a terminal on your computer and connect via SSH:
ssh your-username@your-hostname.local
Enter the password you set during the imaging process.
It is important to start with a fully updated system to ensure compatibility and security. Run these commands:
sudo apt update && sudo apt full-upgrade -y
sudo apt autoremove -y
sudo reboot
A static IP address keeps your server at the same place in your network. You need it for port forwarding and for stable NAS access.
Since Raspberry Pi OS Bookworm (late 2023), the network is managed by NetworkManager. The old file /etc/dhcpcd.conf no longer has any effect.
Alternative: many routers can always give the Pi the same address ("DHCP reservation"). If you set that up in your router, you can skip this step.
First, find the name of the wired connection (usually Wired connection 1):
nmcli -g NAME,DEVICE connection show
Set the static address. Replace the connection name if yours is different, and adjust the IP addresses to match your home router network:
sudo nmcli connection modify "Wired connection 1" ipv4.method manual ipv4.addresses 192.168.x.y/24 ipv4.gateway 192.168.x.1 ipv4.dns "192.168.x.1 8.8.8.8"
sudo nmcli connection up "Wired connection 1"
If the address changes, your SSH session disconnects. Reconnect with ssh your-username@192.168.x.y. Check the result with ip -4 addr show eth0.
On older systems (Bullseye and earlier), the static IP is still set in
/etc/dhcpcd.conf.
Next, install a firewall to block unauthorized network traffic. You need to open specific ports for SSH, Plex, and Samba to function properly.
| Service | Port and Protocol | Purpose |
|---|---|---|
| SSH | 22/tcp | Remote terminal access |
| Plex Media Server | 32400/tcp | Main web interface and streaming |
| Plex Companion | 3005/tcp, 8324/tcp, 32469/tcp | App control and DLNA |
| Plex Discovery | 5353/udp, 32410-32414/udp | Local network discovery |
| Samba (NAS) | 137/udp, 138/udp | NetBIOS name resolution |
| Samba (NAS) | 139/tcp, 445/tcp | Windows file sharing |
Install and configure the firewall:
sudo apt install ufw -y
sudo ufw allow 22/tcp
sudo ufw allow 32400/tcp
sudo ufw allow 3005/tcp
sudo ufw allow 8324/tcp
sudo ufw allow 32469/tcp
sudo ufw allow 5353/udp
sudo ufw allow 32410/udp
sudo ufw allow 32412/udp
sudo ufw allow 32414/udp
sudo ufw allow 32413/udp
sudo ufw allow 137/udp
sudo ufw allow 139/tcp
sudo ufw allow 138/udp
sudo ufw allow 445/tcp
Enable the firewall. Always make sure port 22 is allowed before enabling, otherwise you will lock yourself out of the SSH connection.
sudo ufw enable
If your external hard drive is formatted for Windows, you need to install NTFS drivers so the Linux system can read and write to it.
sudo apt install ntfs-3g -y
Create a mount directory. This is the folder where the contents of your hard drive will appear.
sudo mkdir /mnt/nas-drive
Find the unique identifier (UUID) of your hard drive. It will likely be listed as sda1 or sdb1.
sudo blkid
Configure the system to mount the drive automatically every time it boots. Open the file systems table:
sudo nano /etc/fstab
Add this line at the bottom, replacing YOUR-UUID-HERE with the actual ID you found in the previous step:
UUID=YOUR-UUID-HERE /mnt/nas-drive ntfs-3g defaults,permissions,auto 0 0
Test the mount configuration. If this command returns no errors, the setup is correct.
sudo mount -a
Add the official Plex software repository to your system so you can download and update the server software.
curl https://downloads.plex.tv/plex-keys/PlexSign.key | gpg --dearmor | sudo tee /usr/share/keyrings/plex-archive-keyring.gpg >/dev/null
echo deb [signed-by=/usr/share/keyrings/plex-archive-keyring.gpg] https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list
sudo apt update
sudo apt install plexmediaserver -y
Open a web browser on your computer and go to http://192.168.x.y:32400/web to finish the setup. When you add media libraries in Plex, choose the folders inside your mount point, for example /mnt/nas-drive/Movies.
To reach your Plex server from outside your home, enter port 32400 manually in the Plex web settings. Then log in to your home router and forward port 32400 to the static IP of your Raspberry Pi.
Install Samba, the software that allows Windows computers to access files over the network.
sudo apt install samba samba-common-bin -y
Create a dedicated user for NAS access. You will be asked to enter a new password for this user.
sudo adduser nasuser
sudo smbpasswd -a nasuser
Update the permissions on your hard drive so the new NAS user can read, write, and delete files. You also need to add the Plex system user to the NAS user group so Plex has permission to scan your media files.
sudo chown -R nasuser:nasuser /mnt/nas-drive
sudo chmod -R 775 /mnt/nas-drive
sudo usermod -a -G nasuser plex
Open the Samba configuration file:
sudo nano /etc/samba/smb.conf
Add this configuration block at the very end of the file:
[Share]
comment = Network Storage on Raspberry Pi
path = /mnt/nas-drive
writeable = Yes
create mask = 0775
directory mask = 0775
public = no
valid users = nasuser
Restart the Samba service to apply the new settings.
sudo systemctl restart smbd
You can create an automated task to update the system, clean up old packages, and reboot once a week.
sudo crontab -e
Add this line to perform the maintenance every Monday at 3:00 AM:
0 3 * * 1 apt update && apt upgrade -y && apt autoremove -y && /sbin/reboot
If you want more performance, you can overclock the Raspberry Pi. This strictly requires adequate cooling, such as a large heatsink or an active fan.
sudo nano /boot/firmware/config.txt
Add these settings at the bottom: #Note, this works on my Pi4, your results may vary
over_voltage=5
arm_freq=1800
gpu_freq=500
Save the file and reboot for the changes to take effect.
There are two ways to connect your Windows computer to the newly created network share.
| Method | Best For | Description |
|---|---|---|
| Quick Access | Temporary file transfers | Typing the address directly into the file explorer |
| Map Network Drive | Permanent use | Assigning a drive letter so it acts like a local hard drive |
For Quick Access: Open Windows Explorer. Click inside the address bar at the top, type \your-hostname.local and press Enter. A login window will appear. Enter nasuser as the username and the password you created. You will see the Share folder.
To Map a Network Drive: Open Windows Explorer. Right-click on This PC on the left sidebar and select Map network drive. Choose an available drive letter like Z. In the Folder box, type \your-hostname.local\Share and check the boxes for Reconnect at sign-in and Connect using different credentials. Click Finish, and enter the nasuser credentials when prompted.
Yes, for direct play and light use. It cannot transcode demanding video in real time, so use clients that play your files directly.
Raspberry Pi OS Lite (64-bit), as described in step 1. It has no desktop and uses fewer resources.
Install ntfs-3g, find the UUID with blkid, and add it to /etc/fstab (step 3). The drive then mounts automatically at boot.
Type \your-hostname.local in the Explorer address bar or map the share as a network drive (step 7).
The plex user must be allowed to read the drive. Step 5 adds it to the NAS user's group and sets the permissions.
Only forward port 32400 if you need remote access, keep the system updated and keep the firewall enabled.
This guide is released under the MIT License.
Keywords: Raspberry Pi 4 Plex server, Raspberry Pi NAS, Samba on Raspberry Pi, Plex Media Server tutorial, Raspberry Pi OS Lite 64-bit, NTFS external hard drive, UFW firewall, home media server, DIY NAS, Bookworm NetworkManager static IP.