Because the Global Address of br-lan changes, is there any way to dynamically add rules in the form of variables in the /etc/config/firewall file, or can it be done before loading the /etc/firewall.user file What about some alternative preprocessing?
The initial command lacks square brackets around the destination IPv6 address.
Another missing part seems to be a permissive rule for IPv6 DNAT: NAT6 and IPv6 masquerading > Port forwarding
Thank you, but the above methods have failed after testing. The purpose of dynamically creating fw3 rules can be achieved by using variables in the /etc/firewall.user file. But in the end, after testing, it was found that only ip6tables -t nat -A PREROUTING -p tcp -d ::c669/::ffff --dport 8580 -j DNAT --to-destination [230e:139:5586:520::100: c669]:80.
This rule succeeds because a rule like ip6tables -I INPUT -p tcp -d ::c669/::ffff --dport 80 -j ACCEPT
was added to the fw3 rules before. After the rule is deleted, the DNAT rule becomes invalid.
In the Filter table of any input chain, add an allowed record that allows data packets whose state is in the DNAT state, and pay attention to the order of the records. The reason for the previous failure was that this rule was not written, or the rule was wrong. for example:
Port forwarding is also required to the public network, so the sample is not perfect. And the way to add the rule is -A The additional way is easy to appear after the drop rule, and the previous problems appear in these places.
You are using the wrong chains.
The proper chain names are listed in the wiki linked above.
They specifically designed for custom rules and have a fixed position.
It makes the custom rules override the rest in the same zone.
This problem is also mentioned in the firewall config.
The error of the chain is only a few tests of the details, and the problem can be found. The lack of theory is the root of the problem! So it is recommended to improve the sample because most users do not know much about firewalls like me. Regardless of the v4 or v6 era, the need to publish services to the outside world as infrequently used ports is still very large, so I suggest that the v6 port forwarding function can be normalized. For example, it is implemented on Luci and iptables' rule chain.