加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – iptables从外部接口重定向到loopback的端口?

发布时间:2020-12-14 01:01:12 所属栏目:Linux 来源:网络整理
导读:我尝试将端口从我的lxc-container重定向到环回. 我的lxc-container配置了lxcbr1网桥11.0.3.1. 我尝试将netcat从主机连接到lxc,从lxc连接到主机.成功. 本地主机: # nc -l 1088 LXC: # nc 11.0.3.1 1088Hello! 和localhost见消息:“你好
我尝试将端口从我的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没有看到此消息.

我哪里错了?

我找到了这个答案:http://www.voidcn.com/article/p-atanrest-btv.html

有一些声音,环回不使用PREROUTING.我该怎么办?

解决方法

无法使用DNAT进行环回流量.

我发现了很多类似的问题. 1,2,3等…

根据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都不太可能这样做,这没关系.这是我的意见.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读