首页 > 服务器 > iptables端口映射后php获取客户端ip问题

作者:ghostry 发布时间:2018-02-01 浏览: 4373

转载注明出处: https://blog.ghostry.cn/server/851.html

这里踩了一个坑

刚开始我使用了

iptables -t nat -A PREROUTING -d 外网ip -p tcp --dport 80 -j DNAT --to-destination 内网webIP:80
iptables -t nat -A POSTROUTING -d 内网webIP -p tcp --dport 80 -j SNAT --to-source 外网IP

来映射端口。
却发现php获取的客户端ip全都成了自己的外网IP
经过查找资料。发现原来正确做法是

iptables -t nat -A PREROUTING -d 外网IP -p tcp --dport 80 -j DNAT --to 内网webIP:80

然后在web服务器上面设置默认路由为做转发的机器。
这样php就可以正确的拿到客户端ip了。

标签: php iptables

上一篇: Ubuntu配置go语言编译环境
下一篇: Android刷机包解包打包

添加新评论 »

*
*

欢迎评论!歡迎評論!Comments welcome!komentoj bonvenaj!댓글 오신 것을 환영합니다!
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: :cold: :cryy: :cute: :shy: :sleep: :struggle: :tea: :yahou: