我有一个没有ipv6堆栈和NAT内的Linux主机的Linux路由器。 如何使用iptables在NAT路由器和主机之间来回转发6to4stream量,然后使用路由器的公用IPv4地址在主机上configuration6to4隧道?
这个配方(在路由器上)得到一个ipv6 ping到主机的eth0,但是它们没有到达tun6to4接口。 Wireshark将“ICMP Destination unreachable(Port unreachable)”作为对6to4 ping的ipv4响应。
# inbound destination NAT for IPv6 tunnel. ppp0 is router's WAN interface. iptables -t nat -A PREROUTING -i ppp0 -p 41 -j DNAT --to 192.168.1.100 # inbound forwarding for IPv6 tunnel iptables -t filter -A FORWARD -i ppp0 -p 41 -d 192.168.1.100 -j ACCEPT
我在Linux主机上使用这个脚本,传递路由器的公共IP地址:
#!/bin/bash ### Get the global IPv4 address for your host from the command line: GLOB_IP4=$1 ### Compute the 6TO4 tunnel IPv6 address: GLOB_IP6TO4=$(printf "2002:%02x%02x:%02x%02x::1" $(echo $GLOB_IP4 | tr . ' ')) ### Setup the tunnel ip tunnel add tun6to4 mode sit remote any local $GLOB_IP4 ttl 64 ip link set dev tun6to4 up ip addr add $GLOB_IP6TO4/16 dev tun6to4 ip route add 2000::/3 via ::192.88.99.1 dev tun6to4 metric 1
iptables -t nat -A PREROUTING -d 192.0.2.75 -p 41 -j DNAT --to 10.0.0.2在路由器上应该做的伎俩,假设所有的stream量是从外部启动到您的IP地址(给作为192.0.2.75在这个例子中)。 如果你的支持IPv6的盒子启动了,那么常规的SNAT规则应该可以做到。
秘密酱汁
我以为本地隧道地址会影响6to4封装,将不得不成为我的全球IPv4地址。
ip tunnel add tun6to4 mode sit remote any local $GLOB_IP4 ttl 64
它必须是主机的地址,在我的情况下是192.168.1.100。 留下一切相同的,它的作品!
可悲的是,在互联网和nat后面的linux机器之间有一个linux路由器时,这是不可能完成的。
正如iptables手册所述:
DNAT
该目标仅在nat表,PREROUTING和OUTPUT链以及仅由这些链调用的用户定义链中有效。 它规定了数据包的目标地址应该被修改(并且在这个连接中的所有将来的数据包也将被修改),规则应该停止检查。 它需要一种选项:–to-destination ipaddr [-ipaddr] [:port-port],它可以指定一个新的目的地IP地址,一个包含的IP地址范围,以及一个可选的端口范围如果规则还指定-p tcp或-p udp,则为有效)
只有在协议是TCP或UDP的情况下,才能将“-j DNAT – ”设置为“不能与协议41(6to4)协同工作。