鉴于诸多国内关于OpenWRT固件下配置IPv6相关业务资料不够齐全,固件版本不一,现翻译官方示例供学习参考。
1 DHCP与DNS
分配固定静态地址
uci add dhcp host
#基本信息
uci set dhcp.@host[-1].name="mylaptop"#名称
uci set dhcp.@host[-1].dns='1'
uci add_list dhcp.@host[-1].mac="11:22:33:44:55:66"#MAC地址
uci add_list dhcp.@host[-1].mac="aa:bb:cc:dd:ee:ff"#可以多个MAC但是官方认为不可靠
#ipv4
uci set dhcp.@host[-1].ip="192.168.1.23"#IPv4地址
#ipv6
uci set dhcp.@host[-1].duid="000100004fd454041c6f65d26f43"#设备生成,可不填?
uci set dhcp.@host[-1].hostid="23"
#提交更改生效
uci commit dhcp
/etc/init.d/dnsmasq restart
/etc/init.d/odhcpd restart
防火墙开放ipv6端口
vi /etc/config/firewall
#添加内容
config rule
option src 'wan'#入接口
option proto 'tcp'#协议,也可'tcp udp'
option dest 'lan'
option dest_ip '2001:db8:42::1337'#目的设备的IPv6
option dest_port '80'#端口号,范围写作'1024:65535'
option family 'ipv6'
option target 'ACCEPT'#放行
防火墙转发全部流量至局域网,危险慎用!
config forwarding
option src 'wan6'#Wan口的ipv6子接口
option dest 'lan'#全部局域网
防火墙针对动态前缀的主机端口转发规则
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"#尾号23的主机,子网掩码64,此处/-64特殊写法仅可用于OpenWRT防火墙
uci set firewall.@rule[-1].family="ipv6"
uci set firewall.@rule[-1].proto="tcp udp"
uci set firewall.@rule[-1].target="ACCEPT"
uci commit firewall
/etc/init.d/firewall restart
防火墙端口转发,此处官方认为配置方式与IPv4一致,未提供示例。参照IPv4示例:
config redirect
option target DNAT
option src wan
option dest lan
option proto tcp
option src_dport 2222#请求端口
option dest_ip 192.168.10.20#转发至主机
option dest_port 22#转发至端口
option enabled 1
官方提供的测试页面链接