My Own Apple Music, Served From the Closet
Most of the time, running your own Linux servers and home network is a hobby with a terribly low return on investment. You spend an evening figuring out why a container sits in disk-wait seemingly forever, and the reward is that it now starts, which is what it was supposed to do in the first place.
But every now and then, at long and irregular intervals, it all pays off at once.
Today I walked out of my front door, and the music on my iPhone kept playing. Not from Spotify, Apple, Qobuz, Tidal or any other subscription service. It kept playing from a server in my own home, even as the phone switched from Wi-Fi to cellular data.
What I actually built
In one sentence: my own little music streaming service, reachable from anywhere, yet not exposed to the internet at all.
The pieces, from the bottom up:
- A NAS. An ordinary PC running TrueNAS Community Edition, with a ZFS pool for the data. Music, films, documents.
- Navidrome, an open source music server, running as a container on the NAS. It speaks the Subsonic API, which means a whole ecosystem of client apps can talk to it.
- Amperfy, an open source iOS app that speaks Subsonic. It streams, it caches albums for offline playback, and it works with CarPlay.
- WireGuard, running on my router (a UniFi Dream Machine Pro), so the phone can reach the NAS when it is not at home.
None of these is exotic. The fun part is how they fit together.
Real certificates for names nobody can see
Every single service on my NAS has a proper HTTPS address under a
subdomain I use only at home, something like music.home.example.com.
The names exist only in the router’s local DNS. Ask any public DNS
server for them and you get nothing.
That raises a question: how do you get a Let’s Encrypt certificate for a name the internet cannot see? Let’s Encrypt normally proves that you control a domain by calling your web server from the outside, and there is no “outside” here.
The answer is the DNS-01 challenge. Instead of answering an HTTP request, you prove control by publishing a temporary TXT record in the domain’s public DNS zone. My zone is hosted at Cloudflare, so the reverse proxy (Nginx Proxy Manager) gets an API token that is only allowed to edit DNS records in that one zone, and does the ritualistic renewal dance automatically every couple of months.
It requests a single wildcard certificate, *.home.example.com,
instead of one certificate per service. That matters more than you
might think: every certificate Let’s Encrypt issues is recorded in
public Certificate Transparency logs. Individual certificates would
announce the name of every service I run to the world. A wildcard
announces only that the subdomain exists.
So: valid certificates, a padlock in every browser, and no names leaked. Overkill for self-hosted private services? I think not.
Getting in from the outside
No ports are open to the NAS. The only thing listening on the router’s public address is WireGuard, on a single UDP port, and WireGuard does not even answer unless the packet is signed with a key it already knows. To a port scanner, it looks like nothing is there.
My home connection gets a dynamic IP address from the ISP, so the router also keeps a DNS name updated (dynamic DNS through the same Cloudflare zone). The phone connects to that name, not to an IP address that might change overnight.
Each device is a separate WireGuard peer with its own key pair. The keys were generated on my laptop, and the router was only ever given the public half. If the phone gets lost, I remove that one peer from the router and nothing else is affected.
Split tunnel: only what is going home goes home
A classic VPN sends all your traffic through the tunnel. That is what you want on a dodgy hotel Wi-Fi, but not when the goal is just to reach a music server: every web page and every app update would take a detour through my home connection before reaching the internet.
WireGuard decides what goes into the tunnel with a setting called
AllowedIPs. Mine contains only the home network and the VPN’s own
small subnet:
[Peer]
AllowedIPs = 192.168.0.0/24, 192.168.11.0/24
PersistentKeepalive = 25
Everything else goes straight out to the internet as usual. The tunnel also tells the phone to use the router as its DNS server, so the home-only names resolve to the NAS, through the tunnel.
On the laptop I went one step further and used split DNS: only queries
for my own domain go to the router, everything else goes to whatever
resolver the local network offers. It is wrapped in three small shell
commands, myvpn-up, myvpn-down and myvpn-status.
On-Demand: the part that feels like magic
The WireGuard app for iOS has a feature called On-Demand. You give it rules, and iOS brings the tunnel up and down by itself. Mine are simple:
- on cellular data: tunnel on
- on Wi-Fi: tunnel on, except on my home network
At home, the phone talks to the NAS directly. When I walk out of the door and the phone drops the home Wi-Fi, the tunnel comes up on its own. The music player on my phone does not notice anything. The address is the same, the certificate is the same, and the music just continues.
That is the kind of moment we all wish we had more often: technology that just works.
I was standing on the street, headphones on, listening to music from a closet at home, without having to do anything at all to make it work.
Was it worth it?
In money or time spent, probably not yet. In understanding, absolutely. I now know exactly where my music lives, who can reach it (me), and what happens when the IP address changes (nothing).
And for once, the technology simply worked, the way it is supposed to. Sometimes being a network amateur, with some help from an LLM and the experience of a lifelong Linux nerd, pays dividends.