Netfilter recipes¶
These are reviewable starting templates, not copy-paste production policy. Interface names, routing tables, marks, local exclusions and the Smithproxy service identity must match your host.
Test from a console
Netfilter and policy-routing mistakes can cut off remote access or create a proxy loop. Test in a network namespace first, keep an out-of-band console and save the original ruleset.
TPROXY policy routing¶
Choose a mark and table unused by other software:
sudo ip rule add fwmark 0x1/0x1 lookup 100
sudo ip route add local 0.0.0.0/0 dev lo table 100
sudo ip -6 rule add fwmark 0x1/0x1 lookup 100
sudo ip -6 route add local ::/0 dev lo table 100
The route makes marked packets locally deliverable without replacing their destination address.
Routed IPv4 TPROXY template¶
Assume client traffic arrives on lan0, plaintext TCP/UDP uses port 50080, and dedicated TLS interception uses 50443:
sudo iptables -t mangle -N SMITHPROXY_IN
# Never intercept loopback, management and the proxy host itself.
sudo iptables -t mangle -A SMITHPROXY_IN -d 127.0.0.0/8 -j RETURN
sudo iptables -t mangle -A SMITHPROXY_IN -d 192.0.2.5/32 -j RETURN
# Send TLS and other TCP to their configured listeners.
sudo iptables -t mangle -A SMITHPROXY_IN -p tcp --dport 443 \
-j TPROXY --on-port 50443 --tproxy-mark 0x1/0x1
sudo iptables -t mangle -A SMITHPROXY_IN -p tcp \
-j TPROXY --on-port 50080 --tproxy-mark 0x1/0x1
# General UDP interception.
sudo iptables -t mangle -A SMITHPROXY_IN -p udp \
-j TPROXY --on-port 50080 --tproxy-mark 0x1/0x1
sudo iptables -t mangle -A PREROUTING -i lan0 -j SMITHPROXY_IN
Replace 192.0.2.5 with the Smithproxy/management address. Add explicit destination exclusions for infrastructure that must never be intercepted. Restrict source ranges instead of diverting an entire interface when possible.
IPv6 TPROXY template¶
Mirror the policy explicitly; IPv4 rules do not cover IPv6:
sudo ip6tables -t mangle -N SMITHPROXY6_IN
sudo ip6tables -t mangle -A SMITHPROXY6_IN -d ::1/128 -j RETURN
sudo ip6tables -t mangle -A SMITHPROXY6_IN -d 2001:db8::5/128 -j RETURN
sudo ip6tables -t mangle -A SMITHPROXY6_IN -p tcp --dport 443 \
-j TPROXY --on-port 50443 --tproxy-mark 0x1/0x1
sudo ip6tables -t mangle -A SMITHPROXY6_IN -p tcp \
-j TPROXY --on-port 50080 --tproxy-mark 0x1/0x1
sudo ip6tables -t mangle -A SMITHPROXY6_IN -p udp \
-j TPROXY --on-port 50080 --tproxy-mark 0x1/0x1
sudo ip6tables -t mangle -A PREROUTING -i lan0 -j SMITHPROXY6_IN
Validate extension support and syntax on the target distribution. Systems using the iptables-nft compatibility layer may be better managed with a native nftables ruleset.
Local TCP REDIRECT template¶
REDIRECT is suitable for selected locally originated TCP flows. Run Smithproxy under a dedicated service account if possible, then exempt that account to prevent a loop:
sudo iptables -t nat -N SMITHPROXY_OUT
sudo iptables -t nat -A SMITHPROXY_OUT -m owner --uid-owner smithproxy -j RETURN
sudo iptables -t nat -A SMITHPROXY_OUT -d 127.0.0.0/8 -j RETURN
sudo iptables -t nat -A SMITHPROXY_OUT -p tcp --dport 443 \
-j REDIRECT --to-ports 51443
sudo iptables -t nat -A SMITHPROXY_OUT -p tcp \
-j REDIRECT --to-ports 51080
sudo iptables -t nat -A OUTPUT -p tcp -j SMITHPROXY_OUT
The 51xxx REDIRECT ports are packaging/startup-script conventions and differ from the 50xxx TPROXY listener ports shown in the sample configuration. Confirm actual listeners with the running build before applying rules.
Do not generalize this TCP template to arbitrary UDP. Use TPROXY for general transparent UDP or configure applications with SOCKS5 UDP where appropriate.
nftables translation guidance¶
A native nftables deployment needs the same logical stages:
- return early for loopback, management and Smithproxy-originated traffic;
- match only authorized client sources/interfaces;
- set the selected packet mark;
- use
tproxy to :<port>in a route/output-capable chain; - add matching IPv4 and IPv6 policy routes.
Keep marks in named constants and document ownership when firewalld, Docker, Kubernetes, VPN software or another transparent proxy also manipulates policy routing.
Verification and rollback¶
Before generating traffic:
ip rule show
ip route show table 100
ip -6 rule show
ip -6 route show table 100
sudo iptables -t mangle -L SMITHPROXY_IN -n -v
After one test request, rule counters and diag proxy session list active ips should agree. Prepare rollback commands that remove the jump rules, custom chains, policy rules and table routes; never flush an unrelated production table as a shortcut.