-
Notifications
You must be signed in to change notification settings - Fork 259
Port IP Address Redirection
Home · Start Here · Reference Map
- DNAT redirects traffic from one IP to another; REDIRECT remaps ports on the same host.
- Rules are defined in
/etc/csf/csf.redirect, one entry per line. - Requires NAT tables and specific iptables modules (
ipt_DNAT,ipt_SNAT,ipt_REDIRECT). - Not intended for general routing, NAT gateways, or VPN use cases.
Related guide: Configuration-Guide
- Kernel NAT table support enabled.
- Required iptables modules loaded:
ipt_DNATipt_SNATipt_REDIRECT
- For DNAT (cross-IP) redirections: IP forwarding must be enabled:
cat /proc/sys/net/ipv4/ip_forward
# Must return 1CSF attempts to set
ip_forward = 1automatically when DNAT rules are present, but if the kernel value cannot be changed, DNAT redirection will not work.
- Validate module support:
perl /etc/csf/csftest.plRules are placed in /etc/csf/csf.redirect, one per line. Comments begin with #.
Redirects traffic destined for one IP to another IP (optionally with port mapping):
IPx|*|IPy|*|tcp/udp # All traffic to IPx → IPy (same port)
IPx|portA|IPy|portB|tcp/udp # Traffic to IPx:portA → IPy:portB
Redirects traffic arriving on one port to a different local port:
IPx|portA|*|portB|tcp/udp # Traffic to IPx:portA → local portB
*|portA|*|portB|tcp/udp # Traffic on any IP to portA → local portB
Constraint: port values must be single ports, not ranges.
# /etc/csf/csf.redirect
203.0.113.50|*|198.51.100.10|*|tcp
All TCP connections to 203.0.113.50 are forwarded to 198.51.100.10.
# /etc/csf/csf.redirect
*|8025|*|25|tcp
TCP connections to port 8025 on any address are redirected to local port 25 (SMTP).
# /etc/csf/csf.redirect
203.0.113.60|8443|*|443|tcp
Only connections to 203.0.113.60:8443 are redirected to local port 443.
- Backup current redirect file:
cp /etc/csf/csf.redirect /etc/csf/csf.redirect.bak-
Edit
/etc/csf/csf.redirectand add your rule(s). - Reload CSF:
csf -r- Validate (see next section).
- If validation fails, rollback (see below).
iptables -t nat -L PREROUTING -n --line-numbers | grep -i dnat
iptables -t nat -L PREROUTING -n --line-numbers | grep -i redirectFrom a remote client, connect to the original destination and verify traffic reaches the new target:
# From client — test that IPx:portA reaches IPy:portB
curl -v http://203.0.113.50:8025/# From any host — verify local port remap
telnet 203.0.113.60 8443tail -n 50 /var/log/lfd.log- Restore the backup:
cp /etc/csf/csf.redirect.bak /etc/csf/csf.redirect- Reload CSF:
csf -r- Re-verify that redirect rules have been removed:
iptables -t nat -L PREROUTING -n | grep -iE "dnat|redirect"- DNAT rules are applied in the
PREROUTINGNAT chain — they execute before CSF'sINPUTchain filtering. Ensure the destination IP/port is also allowed in CSF policy if the target is on the same host. -
csf.allow/csf.denyrules apply to the original destination address, not the redirected address. - Port redirection does not bypass connection-limit (
CONNLIMIT) or port-flood (PORTFLOOD) rules on the destination port.
-
IP forwarding disabled: DNAT silently fails if
/proc/sys/net/ipv4/ip_forwardis0. - NAT hairpin / loopback: traffic originating from the same host as the DNAT target may not work without explicit SNAT/masquerade rules — CSF does not configure this automatically.
- Redirect loops: redirecting port A → port B when port B also has a redirect creates a loop. CSF does not detect or prevent this.
- Source IP masking on DNAT: all redirected traffic appears at the destination with the redirecting server's IP as source, not the original client IP. This is by design and cannot be changed.
- Port ranges: specifying port ranges instead of single ports will cause the rule to fail silently.
- Using this for routing/VPN: this feature is designed for simple port/IP remapping, not general-purpose NAT or VPN tunneling.
Last reviewed: 2026-02-27
← Previous: Connection Limit Protection · Next: Integrated User Interface Feature
- Security Features Guide
- Cloud & Container Hardening
- Automation & IaC
- IPv6 Deployment & Hardening
- IP Block Lists
- Reference Map
- Introduction
- csf Principles
- lfd Principles
- csf CLI Options
- lfd CLI Options
- Login Tracking
- Regex Custom Cookbook
- Script Email Alerts
- Process Tracking
- Directory Watching
- Advanced Filters
- Multiple Ethernet
- Generic Linux
- FTP Issues
- Messenger Service
- Block Reporting
- Port Flood
- Pre/Post Scripts
- Port Knocking
- Connection Limit
- Port/IP Redirect
- Integrated UI
- RESTRICT_SYSLOG
- Exim SMTP AUTH
- UI Skinning
- InterWorx
- CentOS Web Panel