Redirect Local Requests to IP to Other IP (Linux

Abstract: Redirects local traffic destined for a specific IP to another IP on Debian 10+ using nftables output chain DNAT.

Created: 2026-09-11 by
To redirect local requests destined for a specific IP address to another IP on Debian 10 and newer, you must configure the nat table within nftables. This process involves creating a new chain in the ip nat family, adding rules that match the destination address, and applying a dnat verdict to rewrite the packet's target. The following guide details the precise commands required to implement this network redirection safely and effectively.

Understanding nftables Structure

Before modifying any rules, it is essential to understand how nftables organizes its configuration compared to its predecessor, iptables. Unlike iptables, which uses flat tables with implicit chains like PREROUTING, nftables relies on an explicit hierarchy of families, tables, and chains. For local traffic redirection, we are primarily concerned with the ip family and the nat table. The nat table is responsible for Network Address Translation. It operates at the netfilter hooks that allow packets to be modified before routing decisions are finalized or after they have been routed. In our case, since we are dealing with local requests (traffic generated by the machine itself), we will focus on the output path. This ensures that applications running on the host sending traffic to the original IP see their packets redirected to the new IP without requiring external interface involvement.

Prerequisites and Verification

Ensure your system is running Debian 10 or a newer version, as older releases may default to iptables-legacy compatibility layers that do not support modern nftables syntax directly. You can verify the installed version using the command nft --version. Additionally, confirm that the nftables service is active and enabled. On Debian systems, this is typically managed via systemd. You should also check the current state of your firewall to avoid conflicts. Run sudo nft list ruleset to view existing rules. If there are existing nat rules, note them down, as adding new rules incorrectly could disrupt current network functionality. It is often safer to start with a clean slate or append to existing configurations carefully.

Creating the NAT Chain

The first step is to create a dedicated chain within the ip nat table where our redirection logic will reside. We will name this chain LOCAL_DNAT. This separation helps keep your configuration organized and makes future maintenance easier. Execute the following command to create the chain:
sudo nft add chain ip nat LOCAL_DNAT { type nat hook output priority -100 ; policy accept ; } 
This command defines a chain named LOCAL_DNAT inside the ip nat table. The hook output specifies that this chain processes packets leaving the local system. The priority -100 places it early in the processing pipeline, ensuring the redirection happens before other potential manipulations. The policy accept means that if no rules match in this chain, the packet continues normally.

Adding Redirection Rules

With the chain established, you need to add rules that define the source and destination conditions for the redirection. Suppose you want to redirect all traffic destined for 192.168.1.100 to 192.168.1.200. Use the following command:
sudo nft add rule ip nat LOCAL_DNAT ip daddr 192.168.1.100 dnat to 192.168.1.200 
This rule matches packets where the destination address (ip daddr) is exactly 192.168.1.100. When a match occurs, the dnat to action rewrites the destination address to 192.168.1.200. If you need to redirect a range of IPs, you can use CIDR notation, such as ip daddr 192.168.1.0/24. Similarly, you can restrict the redirection to specific protocols or ports by adding tcp dport or udp dport criteria to the rule.

Persisting Configuration

Rules added via the command line are volatile and will be lost upon reboot. To make these changes permanent, you must save the current ruleset to a configuration file. On Debian, the standard location for this file is /etc/nftables.conf. First, export the current ruleset:
sudo nft list ruleset > /etc/nftables.conf 
After saving, ensure that the nftables service is configured to load this file on boot. Verify the service status with systemctl status nftables. If the service is not enabled, run sudo systemctl enable nftables. This ensures that your redirection rules are applied automatically every time the system starts. For more context on managing default behaviors in nftables, you might find Understanding the Default Verdict with nftables Rule: A Comprehensive Guide helpful, as it explains how policies interact with custom chains.

Testing and Troubleshooting

Once the rules are in place, test the redirection by attempting to connect to the original IP address from a local application. For example, use curl http://192.168.1.100 or ping 192.168.1.100. If the redirection is working correctly, the connection should succeed but actually communicate with 192.168.1.200. You can verify this by checking logs on the target server or using tcpdump to observe the rewritten packets. If the redirection fails, check the following: 1. Ensure the nftables service is active and loaded the correct configuration. 2. Verify that no other firewall rules are dropping the traffic. 3. Confirm that the target IP (192.168.1.200) is reachable and accepting connections. 4. Check for any conflicting rules in the nat table that might override your new entry. See Unable to traceroute but able to ping if you suspect intermediate routing issues affecting your local requests.

Frequently Asked Questions

Does this method work for IPv6?

No, the examples provided use the ip family which handles only IPv4. For IPv6, you must use the ip6 family instead, changing ip nat to ip6 nat in all commands. The syntax for addresses and redirection remains similar, but you must use IPv6 addresses.

Will this affect incoming traffic from other hosts?

No, because we used the output hook, this rule only applies to traffic generated locally on the machine. Incoming traffic from remote hosts is processed by the prerouting hook, which requires separate rules if you wish to redirect those as well.

How do I remove a specific rule?

You can delete a rule by listing the ruleset with nft list chain ip nat LOCAL_DNAT to get the handle number, then using sudo nft delete rule ip nat LOCAL_DNAT handle <number>. Alternatively, you can flush the entire chain with nft flush chain ip nat LOCAL_DNAT if you want to clear all rules within it.

Can I redirect based on source IP as well?

Yes, you can add a condition for the source address using ip saddr. For example, ip saddr 10.0.0.5 ip daddr 192.168.1.100 dnat to 192.168.1.200 would only redirect traffic originating from 10.0.0.5 to the specified target.

What happens if the new IP is unreachable?

If the destination IP 192.168.1.200 is unreachable, the connection attempt will likely timeout or fail with a "No route to host" error. The redirection itself succeeds, but the underlying network connectivity determines the outcome. Ensure the new IP is valid and accessible from the local machine.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More