linux – iptables从外部接口重定向到loopback的端口?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – iptables从外部接口重定向到loopback的端口?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1832字,纯文字阅读大概需要3分钟。
内容图文
![linux – iptables从外部接口重定向到loopback的端口?](/upload/InfoBanner/zyjiaocheng/971/c1748d1195ca47048a6b8d94b49310ce.jpg)
我尝试将端口从我的lxc-container重定向到环回.
我的lxc-container配置了lxcbr1网桥11.0.3.1.
我尝试将netcat从主机连接到lxc,从lxc连接到主机.成功.
本地主机:
# nc -l 1088
LXC:
# nc 11.0.3.1 1088
Hello!
和localhost见消息:“你好!”.成功!
当我以这种方式重定向端口时:
# iptables -t nat -A PREROUTING -i lxcbr1 -p tcp -d 11.0.3.1 --dport 1088 -j DNAT --to-destination 127.0.0.1:1088
# nc -l 127.0.0.1 1088
此后,我尝试从lxc-container连接:
# nc 11.0.3.1 1088
Hello !
但localhost没有看到此消息.
我哪里错了?
我找到了这个答案:https://serverfault.com/questions/211536/iptables-port-redirect-not-working-for-localhost
有一些声音,环回不使用PREROUTING.我该怎么办?
解决方法:
无法使用DNAT进行环回流量.
根据RFC 5735,网络127.0.0.0/8不应在主机外部路由:
127.0.0.0/8 – This block is assigned for use as the Internet host loopback address. A datagram sent by a higher-level protocol to an
address anywhere within this block loops back inside the host. This is
ordinarily implemented using only 127.0.0.1/32 for loopback. As
described in [RFC1122], Section 3.2.1.3, addresses within the entire
127.0.0.0/8 block do not legitimately appear on any network anywhere.
RFC 1700,第5页,«绝不应出现在主持人之外».
有一个出口:使用inetd.
有许多服务器,xinetd等.
我的选择是rinetd.
我使用这本手册http://www.howtoforge.com/port-forwarding-with-rinetd-on-debian-etch
我的配置如下所示:
$cat /etc/rinetd.conf
# bindadress bindport connectaddress connectport
11.0.3.1 1081 127.0.0.1 1081
11.0.3.1 1088 127.0.0.1 1088
我重启rinetd:
$/etc/init.d/rinetd restart
Stopping internet redirection server: rinetd.
Starting internet redirection server: rinetd.
重定向就像一个魅力.
我不会自己关闭这个问题,因为我仍然在为这样的任务寻找更优雅的解决方案.任何动物,netcat或inetd都不太可能这样做,这没关系.这是我的意见.
内容总结
以上是互联网集市为您收集整理的linux – iptables从外部接口重定向到loopback的端口?全部内容,希望文章能够帮你解决linux – iptables从外部接口重定向到loopback的端口?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。