AKGuidebooks Home Server Admin

Part 5: AI

22. Block the AI from the internet#

What you'll do: add a firewall rule that stops anything running as the ai account from sending data out, except to the server itself. Time: 10 minutes.

The service file in Chapter 21 already limits the engine. This guard is a second lock that covers the whole ai account, so it still holds if the service file is changed by mistake.

flowchart LR
  A["Anything running<br/>as 'ai'"] -- "to 127.0.0.1" --> OK["Allowed"]
  A -. "to the internet<br/>or your network" .-x NO["Dropped and counted"]
  U["Everything else on the server<br/>(updates, Tailscale, you)"] --> NET(("Internet"))

Step 1: Write the rule#

Type on: the server
sudo nano /etc/ai-runtime/aiguard.nft
File: /etc/ai-runtime/aiguard.nft
table inet aiguard
delete table inet aiguard

table inet aiguard {
  chain output {
    type filter hook output priority 0; policy accept;
    meta skuid "ai" oifname "lo" accept
    meta skuid "ai" counter drop
  }
}

In plain words: if the sender is ai and the traffic stays on this computer (lo), allow it. If the sender is ai and it goes anywhere else, drop it and count it. Nobody else is affected.

(The first two lines let you reload the file safely: they remove the old version before adding the new one.)

Step 2: Load it at every boot#

Type on: the server
sudo nano /etc/systemd/system/ai-egress-guard.service
File: /etc/systemd/system/ai-egress-guard.service
[Unit]
Description=Keep the ai account off the network
Before=llama-model.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/nft -f /etc/ai-runtime/aiguard.nft
ExecStop=/usr/sbin/nft delete table inet aiguard

[Install]
WantedBy=multi-user.target
Type on: the server
sudo systemctl daemon-reload
sudo systemctl enable --now ai-egress-guard
systemctl is-active ai-egress-guard

It should say active.

Step 3: Test it#

Try to reach the internet as ai. It must fail:

Type on: the server
sudo -u ai curl -sS --max-time 5 https://deb.debian.org

Expected: an error (timeout, or "couldn't connect"). Now the same thing as you, which must work:

Type on: the server
curl -sS --max-time 5 -o /dev/null -w '%{http_code}\n' https://deb.debian.org

Expected: 200. And the model still answers:

Type on: the server
curl -s http://127.0.0.1:8095/health

See how many attempts have been blocked:

Type on: the server
sudo nft list table inet aiguard

The counter packets number goes up each time something running as ai tries to get out.

Done when: ai can't reach the internet, you still can, and the model still says ok.

Next: 23. Chat with the model from your Mac or PC

Made by Anish · 2026