大网数据广告活动
服务器运维问答

Correct OpenWRT configuration for iptables PREROUTING rule

· 52CE 我爱测

I've recently switch my router firmware from Tomato to OpenWRT. I had the iptable commands below which would intercept http requests to an internal ip (192.168.1.254) on port 80 and redirect to a different internal ip (192.168.1.…

问题原文

原帖链接 · Shawn McGough · CC BY-SA 3.0

I've recently switch my router firmware from Tomato to OpenWRT. I had the iptable commands below which would intercept http requests to an internal ip (192.168.1.254) on port 80 and redirect to a different internal ip (192.168.1.133) on port 8082.

This configuration is not working working on OpenWRT. I've entered it in the Firewall - Custom Rules section.

iptables -t nat -I PREROUTING -p tcp -d 192.168.1.254 --dport 80 -j DNAT --to-destination 192.168.1.133:8082
iptables -t nat -I POSTROUTING -p tcp --dport 80 -j MASQUERADE

I've read up quite a bit but most guides are how to set up WAN port forwarding. I've been at it for hours and have had to boot OpenWRT into failsafe mode a few times. I would be grateful for any help.

Additional details:

  • I had these commands working on the Tomato router
  • both IPs are PING-able from inside the network
  • target IP & port (192.168.1.133:8082) serves content when hit directly
  • both IPs are PING-able from inside the network

已采纳解答

原帖链接 · Shawn McGough · CC BY-SA 3.0

After a few more hours of trying, I was able to get this working with the help of this article; https://www.debuntu.org/how-to-redirecting-network-traffic-to-a-new-ip-using-iptables/

My POSTROUTING command was not correct. Switching to the following command worked:

iptables -t nat -I POSTROUTING -j MASQUERADE

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。