首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未能在SuSE Linux上正确转发iptables

未能在SuSE Linux上正确转发iptables
EN

Server Fault用户
提问于 2016-09-10 16:05:57
回答 1查看 751关注 0票数 0

我正努力通过iptables转发一个端口。我做了很多谷歌搜索,但我尝试的所有解决方案都不起作用。

在同一个局域网上用三台计算机进行非常简单的设置

代码语言:javascript
运行
复制
192.168.0.1 # destination
192.168.0.2 # redirector (only one interface)
192.168.0.3 # source

我的iptables配置也很简单

代码语言:javascript
运行
复制
# iptables -L -n -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80 to:192.168.0.1
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443 to:192.168.0.1

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0

# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

根据我所读到的,这应该行得通。但事实并非如此,我也曾和iptables -t nat -I POSTROUTING 1 -p tcp -d 192.168.0.1 --dport 443 -j SNAT --to-source 192.168.0.1玩过,但也不起作用。是的,ip_forward是启用的。

浏览到192.168.0.2:80/443应该从192.168.0.1返回内容,不是吗?有什么想法吗?

EN

回答 1

Server Fault用户

回答已采纳

发布于 2017-08-11 09:18:51

我让它起作用了!正确的规则是

代码语言:javascript
运行
复制
iptables -t nat -A PREROUTING -d 192.168.0.2 ! -s 192.168.0.1 -p tcp --dport 80 -j DNAT --to 192.168.0.1:80
iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp --dport 80 -j SNAT --to 192.168.0.2.

添加-d就能做到这一点。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/802303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档