My desktop PC sits on VLAN1 and has a static ipv4 address.
OpenWrt has assigned an ipv6 address:
2a02:x:x:1::190/128
1 = vlan number
190 = last octet of ipv4 static ip address (these are nifty features of OpenWrt IMHO).
The first three parts to the address are the routing prefix, which is assigned dynamically by my ISP.
The fourth part is the subnet ID.
The last four parts are the interface identifier.
The guide contains this example of a firewall rule:
uci add firewall rule
uci set firewall.@rule[-1].name="Forward-IPv6"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest="lan"
uci set firewall.@rule[-1].dest_ip="::23/-64"
uci set firewall.@rule[-1].family="ipv6"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
If I were trying to forward SSH my desktop PC, would this be the correct config?
uci add firewall rule
uci set firewall.@rule[-1].name="Forward-IPv6"
uci set firewall.@rule[-1].src="wan_ipv6"
uci set firewall.@redirect[-1].src_dport="22"
uci set firewall.@rule[-1].dest="lan"
uci set firewall.@rule[-1].dest_ip="1::190/-80"
uci set firewall.@redirect[-1].dest_port="22"
uci set firewall.@rule[-1].family="ipv6"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
You should enter the negative value of the IPv6 assignment length of your LAN interface, in your case /-64.
The subnet is already determined by dest="lan", so that information isn't needed in dest_ip
With IPv6 you don't need NAT, so drop the src_dport
All in all it should look like this:
uci add firewall rule
uci set firewall.@rule[-1].name="Forward-SSH-IPv6"
uci set firewall.@rule[-1].src="wan"
uci set firewall.@rule[-1].dest="lan"
uci set firewall.@rule[-1].dest_ip="::190/-64"
uci set firewall.@rule[-1].dest_port="22"
uci set firewall.@rule[-1].family="ipv6"
uci set firewall.@rule[-1].proto="tcp"
uci set firewall.@rule[-1].target="ACCEPT"
The prefix of 48 means that the ISP chooses the first 48 bits and you control the last 80 bits. So these rules should be written as -80 not -64.
If you only match the last 64 bits, which router or LAN is not considered, and the port is open to any thing on any of your networks (in the lan zone) that ends in ::190. You probably don't want that. Use -80 and include the delegated bits (ip6hint) in the address to match, such as 08::190/-80
Also since there's no NAT in use, the IPv4 concept of "port forward" to use ports to share a single public IP doesn't apply. These are simply forwards. Each server has its own public IP. You can allow input to a single port or all ports.
Would this be the rule to open up port 22 for just my desktop PC?
uci add firewall rule
uci set firewall.@rule[-1].name="Forward-IPv6"
uci set firewall.@rule[-1].src="wan_ipv6"
uci set firewall.@rule[-1].dest="lan"
uci set firewall.@rule[-1].dest_ip="1::190/-48"
uci set firewall.@redirect[-1].dest_port="22"
uci set firewall.@rule[-1].family="ipv6"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
I've performed some tests, and the method from the wiki works as well, provided that the rule only applies to the LAN destination zone with only LAN network assigned to it by default.
This allows to omit the IPv6 hint and specify the length of the prefix assigned to the LAN interface.