|
本帖最后由 阿泥基 于 2023-6-4 07:11 编辑
- #!/bin/sh
- ct=$(ifstatus wanct_6 | jsonfilter -e '@["route"][0].source')
- cm=$(ifstatus wancm_6 | jsonfilter -e '@["route"][0].source')
- nft add table ip6 myrule6
- nft create chain ip6 myrule6 srcnat { type nat hook postrouting priority srcnat \; } >>/dev/null 2>&1 || \
- nft flush chain ip6 myrule6 srcnat
- nft add rule ip6 myrule6 srcnat oifname "pppoe-wanct" ip6 saddr != $ct snat ip6 prefix to ip6 saddr map { $cm : $ct } || \
- nft add rule ip6 myrule6 srcnat oifname "pppoe-wanct" ip6 saddr != $ct masquerade
- nft add rule ip6 myrule6 srcnat oifname "pppoe-wancm" ip6 saddr != $cm snat ip6 prefix to ip6 saddr map { $ct : $cm } || \
- nft add rule ip6 myrule6 srcnat oifname "pppoe-wancm" ip6 saddr != $cm masquerade
复制代码
以上是我的IPv6前缀转换脚本,接口名称改成你自己的
22.03以后需要创建脚本文件然后修改防火墙配置,22.03以前的版本(启用了nftables)可以添加到防火墙的自定义规则
向 /etc/config/firewall 添加以下内容
- config include
- option path '/usr/nft-nat6.sh'
复制代码
顺便发下我的DMZ脚本
使用方法同上,也可以转为nft格式
* 由于IPv6前缀转换要通过外部命令获取前缀地址,所以只能使用shell脚本 *
- #!/bin/sh
- nft add table myrule4
- nft create chain myrule4 DMZ { type nat hook prerouting priority dstnat + 5 \; } >>/dev/null 2>&1 || \
- nft flush chain myrule4 DMZ
- nft add rule myrule4 DMZ iifname "pppoe-wanct" tcp dport 1024-65535 dnat ip to 192.168.8.208:1024-65535
- nft add rule myrule4 DMZ iifname "pppoe-wanct" udp dport 1024-65535 dnat ip to 192.168.8.208:1024-65535
- nft add rule myrule4 DMZ iifname "pppoe-wancm" tcp dport 1024-65535 dnat ip to 192.168.8.218:1024-65535
- nft add rule myrule4 DMZ iifname "pppoe-wancm" udp dport 1024-65535 dnat ip to 192.168.8.218:1024-65535
复制代码
如果使用iptables的话,可以把以下规则添加到防火墙的自定义规则
未经测试,不保证效果
- ct=$(ifstatus wanct_6 | jsonfilter -e '@["route"][0].source')
- cm=$(ifstatus wancm_6 | jsonfilter -e '@["route"][0].source')
- ip6tables -t nat -A POSTROUTING -o "pppoe-wanct" -s $cm -j NETMAP --to $ct || \
- ip6tables -t nat -A POSTROUTING -o "pppoe-wanct" -j MASQUERADE
- ip6tables -t nat -A POSTROUTING -o "pppoe-wancm" -s $ct -j NETMAP --to $cm || \
- ip6tables -t nat -A POSTROUTING -o "pppoe-wancm" -j MASQUERADE
- iptables -t nat -A PREROUTING -i "pppoe-wanct" -p tcp --dport 1024:65535 -j DNAT --to-destination 192.168.8.208
- iptables -t nat -A PREROUTING -i "pppoe-wanct" -p udp --dport 1024:65535 -j DNAT --to-destination 192.168.8.208
- iptables -t nat -A PREROUTING -i "pppoe-wancm" -p tcp --dport 1024:65535 -j DNAT --to-destination 192.168.8.218
- iptables -t nat -A PREROUTING -i "pppoe-wancm" -p udp --dport 1024:65535 -j DNAT --to-destination 192.168.8.218
复制代码 |
|