Skip to content

How to Use nftables Redirect for Transparent Proxies

DodaTech Updated 2026-06-24 2 min read

The redirect statement in nftables sends matching traffic to a local port for transparent proxy processing. It is essential for transparent proxy setups. This guide walks through the specific troubleshooting steps to diagnose and resolve redirect issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Wrong: Using legacy iptables REDIRECT syntax

nft add rule ip nat prerouting tcp dport 80 redirect to :8080

Right: nftables redirect statement

Output

Redirect rule added:\n  Port 80 traffic → port 8080 (local proxy)\n  Transparent proxy: enabled

Prevention

To avoid future issues, follow these best practices:

  • Use redirect in the nat table prerouting chain
  • The redirect target sends packets to a local port without changing the destination IP
  • Use for transparent HTTP proxies like Squid
  • Use for port redirection of local traffic in the output chain
  • The redirect statement is also available in ip6 family

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with redirect

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world NFTABLES code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the difference between redirect and dnat?|||redirect sends packets to a local port on the same host. dnat can redirect to any IP:port. redirect is simpler for local proxy setups.
Can I redirect UDP traffic? Yes. Use redirect to :port for UDP-based proxy services.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro