Setup IPv6 NAT on OpenWRT Router


This tutorial is a HowTo for setting up IPv6 NAT on OpenWRT router.

The information of the environment is listed below.

Network Environment: China Education and Research Network Center with dual stack IPv6

Network Device: NETGEAR R6100 (128M RAM)

Firmware Version: OpenWrt Chaos Calmer 15.05

Install Dependencies for OpenWRT

Login to OpenWRT router via SSH and run following commands:

opkg update
opkg install ip6tables
opkg install kmod-ipt-nat6
opkg install iputils-tracepath6

Setup IPv6 for Local-area Network

Edit /etc/config/network, and add following lines in config interface 'lan':

option ip6addr 'fc00:192:168:113::1/64'

Remove following lines if exists:

option ula_prefix [IP v6 Address here]

Edit /etc/config/dhcp, and change the content in  config dhcp 'lan' as follows:

config dhcp 'lan'
    option interface 'lan'
    option start '100'
    option limit '150'
    option leasetime '12h'
    option dhcpv6 'server'
    option ra 'server'
    option ra_management '1'
    option ra_default '1'
    option ndp 'hybrid'

Setup Gateway for IPv6 Network

Add following lines to /etc/firewall.user for forwarding IPv6 traffic:

ip6tables -t nat -A POSTROUTING -o $(uci -q get network.wan6.ifname) -j MASQUERADE

Setup up IPv6 gateway by creating file in /etc/hotplug.d/iface/90-ipv6 and adding following lines to the file:

[ "$ACTION" = ifup ] || exit 0
[ "$INTERFACE" = wan6 ] && {             
    route -A inet6 add ::/0 gw $(tracepath6 -n | grep ' 1: ' | awk 'NR==1 {print $2}') dev $(uci -q get network.wan6.ifname)

Then, add execute permission to this file:

chmod 755 /etc/hotplug.d/iface/90-ipv6

Complete Setup

Finishing setting up by restating your router. Then you'll get IPv6 address in your computer.




Contact Us
  • Harbin Institute of Technology, Harbin, China
  • cshzxie [at] gmail [dot] com