Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:network:ipv6:nat64 [2023/08/08 21:56] – Add note on DNS64+NAT64 in dual-stack network sgryphondocs:guide-user:network:ipv6:nat64 [2024/04/20 15:28] – [Option 1 - Running in the main network namespace] goetz
Line 1: Line 1:
-====== NAT64 for IPv6-only devices ======+====== NAT64 for IPv6-only network (Jool) ====== 
 +{{section>meta:infobox:howto_links#basic_skills&noheader&nofooter&noeditbutton}}
  
-NAT64 (Network address translation from IPv6 to IPv4) is a technology for allowing IPv6-only devices to connect and interoperate with IPv4-only servers on the Internet. It works in conjunction with DNS64, where the DNS returns a specially formatted IPv6 address that encodes the target IPv4 address, which is then handled by NAT64 to forward packets.+See also: 
 +[[docs:guide-user:network:ipv6:ipv6.nat6|NAT66 and IPv6 masquerading]], 
 +[[docs:guide-user:firewall:fw3_configurations:fw3_nat#ipv6_nat|IPv6 NAT and NPT]]
  
-It works much like the NAT44 used by most home networks that forwards packets between IPv4 private address space and IPv4 public address space, except it forwards between IPv6 (public) addresses and IPv4 public addresses.+NAT64 (Network address translation from IPv6 to IPv4) is a technology for allowing an IPv6-only network to connect and interoperate with the IPv4 Internet.
  
-NAT64 is applicable both for IPv6-only networks, where all devices are IPv6-only, and individual IPv6-only devices in a dual-stack network.+It's very similar to the NAT44 used by most home networks that forwards packets between IPv4 private address space and IPv4 public address spaceexcept it forwards between IPv6 (public) addresses and IPv4 public addresses.
  
-NAT64 can be easily activated using [[https://github.com/NICMx/Jool#jool|Jool]].+It works in conjunction with several technologies: 
 +  * DNS64, where the DNS returns a specially formatted IPv6 address that encodes the target IPv4 address, which is then handled by NAT64 to forward packets. 
 +  * [[https://git.openwrt.org/?p=project/odhcpd.git;a=commitdiff;h=c6bff6f1c0fbb37a21a7f54e393615bad22a72d9|PREF64]], where the router advertises in an ICMPv6 Router Advertisement the NAT64 prefix which devices can use to create a CLAT interface (Android, iOS and macOS uses this).
  
-For latest version, OpenWRT 22.03, you can enable the Netfilter version of Jool for NAT64 via one of the following: 
  
-==== From LuCI web console ====+In OpenWrt, NAT64 can be easily activated using [[https://github.com/NICMx/Jool#jool|Jool]].
  
-1. System > Software: Install `jool-tools-netfilter` (this will install `kmod-jool-netfilter` and other dependencies). 
  
-2. System > Startup > Local Startup: Add the following to /etc/rc.local:+===== Two options are possible ===== 
 + 
 + 
 +=== Option 1 - Running in the main network namespace === 
 + 
 +Pros 
 + 
 +  * easy to activate 
 +  * basic integration with the uci configuration system 
 + 
 +Cons 
 + 
 +  * hard to enforce firewall rules 
 +  * translation not available for locally (on the router) generated traffic 
 +  * fights over dynamic port numbers 
 +  * needs to be reconfigured every time the public IPv4 changes 
 + 
 + 
 +=== Option - Running jool in a separate network namespace === 
 + 
 +Pros 
 + 
 +  * easy to enforce firewall rules 
 +  * translation available for all traffic 
 + 
 +Cons 
 + 
 +  * no integration with the configuration system  
 + 
 + 
 +==== Option 1 - Running in the main network namespace ==== 
 + 
 +The following packages need to be installed first:
  
 <code> <code>
-jool instance add --pool6 64:ff9b::/96+# opkg update 
 +# opkg install kmod-jool-netfilter jool-tools-netfilter
 </code> </code>
  
-3. System > Reboot > Perform reboot+==== Jool Configuration Syntax ====
  
-4. Confirm working NAT64 from a device inside your LAN ''ping 64:ff9b::8.8.8.8''+Jool's configuration is split into three configuration files: 
 +  * /etc/config/jool 
 +  * /etc/jool/jool-nat64.conf.json 
 +  * /etc/jool/jool-siit.conf.json
  
-==== Command line ==== +=== /etc/config/jool ===
  
-Using your router command line (e.g. SSH into the device).+This file controls which of the services is enabled (NAT64, SIIT, or both).
  
 <code> <code>
-# Install packages +config jool 'general' 
-opkg update + option enabled '0' 
-opkg install kmod-jool-netfilter jool-tools-netfilter+ 
 +config jool 'nat64' 
 +        option enabled '0' 
 + 
 +config jool 'siit' 
 +        option enabled '0'
 </code> </code>
  
 +=== /etc/jool ===
 +
 +In this folder are the files that actually configures Jool's NAT64 and SIIT modules.
 +
 +The reference for configuring these is in the jools official documentation:
 +  * [[https://nicmx.github.io/Jool/en/config-atomic.html|Jool's configuration examples]]
 +  * [[https://nicmx.github.io/Jool/en/documentation.html|Jool's documentation]]
 +
 +
 +=== Using Jool ===
 +
 +== Basic setup ==
 +
 +After having Jool installed you need to configure it. This is a basic sample configuration that can be used as a template:
 +
 +/etc/jool/jool-nat64.conf.json:
 <code> <code>
-# Add the following line to /etc/rc.local (before the exit 0) +
-jool instance add --pool6 64:ff9b::/96+ "comment": "NAT64 instance configuration.", 
 + "instance": "nat64", 
 + "framework": "netfilter", 
 + "global":
 + "pool6": "64:ff9b::/96", 
 + "maximum-simultaneous-opens": 16, 
 + "source-icmpv6-errors-better": true 
 +
 +
 +</code> 
 + 
 +After saving the configuration you need to enable it: 
 + 
 +<code> 
 +uci set jool.general.enabled="1" 
 +uci set jool.nat64.enabled="1" 
 +uci commit jool 
 +service jool restart
 </code> </code>
  
 +After this configuration, jool should be running. You can test this by pinging an IPv4 address.
 <code> <code>
 # Confirm working NAT64 from a device inside your LAN # Confirm working NAT64 from a device inside your LAN
-ping 64:ff9b::8.8.8.8+ping 64:ff9b::1.1.1.1
 </code> </code>
  
-To check Jool's version, run+ 
 +==== Option 2 - Running jool in a separate network namespace ====  
 + 
 +Inspired and supported by the tutorial IPv6-only/mostly on OpenWrt by Ondřej Caletka (([[https://ripe87.ripe.net/wp-content/uploads/presentations/8-IPv6-mostly_on_OpenWRT.pdf|RIPE87 Tutorial IPv6-mostly on OpenWrt]])). 
 + 
 +The following packages need to be installed first:
  
 <code> <code>
-jool --version+kmod-veth 
 +ip-full 
 +kmod-jool-netfilter 
 +jool-tools-netfilter
 </code> </code>
  
-As of 2022-10-24, the above installs Jool 4.1.6.1, with "(Xtables disabled)".+=== Setup jool network namespace ===
  
-==== Usage ====+Create or copy the following shell script to ''/etc/jool/setupjool.sh''
  
-When using NAT64, in your IPv6 only network, be sure to [[docs:guide-user:base-system:dhcp_configuration#upstream_dns_provider|change]] your DNS to [[https://developers.google.com/speed/public-dns/docs/dns64|Google's DNS64]] or set up your own [[https://github.com/cvmiller/nat64#running-your-own-dns64-server|DNS64]] to correctly resolve domain names into translated addresses.+<code> 
 +#!/bin/sh 
 +ip link add jool type veth peer openwrt 
 +ip netns add jool 
 +ip link set dev openwrt netns jool 
 +ip netns exec jool sh <<EOF 
 +    sysctl -w net.ipv4.conf.all.forwarding=1 
 +    sysctl -w net.ipv6.conf.all.forwarding=1 
 +    sysctl -w net.ipv6.conf.openwrt.accept_ra=2 
 +    sysctl -w net.ipv4.ip_local_port_range="32768 32999" 
 +    ip link set dev lo up 
 +    ip link set dev openwrt up 
 +    ip addr add dev openwrt 192.168.164.2/24 
 +    ip addr add dev openwrt fe80::64 
 +    ip route add default via 192.168.164.1 
 +    modprobe jool 
 +    jool instance add --netfilter --pool6 64:ff9b::/96 
 +    jool global update lowest-ipv6-mtu 1500 
 +    jool pool4 add 192.168.164.2 33000-65535 --tcp 
 +    jool pool4 add 192.168.164.2 33000-65535 --udp 
 +    jool pool4 add 192.168.164.2 33000-65535 --icmp 
 +EOF 
 +</code>
  
-See also: +Make it executable and execute it once. 
-  * [[packages:pkgdata:jool-tools|Jool package information and documentation]] +<code> 
-  * [[https://github.com/openwrt/packages/tree/master/net/jool/files#readme|Jool source code and upstream documentation]] +chmod +x setupjool.sh 
-  * [[http://tools.ietf.org/html/rfc6052|RFC6052]] and [[http://tools.ietf.org/html/rfc6146|RFC6146]] for reference.+</code>
  
-===== DNS64+NAT64 in a dual-stack network =====+Add the following line to ''/etc/rc.local'' through the CLI or Luci UI (''System Startup - Local Startup''), before the ''exit 0''.
  
-In a standard dual-stack network, with regular DNS, an IPv6-only device cannot connect to IPv4-only serves, as it has no access to NAT44.+<code> 
 +/etc/jool/setupjool.sh 
 +</code>
  
-You can enable NAT64 in a dual-stack network, which will allow these devices to use DNS64, and then access the IPv4-only servers. This is useful for testing individual devices (e.g. turn off IPv4 and manually configure DNS).+=== Setup jool interface ===
  
-You can also enable DNS64 for the entire dual-stack network, which will result in all devices that support IPv6 (including dual-stack devices) using NAT64 (because they get a DNS64 result) instead of NAT44This will allow IPv6-only devices to work automatically.+  * use IPv4 subnet 192.168.164.1/24 
 +  * allocate one IPv6 /64 with SLAAC 
 +  * route NAT64 prefix to fe80::64 
 +  * configure ''jool'' firewall zone and forward from ''lan'' zone
  
-**Warning:** Some devices or software may only partially support IPv6. i.e. in a standard dual-stack network they may have some working software (such as a browser), but other software may internally expect IPv4 addresses and so fail if DNS64 is turned on. Example: PlayStation 5 (as at 2023-08-09) mostly works with DNS64 (such as the internet browser), but the PlayStation Store component does not work -- it fails to handle the IPv6 address.+Setup new interface
  
-===== Extras ===== +<code> 
-{{section>meta:infobox:howto_links#basic_skills&noheader&nofooter&noeditbutton}}+config interface 'jool' 
 + option proto 'static' 
 + option device 'jool' 
 + option ipaddr '192.168.164.1' 
 + option netmask '255.255.255.0' 
 + option ip6assign '64' 
 + option ip6hint '64' 
 +</code>
  
-Setting up NAT64 with Jool according to the official package documentation. +Configure DHCPv4 and SLAAC/DHCPv6
-Utilize service and configuration management using conventional OpenWrt means.+
  
-<code bash+<code> 
-# Install packages +config dhcp 'jool' 
-opkg update + option interface 'jool
-opkg install jool-tools-netfilter+ option start '100' 
 + option limit '150' 
 + option leasetime '12h' 
 + option ignore '1' 
 + option ra 'server' 
 + option ra_default '2' 
 +</code>
  
-# Configure NAT64 +Add a static IPv6 route
-cat << EOF > /etc/jool/jool-nat64.conf.json +
-{ "instance": "default",+
-"framework": "netfilter",+
-"global": { "pool6": "64:ff9b::/96" } } +
-EOF +
-uci set jool.general.enabled="1" +
-uci set jool.nat64.enabled="1" +
-uci commit jool +
-/etc/init.d/jool restart+
  
-# Check from a LAN client +<code> 
-ping 64:ff9b::8.8.8.8+config route6 
 + option interface 'jool' 
 + option target '64:ff9b::/96' 
 + option gateway 'fe80::64'
 </code> </code>
 +
 +Add ''jool'' firewall zone
 +
 +<code>
 +config zone
 + option name 'jool'
 + option input 'ACCEPT'
 + option output 'ACCEPT'
 + option forward 'REJECT'
 + list network 'jool'
 +</code>
 +
 +Forward ''lan'' zone to ''jool''
 +
 +<code>
 +config forwarding
 + option src 'lan'
 + option dest 'jool'
 +</code>
 +
 +=== Testing ===
 +
 +After this configuration, jool should be running and the firewall is correctly configured. You can test this by pinging a synthesized IPv4 address.
 +
 +<code>
 +# Confirm working NAT64 from your router
 +ping 64:ff9b::1.1.1.1
 +</code>
 +
 +Make sure it works also from the connected devices
 +- otherwise it might be a routing/firewall issue
 +
 +=== Add forwardings from existing firewall zone to ''jool'' ===
 +
 +e.g., ''lan''
 +
 +<code>
 +config forwarding
 + option src 'lan'
 + option dest 'jool'
 +</code>
 +
 +
 +
 +==== Add PREF64 option to the existing networks ====
 +
 +Option in the Router Advertisement messages carring the NAT64 prefix the network is using.
 +New feature introduced with ''v23.05.0''
 +
 +<code>
 +config dhcp 'lan'
 + option interface 'lan'
 +        ...
 + option ra_pref64 '64:ff9b::/96'
 +</code>
 +
 +
 +==== Configure DNS64 ====
 +
 +In a standard dual-stack network, with regular DNS, an IPv6-only device cannot connect to IPv4-only servers, as it has no access to NAT44.
 +
 +DNS64 comes to fix this, by synthesizing AAAA records from A records. These IPv6 addresses are ranslated by NAT64 (''jool'') to IPv4 addresses.
 +
 +To use DNS64 you can [[docs:guide-user:base-system:dhcp_configuration#upstream_dns_provider|change your DNS]] to [[https://developers.cloudflare.com/1.1.1.1/infrastructure/ipv6-networks/|Cloudflare's DNS64]] [[https://developers.google.com/speed/public-dns/docs/dns64|Google DNS64]] or set up  [[https://github.com/openwrt/packages/blob/master/net/unbound/files/README.md#complete-uci|unbound for DNS64]] to correctly resolve domain names into translated addresses.
 +Cloudflare and Google DNS64 can only be use if you use the well-known NAT64 prefix ''64:ff9b::/96''.
 +
 +==== Become IPv6-mostly ====
 +
 +Android and iOS as well as macOS are working fine in IPv6-only networks.
 +To signal to clients which are able and willing to run IPv6-only, the DHCP option 108 was introduced with RFC8925.
 +
 +Add this option to the DHCPv4 configuration of the desired zone e.g., ''lan''
 +<code>
 +# 30 minutes = 1800 seconds = 0x708 seconds
 +dhcp_option '108,0:0:7:8'
 +</code>
 +
 +After this all your mobile and macOS devices will drop the IPv4 lease and run in IPv6-only mode.
 +
 +
 +==== See also: ====
 +  * [[https://github.com/openwrt/packages/blob/master/net/jool/files/readme.md|Jool source code and documentation]]
 +  * [[http://tools.ietf.org/html/rfc6052|RFC6052]], [[http://tools.ietf.org/html/rfc6146|RFC6146]], [[http://tools.ietf.org/html/rfc7050|RFC7050]] and [[http://tools.ietf.org/html/rfc8925|RFC8925]] for reference.
  
  • Last modified: 2024/06/08 05:52
  • by goetz