All six DNS walkthroughs start with the same application route. This foundation selects the newsgroup reader’s account, marks its packets and directs them into an existing VPN. The independent account guards remain in place if classification or routing fails.
Open the Walkthrough Shell
From your ordinary administrator account, open a root login shell first:
sudo -i
Use Bash in that root shell for the remaining setup, checks, and withdrawal. Do not nest another root shell when following a shared section. Confirm root access and retain the original account for comparison tests:
set -euo pipefail
test "$(id -u)" -eq 0
ORDINARY_USER="${SUDO_USER:-}"
test -n "$ORDINARY_USER"
test "$ORDINARY_USER" != root
test "$ORDINARY_USER" != newsvpn
test "$(id -u "$ORDINARY_USER")" -ne 0
id "$ORDINARY_USER"
Stop if the account is not your intended ordinary user. Administrative commands now run without repeated sudo. runuser -u ... -- deliberately runs a test under the named account; testing as root would not exercise the reader’s UID guard. When following a linked foundation check, keep its ordinary-user tests under ORDINARY_USER too; a root request is not the ordinary-account comparison. The examples require runuser as well as the tools listed below. Root login shells, account-specific commands
1. Define What We Are Selecting
Use a Usenet reader running under a dedicated, unprivileged Linux account named newsvpn. All IPv4 network connections owned by that account must use the VPN. Other accounts retain their normal routing. The account must not run the VPN client or unrelated services. A temporary browser comparison, described in the chosen DNS walkthrough, must use the selected application route; do not turn this account into your ordinary desktop account.
Give the reader account its own configuration and only the file permissions it needs, including access to its download location. It should have no administrative privileges. Continue administering the host through your normal account; running the reader under a separate identity does not require a second desktop login. Resolve and verify the account’s actual numeric UID rather than assuming a particular number.
The account provides a selection boundary. It does not establish a VPN or force its traffic through one by itself. Routing selects the path, and the independent firewall guard restricts which paths the account may use.
This selects a socket owner, not an executable name or an NNTP port. It covers the reader’s other connections only if they use the same account. The owner match is not a process-name detector. Helpers using another account, inherited sockets, proxies, and shared resolver services need separate investigation. This is a policy for cooperative software, not containment of a malicious or privileged application.
The current account-guard commands provide no direct LAN or loopback IP exception. Your ordinary account can still reach the printer. A local DNS stub will need a narrowly scoped allowance if required by the chosen DNS walkthrough in Section 8; a broad loopback exception could also admit a local proxy. Unix-domain IPC is outside these IP rules. An approved shared resolver must enforce the independent DNS policy on its own outbound traffic; other delegated networking still needs separate review.
If UID is the only criterion, a direct ip rule uidrange selector may be simpler. This article deliberately demonstrates the classification → mark → policy-rule sequence. Do not install both selection methods for the same test; that would mask a missing marking rule. See ip-rule selectors.
2. Example Values and Prerequisites
| Item | Example |
|---|---|
| Physical host address | 192.168.50.10/24 on eth0 |
| Direct gateway | 192.168.50.1 |
| Working point-to-point VPN | tun0, local address 10.8.0.2 |
| VPN server’s public endpoint | 198.51.100.20 |
| News server | news.example, IPv4 address 203.0.113.10, implicit TLS port 563 |
| Dedicated table | 101 |
| Rule priority | 10100 |
| Dedicated packet-mark value | 0x100 |
| Account | Existing dedicated account newsvpn; discover its actual numeric UID |
Replace documentation addresses and names consistently with real, permitted test endpoints. Do not assume UID 1000 or any other fixed user number. Account provisioning and the reader’s launch command depend on the chosen distribution and client; an unrelated desktop session must not be repurposed as this account.
The VPN already provides Internet access and return routing for its local address. It leaves the host’s direct route usable. Its own transport runs under another account and must continue using the direct path. This example uses fixed tunnel addressing and no host forwarding. An interface or address change requires revalidation.
Use a separate lab host or a deliberately withdrawn prior scenario. Table 101 does not cancel existing routing or firewall rules. A previous destination selector could conceal a missing mark rule, and a previous guard could block the ordinary-account comparison. Inspect and remove only settings owned by the prior exercise, with protected applications stopped. Never flush the host configuration to make room for this example.
Use the same Ubuntu 24.04 lab baseline and tools as the chosen DNS walkthrough, plus OpenSSL for the known-address TLS check. Keep the priority-zero local routing rule. The VPN transport must not be selected by the reader’s UID or mark; inspect the actual policy before proceeding.
3. Inspect and Record the Starting State
Run these in the same administrative shell for the walkthrough. NEWS_UID is used in later commands; confirm it is the intended non-root account before continuing.
NEWS_UID=$(id -u newsvpn)
test "$NEWS_UID" -ne 0
id newsvpn
printf '%s\n' "$NEWS_UID"
uname -r
ip -V
iptables -V
ip6tables -V
ip -4 addr show dev eth0
ip -4 addr show dev tun0
ip -4 rule show
ip -4 route show table all
iptables-save
ip6tables-save
sysctl net.ipv4.conf.all.rp_filter net.ipv4.conf.tun0.rp_filter
Stop if the account lookup fails, the UID is empty or zero, or any other prerequisite is wrong. Confirm table 101, priority 10100, the chosen mark value, and the proposed rule comments are unused in both running and persistent configuration. Review other mark writers, routing rules, NAT, and firewall managers. This example assigns the complete packet mark: confirm the selected traffic does not depend on another mark that would be overwritten. Later rules must not change this mark or override its routing result.
Record the original per-interface reverse-path-filter value for recovery. Store the baseline securely; firewall listings can contain information about your network. These commands inspect state, not back it up automatically.
4. Install Independent Account Guards
The IPv4 guard uses the account directly. It does not depend on the packet receiving a mark:
iptables -w -I OUTPUT 1 -m owner --uid-owner "$NEWS_UID" ! -o tun0 -m comment --comment newsvpn-guard4 -j DROP
ip6tables -w -I OUTPUT 1 -m owner --uid-owner "$NEWS_UID" -m comment --comment newsvpn-guard6 -j DROP
iptables -w -S OUTPUT
ip6tables -w -S OUTPUT
Read the IPv4 rule as: if this account owns the outgoing traffic and the selected output interface is not tun0, drop it.
| Component | Responsibility |
|---|---|
| Packet mark and routing rule | Select the VPN path |
| Account-based firewall guard | Prevent another path from being used |
If the marking rule disappears, the guard still recognizes the account. If routing falls back to a direct interface, the guard blocks that output. This separation is why the guard matches the UID rather than depending on the same mark used for routing.
The guard does not establish the VPN, verify tunnel health, or explicitly allow traffic through it. It recognizes the output interface, not whether encryption is working. Traffic selected for tun0 still has to satisfy the remaining firewall rules. Keep the actual VPN interface and configuration under the administrator’s control.
The IPv6 rule deliberately blocks all IPv6 output from this account. This is an IPv4-only reader example, not a claim to route IPv6 through the VPN. If the IPv6 guard cannot be installed, stop; do not start the reader with an unexplained gap. Verify both guards precede broad accept rules, including established-connection accepts.
Install and verify both guards before starting the reader. The tradeoff is that the reader account also loses direct LAN and loopback IP access. A local DNS stub or a browser-based reader interface may therefore need a separately reviewed, narrowly scoped arrangement. Your ordinary account retains its existing access; do not add a broad exception merely to make a helper service work.
For repeated runs, inspect first and use the same rule specification with -C OUTPUT to check an existing guard. Reuse an exact, correctly placed rule; do not insert duplicates. An unsuccessful check can also indicate a permissions or backend problem. The iptables manual describes the check, insert, and delete operations.
5. Build the VPN Table
ip -4 route add unreachable default metric 32767 table 101
ip -4 route add default dev tun0 src 10.8.0.2 metric 100 table 101
ip -4 route show table 101
The table has a usable VPN default because the account can contact more than one destination. Both entries are defaults; the lower metric selects the usable route. If that route is removed, the unreachable route terminates the lookup. Retain unreachable as the primary example; blackhole would also terminate lookup, but discards packets silently. See route types, metrics, and source selection.
The table’s src is a preferred source for route selection, not a source-address rewrite. An ordinary unmarked local connection can initially choose 192.168.50.10 before mangle/OUTPUT changes its mark. We address that explicitly next.
6. Account for the Source and Return Path
Routing chooses the VPN path. Source translation gives the outgoing packet an address that the VPN can carry and return traffic to. A reader connection may initially select the host’s ordinary address, 192.168.50.10. Marking it with 0x100 can redirect it through tun0, but that does not automatically replace an existing source address with 10.8.0.2.
For this fixed-address example, add scoped SNAT for the exact mark value, physical source address, and VPN output interface:
iptables -w -t nat -I POSTROUTING 1 -s 192.168.50.10/32 -o tun0 -m mark --mark 0x100 -m comment --comment newsvpn-snat -j SNAT --to-source 10.8.0.2
iptables -w -t nat -S POSTROUTING
The rule applies only when all three conditions match: source 192.168.50.10, output interface tun0, and the complete packet mark 0x100. It changes the source to 10.8.0.2, the local tunnel address. The mark value is reserved exclusively for this policy, so the rule does not translate other accounts’ ordinary unmarked traffic. Review existing NAT before inserting it. SNAT takes place in POSTROUTING, after route selection. See the Netfilter NAT documentation.
| Stage | Address Handling |
|---|---|
| Reader creates the connection | Original source: 192.168.50.10 |
| Packet leaves through the VPN | SNAT changes its source to 10.8.0.2 |
| Matching reply returns through the tunnel | Connection tracking reverses the translation and delivers it to the original local connection |
A separate manually written DNAT rule is not needed for those replies. The VPN’s remote side must already provide the necessary onward and return routing; this local rule does not configure the remote side. The tunnel address 10.8.0.2 is not necessarily the public address seen by the news server.
SNAT is appropriate here because of the example’s initial source selection. It is not a universal requirement for every VPN configuration.
Use fresh connections when testing. NAT decisions persist for a tracked connection, so removing or changing the rule does not retrofit an existing session. Do not clear the entire conntrack table. If a fresh reader connection has an unexpected source, stop and investigate instead of widening the rule indiscriminately. Dynamically addressed tunnels would need a separately reviewed approach, such as scoped MASQUERADE and reconnect handling. See Netfilter’s connection-tracking explanation.
Reverse-path filtering is a separate check. Strict mode can reject a legitimate reply arriving through tun0 because the host’s unmarked route back to its sender points through eth0. For this asymmetric example, use loose checking on tun0:
sysctl -w net.ipv4.conf.tun0.rp_filter=2
sysctl net.ipv4.conf.all.rp_filter net.ipv4.conf.tun0.rp_filter
Do this only after recording the original value and checking the host’s policy. Loose checking still requires a route to the source, but does not require it to use the receiving interface. Linux uses the maximum of all and the interface value. This does not disable filtering globally; it is a specific tradeoff for this example. A recreated interface needs its policy reapplied. See kernel IP sysctl documentation.
The existing firewall must also admit the expected reply traffic. A zero-error command sequence does not settle that policy.
7. Connect Classification to Routing
First install the consumer of the mark, then the marking rule, with the reader still stopped:
ip -4 rule add priority 10100 fwmark 0x100 lookup 101
iptables -w -t mangle -A OUTPUT -m owner --uid-owner "$NEWS_UID" -m comment --comment newsvpn-mark -j MARK --set-mark 0x100
ip -4 rule show
iptables -w -t mangle -S OUTPUT
Use --set-mark 0x100 to assign one complete mark value. The routing selector fwmark 0x100 and the NAT selector --mark 0x100 both match that exact value. No explicit bitmask is needed for this example. Assigning the complete value replaces any previous packet mark, so the preflight check must confirm that the selected traffic does not need another marking policy. See the MARK documentation.
Placing classification after existing mangle rules avoids an earlier writer undoing it, but a pre-existing terminal verdict can make an appended rule unreachable. Verify the actual chain, counter activity, and final route. Do not assume append order alone proves correct placement.
For local traffic, the kernel’s mangle OUTPUT handling can reconsider the route after a mark change. The nftables route-chain implementation also checks for a changed mark and reroutes. No PREROUTING marking is needed for this host-originated example. Record the installed iptables backend and verify its actual packet path.
There is no CONNMARK save/restore in the initial design. Account-owned outbound packets are classified as they traverse OUTPUT. We do not need to give inbound replies the outbound routing mark, and we have explicitly addressed reverse-path checking. This simplification must be checked with the selected reader and socket behavior rather than extended to every application.
8. Give DNS Its Own Routing Policy
The application account and mark do not select the shared resolver’s upstream route. Choose one of the six DNS policies after preparing this foundation. The private-resolver and shared-stub alternatives have different account-guard requirements; follow only the selected walkthrough. Keep applications stopped until its DNS configuration and checks are complete.
The known-address TLS checks below isolate application routing from DNS. They do not substitute for a DNS policy. All six walkthroughs keep application fallback separate from DNS fallback.
9. Verify the Route, Source, and Application
Use set +e before diagnostic commands so expected failures do not close the walkthrough shell. Inspect each result, especially every restore operation. The route lookup below supplies a mark manually. It verifies the policy-rule/table combination; it does not prove that the reader receives a mark:
set +e
ip -4 route get 203.0.113.10 mark 0x100
ip -4 route get 203.0.113.10
ip -4 route get 198.51.100.20
ip -4 route get 192.168.50.25
iptables -w -t mangle -L OUTPUT -n -v --line-numbers
iptables -w -t nat -L POSTROUTING -n -v --line-numbers
iptables -w -L OUTPUT -n -v --line-numbers
ip6tables -w -L OUTPUT -n -v --line-numbers
Expect the marked lookup to use table 101 and tun0; the unmarked lookup should use the direct route. The VPN endpoint and the ordinary account’s printer connection must remain direct/local. These lookups do not execute firewall rules or demonstrate SNAT.
With real replacement values, test an NNTP TLS handshake under the selected account without DNS or account credentials:
runuser -u newsvpn -- openssl s_client -4 -connect 203.0.113.10:563 -servername news.example -verify_hostname news.example -verify_return_error
Verify certificate trust and hostname, inspect the server greeting, then close the session. Use the appropriate trusted CA configuration for the platform. This tests transport, not authentication or the reader’s full behavior. Do not put news-provider passwords in command arguments or audit transcripts. OpenSSL documents these verification options.
For the ordinary-account control, repeat the same known-address handshake as your recorded ordinary user:
runuser -u "$ORDINARY_USER" -- openssl s_client -4 -connect 203.0.113.10:563 -servername news.example -verify_hostname news.example -verify_return_error
This checks the same endpoint from the other account; it does not report a public exit address. Use the simple browser comparison in the chosen DNS walkthrough for that feedback, after its resolver setup is complete.
Inspect captures on tun0 and eth0 during selected-account tests: selected inner traffic should leave through the tunnel with the expected source, while only encrypted VPN transport should carry it on the physical path. NAT counters describe new tracked connections, not every packet. Record counter differences rather than resetting shared counters.
Finally launch the chosen reader under newsvpn using its documented command and dedicated configuration. Confirm the actual socket owner, helper accounts, TLS validation, name resolution, authentication, and an authorized read/download. Test posting separately only if needed, using an appropriate test group and provider permission. A working OpenSSL test is not proof that the reader is correctly configured. Neither a sample credential nor an invented reader-launch command is supplied here.
10. Failure Tests
Run one fault at a time in the isolated environment, restoring and verifying the normal state between cases. Keep both account guards active. Test fresh connections as well as an existing download and the reader’s retries.
| Fault | Expected Result |
|---|---|
Remove the usable VPN default from table 101 |
Marked lookup fails through the unreachable default; reader cannot switch to direct access. |
| Remove the mark selector | Lookup may become direct; the independent UID guard blocks the reader. |
| Remove the marking rule | Reader packets may remain unmarked; the same UID guard blocks direct output. |
| Stop the VPN through its supported controls | Reader traffic fails closed; ordinary-account direct and LAN traffic remain usable. |
| VPN becomes unresponsive but interface remains | Reader may hang or time out; it must not establish a direct fallback. |
| Try IPv6 from the reader account | No IPv6 traffic from that account leaves the host. |
| Reconnect or recreate the tunnel | Recheck address, routes, reverse-path filter, SNAT, and guards before resuming the reader. |
For the first fault, remove only the usable default, test, then restore it when the interface and source address are verified:
ip -4 route del default dev tun0 src 10.8.0.2 metric 100 table 101
ip -4 route show table 101
ip -4 route get 203.0.113.10 mark 0x100
ip -4 route add default dev tun0 src 10.8.0.2 metric 100 table 101
For the second fault, test between the delete and restore blocks:
ip -4 rule del priority 10100 fwmark 0x100 lookup 101
ip -4 rule add priority 10100 fwmark 0x100 lookup 101
For the third fault, test between the delete and restore blocks:
iptables -w -t mangle -D OUTPUT -m owner --uid-owner "$NEWS_UID" -m comment --comment newsvpn-mark -j MARK --set-mark 0x100
iptables -w -t mangle -A OUTPUT -m owner --uid-owner "$NEWS_UID" -m comment --comment newsvpn-mark -j MARK --set-mark 0x100
A routing rejection can occur before the firewall guard sees a packet, so its counter need not increase in every failure test. For direct-fallback attempts caused by a missing mark or selector, inspect the UID guard’s counter and the physical-interface capture. A timeout alone proves neither correct classification nor absence of leakage.
For the IPv6 test, use a permitted IPv6 endpoint and inspect guard counters/captures. If the host has no usable IPv6 path, record that limitation: a failed connection alone does not demonstrate enforcement on an IPv6-capable host. Independently verify the dedicated DNS policy throughout failure and reconnection tests, including the shared resolver and requests from other accounts. The reader-only IPv6 guard is not host-wide DNS protection.
11. Withdrawal and Persistence
Withdraw the chosen DNS walkthrough first, using its own restoration sequence. Then stop the reader and its helpers and retain both original account guards. Inspect which foundation-owned entries remain. Run each deletion separately, check its result, and remove only entries actually present:
iptables -w -t mangle -D OUTPUT -m owner --uid-owner "$NEWS_UID" -m comment --comment newsvpn-mark -j MARK --set-mark 0x100
ip -4 rule del priority 10100 fwmark 0x100 lookup 101
iptables -w -t nat -D POSTROUTING -s 192.168.50.10/32 -o tun0 -m mark --mark 0x100 -m comment --comment newsvpn-snat -j SNAT --to-source 10.8.0.2
ip -4 route del default dev tun0 src 10.8.0.2 metric 100 table 101
ip -4 route del unreachable default metric 32767 table 101
An entry already absent after a deliberate fault is different from an unexplained command failure. Restore the recorded tun0 reverse-path-filter value if this example alone changed it and the same interface still exists. Use sysctl -w net.ipv4.conf.tun0.rp_filter=RECORDED_VALUE, replacing the placeholder with the saved value; do not guess it. Existing conntrack entries may outlive rule deletion; keep the application stopped rather than flushing unrelated sessions.
Keeping the guards means the account remains blocked from direct use. Their removal is a deliberate change in protection, not automatic error cleanup. Do not delete or recycle the account while a numeric-UID guard is intended to protect it.
After runtime tests pass, persistence needs one configuration owner: account guards before the reader can start; table, SNAT, reverse-path policy, selector, and marking ready before the reader is enabled; and safe reapplication when the tunnel is recreated. Stop on setup failure and preserve blocking. Do not simply concatenate these blocks into a boot script. Verify firewall-manager reloads and a reboot with independent recovery access.
Leave the Root Shell
If continuing into your chosen DNS walkthrough, stay in this shell and skip its repeated shell-opening section. Otherwise return to your ordinary account when finished:
exit
Review History
Preserved November 15 technical proposal (text). The local revision reconciles that proposal with the later root-session, DNS-policy and withdrawal decisions. This simple foundation remains a manual setup whose Linux acceptance is deferred. The separate advanced Ubuntu walkthrough documents the implemented startup and persistence controls for the advanced use cases; it does not change this example.