Skip to content

Package Cache On A Raspberry Pi

apt-cacher-ng on a Raspberry Pi behind a Squid allowlist: one door out for every isolated network, and the one apt setting that made it reliable.

Published November 21, 2026 · Updated December 2, 2026

The package cache used to be a container. CT 800, one core, one job.

It still has one job. It just moved out of the hypervisor.

When I split the lab into separate networks, several of them lost their internet on purpose. They still needed updates, so the lab got a small proxy that all of them go through. Once that proxy existed, keeping a second machine just to cache packages made no sense, so the cache moved in with it. Three Guests I Removed has the rest of that decision.

This page is how the board is put together, and how I check it.

Sheet 1 · Physical
Sheet 1 (physical) of the homelab drawing set: infra-proxy.
The proxy board, plugged straight into the router.

The Board

ItemValue
Hardwarea spare Raspberry Pi 4B
NetworkVLAN 40, where the small boards live
Address10.0.40.19
Squidport 3128, the allowlist
apt-cacher-ngport 3142, the package cache
Built byone Ansible role

One Door Out

Two services run on the board, and the way they are stacked is the whole design.

Squid is the only way out. It allows a short list of domains, by name, on ports 80 and 443, and it denies everything else.

apt-cacher-ng is the cache. It does not reach the internet by itself. It fetches through the Squid sitting next to it, so the same list covers the packages too. A mirror that is not on the list cannot be reached through the cache either.

Rendering Architecture Diagram...

The hosts that use it are the Proxmox nodes and the rest of VLAN 10 (OOBM), the compute VLAN, the other small boards, and the monitoring board. The storage VLAN gets Squid only.

The router backs this up. In the small boards' VLAN, only this board may reach the internet on ports 80 and 443. The others have no web access of their own, so they cannot quietly go around the proxy.

The Squid Config

This is the config the role writes, with my domain list and client networks taken out:

http_port 3128
 
# Public resolvers, not the Pi-holes
dns_nameservers <resolver> <resolver>
 
acl localnet src <one line per client network>
acl localnet src 127.0.0.1/32
acl update_domains dstdomain -n <the allowlist>
 
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 443
acl CONNECT method CONNECT
 
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet update_domains
http_access deny all
 
forwarded_for delete
via off

A few of those lines need explaining.

The -n on the allowlist matters. Without it, a request for a bare IP address makes Squid look up that address's name and try the list again. With -n there is no lookup, and the request is simply denied.1 So a domain on the list cannot be reached by typing its IP address instead.

127.0.0.1 is a client because apt-cacher-ng lives on the same board and fetches through Squid.

Squid resolves names with public resolvers, not with my Pi-holes. The Pi-holes are installed and updated through this proxy, so leaning on them here would be a loop: the proxy would need a Pi-hole before it could help build one.

The last two lines keep the client's details out of what Squid sends on to the internet. Without them Squid adds the client's address and its own name to each request.2

The role never swaps the live file blindly. It runs the new file through Squid's own check first, and a file that does not parse stops the run:

squid -k parse -f /path/to/new-squid.conf

The Cache Config

apt-cacher-ng needs very little. The role installs the Debian package and adds one small file, /etc/apt-cacher-ng/zz_homelab.conf:

Port: 3142
CacheDir: /var/cache/apt-cacher-ng
Proxy: http://127.0.0.1:3128

The last line is the one that matters. It sends every fetch through the local Squid.

The file name starts with zz_ on purpose. apt-cacher-ng reads every .conf file in that directory in alphabetical order and merges them,3 and this one has to sort after Debian's own zz_debconf.conf, so that my values win.

The board also patches itself. It runs unattended-upgrades and fetches its own updates directly. It is the one machine in that network that can.

Pointing A Host At It

Ansible writes one file, /etc/apt/apt.conf.d/00proxy, on every Debian machine in the lab, the Proxmox nodes included:

Acquire::http::Proxy "http://10.0.40.19:3142";
Acquire::https::Proxy "http://10.0.40.19:3128";
Acquire::http::Pipeline-Depth "0";

The first two lines send apt down two different paths.4

Plain http goes to apt-cacher-ng and gets cached. The first host to ask for a package pays for the download, and the rest get the local copy.

https goes to Squid and is passed straight through. An https download is encrypted end to end, so a cache in the middle has nothing it can keep. apt-cacher-ng's own manual says the same about tunnelled TLS.5

The proxy itself gets no file. Neither do the hosts in VLAN 20 (MGMT), which reach the internet directly: the two Tailscale routers and the reverse proxy.

Proxmox's own downloads, the container templates among them, do not read apt's file. They go through the datacenter http_proxy option, which points at Squid. How I Build A Node Now covers that side.

Checking It Works

From my Mac, the three ports first:

for p in 22 3128 3142; do nc -vz -w2 10.0.40.19 $p; done

Then from any client, without changing anything on it:

# The cache answers
apt -o Acquire::http::Proxy=http://10.0.40.19:3142 update
 
# A domain on the allowlist: Squid passes it on
curl -x http://10.0.40.19:3128 -I https://<an-allowed-domain>
 
# A domain that is not: Squid answers 403
curl -x http://10.0.40.19:3128 -I https://example.com

The cache also keeps its own statistics page, at http://10.0.40.19:3142/acng-report.html.

When something is refused and I do not know why, Squid's log on the board names it:

sudo grep TCP_DENIED /var/log/squid/access.log | tail

The Line That Made It Reliable

The third line of the apt file is there because of the monitoring board.

On 28 October 2026 the Rock 5B would not update. apt stopped with File has unexpected size (21602 != 889839). apt-cacher-ng had answered one request with the body of the file before it.

apt sends several requests down one connection without waiting for each answer. That is HTTP pipelining. Behind a mirror that redirects, apt-cacher-ng got the answers out of order.

The fix is one setting, and it is now on every host:

Acquire::http::Pipeline-Depth "0";

Zero turns pipelining off.6 One request at a time.

Mirrors That Redirect

The same day taught me a second thing. Armbian's package address does not serve packages itself. It redirects each request to a mirror, and not always the same one. I tested it twice from the proxy, an hour apart, and got two different mirrors.

An allowlist cannot keep up with that. Whichever mirror I allowed, the next request could be sent somewhere else.

So the board now points at one mirror directly, and that mirror is on the list.

What It Costs Me

If the board is down, the isolated networks wait for their updates. Nothing else in the lab can fetch a package for them.

Every new download source also means a change to the allowlist. That list is the only thing between a host and the internet, so I treat it as a change to review, not a quick edit. I run the role in check mode first, read the diff, and only then apply it.

It is the same job the container did. There is one less guest on the hypervisor, and one way out of the lab instead of many.

Footnotes

  1. Squid configuration directive acl: for dstdomain, "a reverse lookup is tried if a IP based URL is used and no match is found"; with -n, the ACL "would immediately declare a mismatch without any warnings or lookups". ↩

  2. Squid configuration directive forwarded_for: "If set to "delete", Squid will delete the entire X-Forwarded-For header." Squid configuration directive via: "If set (default), Squid will include a Via header in requests and replies". ↩

  3. Apt-Cacher NG manual, "Configuration file types": "apt-cacher-ng reads all files matching *.conf in alphabetical order and merges the contents." ↩

  4. apt-transport-http(1), "Proxy Configuration": proxies for APT are set with Acquire::http::Proxy. apt-transport-https(1): the http options are also available under Acquire::https. ↩

  5. Apt-Cacher NG manual, "Access to SSL/TLS remotes (HTTPS)": with tunnelling, "the proxy has no control of the data flowing through it so the proxy cannot cache the data in any useful way". ↩

  6. apt-transport-http(1), "Connection Configuration": Acquire::http::Pipeline-Depth enables HTTP pipelining, with a default of 10, and setting it to 0 disables it. ↩

Comments

Sign in with GitHub to leave a comment or reaction.