带有Loopback IP,IPFW和natd的FreeBSD Jail – 出站连接从jail失败

我有一个FreeBSD 9.0服务器。 它有几个监狱,但他们都有这个相同的问题。 他们不能启动与外界的联系。 他们彼此沟通,主持人很好。

相关的rc.conf设置:

 firewall_enable="YES" # IPFW firewall_type="/etc/ipfw.rules" # Rule script for IPFW natd_enable="YES" # NAT for Internet Routing natd_interface="wan0" # NAT Card natd_flags="-f /etc/natd.conf -dynamic" # NAT Conf ifconfig_lo1_name="jail1" ifconfig_jail1="inet 192.168.1.101/32" jail_asdf_rootdir="/jails/asdf" jail_asdf_hostname="asdf.example.net" jail_asdf_ip="192.168.1.101" jail_asdf_devfs_enable="YES" 

sysctl.conf

 security.jail.allow_raw_sockets=1 

来自ipfw.rules

 # XXX 00050 divert natd ip4 from any to any via wan0 add 00060 check-state # Allow me out add 00135 allow ip from me to any keep-state add 00136 allow ip6 from me6 to any keep-state # HTTP add 11010 allow tcp from any to me http setup keep-state add 11011 allow tcp from any to me6 http setup keep-state add 11012 allow tcp from any to me https setup keep-state add 11013 allow tcp from any to me6 https setup keep-state .... lots more rules like the above .... # General Network - ICMP add 61001 allow icmp from any to any # XXX last rule is deny everything 

natd.conf

 redirect_port tcp 192.168.1.101:80 80 redirect_port tcp 192.168.1.101:443 443 

这对于传入连接非常有用。 我已经从多台电脑进行testing,我可以很好地到达网站。

当我jexec 1 csh得到在监狱的壳我不能创build一个传出的连接。 监狱的resolv.conf指向主机服务器,它执行罚款的名称parsing。 随着ICMP仍然毫无例外地通过我可以从监狱平。

我可以在tcpdump -i wan0 host 1.2.3.4上执行tcpdump -i wan0 host 1.2.3.4 ,并在stream量通过时观察stream量。 我看到SYN出去了,SYN ACK回来了。 几秒钟之后,监狱又一次重试。

我如何允许我的监狱传出连接?

更新
我相信我明白这个问题。 传出数据包从防火墙规则开始,进行NAT转换,允许并logging为外部IP,作为传出连接。 当返回数据包回来时,它会经过翻译,但现在不符合检查状态规则,因为数据包具有内部IP。 仍在寻找解决scheme。

    从地址转换总是在状态规则检查之前发生的问题来看,解决scheme应该是显而易见的。 地址转换需要拆分。

    上面find的规则的更正版本是:

     add 00050 divert natd ip4 from any to any via wan0 in add 00060 check-state # Talking to myself add 00200 allow ip from me to me keep-state # HTTP add 11010 skipto 63000 tcp from any to me http,https setup keep-state add 11011 skipto 63000 tcp from any to me6 http,https setup keep-state # General Network - ICMP add 61001 allow icmp from any to any # Last rule of "normal" traffic add 62000 deny ip from any to any # Only for my outbound and specifically allowed incoming add 63000 divert natd ip from any to any via wan0 out add 63001 allow ip from any to any # XXX last rule is deny everything