Complete Traffic Forwarding Guide (iptables)
This guide explains how to use IP forwarding and iptables NAT to redirect incoming traffic from a Linux relay server to a 4iProto destination server. Typical use cases include full traffic forwarding, transparent proxy setups, and gateway relay designs.
:::info Alternative For a dedicated Abdal 4iProto Multi-Hop TCP/UDP proxy (without writing iptables rules yourself), see Abdal 4iProto Proxy Multi-Hop. :::

danger
Apply these rules carefully. Incorrect NAT rules can lock you out of the relay host. Keep an alternate SSH path ready before changing PREROUTING rules.
Prerequisites
- Linux operating system
- Root access
- iptables installed and active
- Valid 4iProto server IP
- Basic understanding of NAT, DNAT, SNAT, and routing
Step 1: Enable IP Forwarding
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
Step 2: Redirect SSH Port to Another Server
Keep management access reachable by redirecting SSH intentionally (replace placeholders):
iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination IRAN_IP
Step 3: Forward All Traffic to 4iProto Server
iptables -t nat -A PREROUTING -j DNAT --to-destination 4iProto_IP
Step 4: Enable Source NAT
iptables -t nat -A POSTROUTING -j MASQUERADE
Important Notes
- The SSH port rule must be applied before the general PREROUTING rule
- Ensure alternative SSH access before applying rules
- Adjust firewall settings if you use
firewalldorufw - Replace
IRAN_IPand4iProto_IPwith real addresses for your topology