├── LICENSE ├── README.md └── nat64_start.sh /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## NAT64 on OpenWRT 2 | 3 | An IPv6 to IPv4 protocol translator for OpenWRT Chaos Calmer (15.05.1), LEDE 17.01.02, OpenWrt 18.06.1, and OpenWrt 19.07.x 4 | 5 | ### Why? 6 | 7 | Although running dual stack is the preferred transition method for IPv6, it makes the network more complex, since two protocols need to be run (v4 & v6). A clear way to simplify the network is to only run one networking protocol. Since you will want to migrate to IPv6 eventually, the simple choice is to move to an IPv6-only network. 8 | 9 | ### Creating an IPv6-only network 10 | 11 | It is actually quite easy, just disable the DHCPv4 server on the router. No clients will obtain an IPv4 address, and therefore the client nodes will *have* to use IPv6 to get out. 12 | 13 | ### It is Dark out there 14 | 15 | But you will quickly discover that much of the world's content is still only served on the legacy, IPv4, protocol. This is where **NAT64** comes in. Although it is called NAT (Net Address Translation), it translates from IPv6 to IPv4 and back again, allowing IPv6-only clients to connect to all that legacy connected content. 16 | 17 | ### What is needed? 18 | 19 | An OpenWRT-based router, preferably running the latest release, Chaos Calmer (15.05.1), or LEDE 17.01.02, or the latest OpenWrt (v19.07.x) 20 | * A package from the past **tayga** (for OpenWrt available from 12.09) 21 | * a little configuration, a script to start-up the **tayga** daemon 22 | * Google's DNS64 service. 23 | 24 | - - - 25 | ## UPDATE: January 2021 26 | 27 | THIS SCRIPT is **NO** longer necessary for OpenWrt 28 | 29 | Rather than using `tayga` (below), an easier, more modern software package called **Jool** has been implemented on **OpenWrt v19.07.x**. 30 | 31 | To install Jool: 32 | ``` 33 | opkg update 34 | opkg install kmod-jool 35 | ``` 36 | 37 | To start the Jool NAT64 service: 38 | ``` 39 | /sbin/insmod jool pool6=64:ff9b::/96 40 | ``` 41 | 42 | To make the NAT64 service start when the router is rebooted, add the `insmod` line to your `/etc/rc.local` 43 | 44 | **And you are done!** No need to create config files or change any existing ones. Recommend using `jool` over `tayga` for OpenWrt 19.07.x and newer. 45 | 46 | ## UPDATE: June 2022 47 | 48 | Jool has changed in OpenWrt 21.02.x, and is now at version 5.4.154.x 49 | 50 | To install Jool: 51 | ``` 52 | opkg update 53 | opkg install kmod-jool jool-tools 54 | ``` 55 | 56 | To start the Jool NAT64 service: 57 | ``` 58 | /sbin/modprobe jool 59 | /usr/bin/jool instance add "default" --netfilter --pool6 64:ff9b::/96 60 | /usr/bin/jool global update source-icmpv6-errors-better on 61 | ``` 62 | 63 | Because of the *magic* of `jool` you will need to test the NAT64 functionality from a client attached to the OpenWrt router. You *can not* test NAT64 from OpenWrt itself. 64 | 65 | Recommend putting the lines above into `/etc/rc.local` so your NAT64 service will restart when your router reboots. 66 | 67 | - - - 68 | 69 | ### Getting Tayga for OpenWrt (v15.05) (Old Method) 70 | 71 | The OpenWrt devs dropped the **tayga** package way back in 2012, but fortunately, it still works, *mostly*. My router is a **brcm47xx**-based, you will want to make sure you use the correct architecture for your router. You can find tayga in: 72 | ``` 73 | https://downloads.openwrt.org/attitude_adjustment/12.09/brcm47xx/generic/packages/ 74 | ``` 75 | Download it to your computer, then `scp` it over to your router, preferable the /tmp/ directory (since it is writable). Once it is on the router, update the package list, install the tun device, and then install the `tayga` package with `opkg` 76 | ``` 77 | opkg update 78 | opkg install kmod-tun 79 | opkg install tayga 80 | ``` 81 | 82 | The tayga package will pull in the `ip` package as well, so make sure your router is connected to the internet. 83 | 84 | ### Getting Tayga for LEDE (v17.04) and OpenWrt (v18.06.x & 19.07.x) 85 | 86 | Getting **tayga** for LEDE is even easier, as it is part of the distro, and can be installed directly. 87 | ``` 88 | opkg update 89 | opkg install tayga-xxx.pkg 90 | ``` 91 | Because **tayga** is part of the disto, it will automatically pull in dependencies like the tun kernel module. 92 | 93 | ### Configuring OpenWRT for NAT64 94 | 95 | You will need to edit the /etc/config/network and /etc/config/dhcp files. Add the following to /etc/config/network, which will show the nat64 interface in Luci properly: 96 | ``` 97 | config interface 'nat64' 98 | option proto 'tayga' 99 | option ifname 'nat64' 100 | 101 | ``` 102 | 103 | And edit the /etc/config/dhcp file to include RDNSS pointing to Google's DNS64 server: 104 | ``` 105 | config dhcp 'lan' 106 | option interface 'lan' 107 | option dhcpv6 'server' 108 | option ra_management '1' 109 | option ignore '1' 110 | option ra 'server' 111 | list domain 'mydomain.com' #your search domain 112 | list dns '2001:db8:1d:583:211:24ff:fee1:dbc8' #your internal DNS server 113 | list dns '2001:4860:4860::6464' #Google DNS64 server 114 | ``` 115 | 116 | The DNS servers and search domain will be announced in the RA (Router Advertisement) as well as via DHCPv6. Android/ChomeOS don't do DHCPv6, and Apple/Windows do. **As of April 2017**, Windows 10 can work in a SLAAC-only network, as it now supports the RDNSS field in the RA. 117 | 118 | #### DNS and ip6neigh 119 | If you aren't running an internal DNS server, give some thought to doing so. And it is really easy with [ip6neigh](https://github.com/AndreBL/ip6neigh/) running on your OpenWrt router. It is a project, which *automatically* populates DNS on your router with IPv6 host names, making running a local DNS a snap, and it will make your IPv6 life *much* easier. 120 | 121 | ### Running your own DNS64 Server 122 | 123 | It is easy to use Google's DNS64 server, but you may want to not be tracked by Google, or just want to have a DNS server closer to your network. 124 | 125 | Setting up your own DNS64 server is not all that difficult if you have minimal experience with the ISC DNS server (**bind9**). First step is to install **bind9** using **apt-get** or **yum** (depending on your distro). 126 | 127 | Once **bind9** is installed, edit ` /etc/bind/named.conf.options` file adding the following: 128 | 129 | ``` 130 | // DNS64 config 131 | auth-nxdomain no; 132 | listen-on-v6 { any; }; 133 | allow-query { any; }; 134 | 135 | // set to NAT64 prefix 136 | dns64 64:ff9b::/96 { 137 | clients { any; }; 138 | }; 139 | ``` 140 | 141 | Restart **bind9** and then test with: 142 | 143 | ``` 144 | $ host twitter.com localhost 145 | twitter.com has IPv6 address 64:ff9b::68f4:2ac1 146 | twitter.com has IPv6 address 64:ff9b::68f4:2a41 147 | ``` 148 | 149 | Once you have your own DNS64 server up and running, update the 'list DNS' address in `/etc/config/network` on your router to advertise your DNS64 server. 150 | 151 | #### Running DNS64 on your OpenWrt Router 152 | 153 | You don't need to run a different DNS server, if you aren't already running one for DNS64. You can actually run bind9 (aka `named`) on the OpenWrt router. By doing the following you will have DNS64/NAT64 running all on one router. 154 | 155 | * Install bind9 on the router `opkg install bind-server bind-tools` 156 | * Disable `dnsmasq` on the router, as it conflicts with `named`
157 | `/etc/init.d/dnsmasq disable` 158 | * Apply the bind9 config (above) to `/etc/bind/named.conf` file 159 | * Start the bind9 daemon `/etc/init.d/named start` 160 | 161 | If you have your own DNS server at home, you can point to it using bind-config. at the bottom of `/etc/bind/named.conf` add: 162 | 163 | ``` 164 | // point to your house DNS Domain e.g. myHouseDNS.net 165 | zone "myhousedns.net" IN { 166 | type forward; 167 | forwarders { 168 | // The address of your House DNS server 169 | 2001:db8:8011:fd11::1; 170 | }; 171 | }; 172 | ``` 173 | 174 | Now any DNS requests to your local domain (e.g. myhousedns.net) will be directed to your in-house DNS server, and the rest of the requests, will be served with Synthesized IPv6 addresses (for IPv4-only servers out on the internet). 175 | 176 | After adding your house DNS server forwarding lines, remember to restart `named` with `/etc/init.d/named restart` 177 | 178 | Note: `ip6neigh **does not** work with bind9. 179 | 180 | 181 | 182 | #### Restart networking 183 | 184 | Once the UCI configuration files are edited, restart networking with: 185 | 186 | ``` 187 | /etc/init.d/networking restart 188 | ``` 189 | 190 | 191 | ### A little knowledge 192 | 193 | In a perfect world, the old version of tayga would read the UCI configuration file, and be started. Alas, it is from a past release, and for some reason doesn't read the UCI config. So we'll use a script to setup and start `tayga`. This is a little hack to get NAT64 up and running on OpenWrt & LEDE Routers (15.05 thru to the cutrent 19.07.x). 194 | 195 | But before we run the script, we need to know what is the WAN interface? Usually `eth1` or `eth0.2` 196 | 197 | You can find this by looking at `ip addr` on your router and seeing what interface has the outside/public IPv4 address. 198 | 199 | As of version 1.1, the `nat64_start.sh` will automatically detect your `WAN` interface, except for PPPoE WANs. 200 | 201 | ### Starting tayga 202 | 203 | `scp` the `nat64_start.sh` script to the router, and store it in /root, so it will be there on the next reboot. 204 | 205 | Run the nat64_start.sh script. If using PPPoE for your ISP connection, then feed the PPPoE WAN interface via a command line parameter `-w`, and sit back and let the script to its work. 206 | ``` 207 | /root/nat64_start.sh -w eth0.2 208 | === Check that WAN interface is present and up 209 | UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 210 | === Collected address info: 211 | === WAN4 107.190.20.37 212 | === WAN6 2001:470:ebad::221:29ff:fec3:6cb0 213 | === LAN6 2001:470:ebad:8::1 214 | === NAT64 Prefix 64:ff9b::/96 215 | killall: tayga: no process killed 216 | === Making tun device: nat64 217 | Created persistent tun device nat64 218 | === Testing tayga 219 | PING 64:ff9b::8.8.4.4 (64:ff9b::808:404): 56 data bytes 220 | 64 bytes from 64:ff9b::808:404: seq=0 ttl=54 time=16.104 ms 221 | 64 bytes from 64:ff9b::808:404: seq=1 ttl=54 time=15.813 ms 222 | 64 bytes from 64:ff9b::808:404: seq=2 ttl=54 time=16.953 ms 223 | 224 | --- 64:ff9b::8.8.4.4 ping statistics --- 225 | 3 packets transmitted, 3 packets received, 0% packet loss 226 | round-trip min/avg/max = 15.813/16.290/16.953 ms 227 | Pau! 228 | 229 | ``` 230 | 231 | ### Testing NAT64 232 | 233 | At the end of the script, it will ping6 Googles IPv4 DNS server 8.8.4.4. If you see echo returns, then NAT64 is up and running, congratulations! Enjoy the simplicity of an IPv6-only network, and all the legacy attached content. 234 | 235 | ### Rebooting with NAT64 236 | 237 | If you want NAT64 to be up and running the next time you reboot the router, you will need to add it to the start up items in Luci under System->Startup (at the bottom). Add the following **before** the `exit 0`: 238 | ``` 239 | # Start tayga NAT64 daemon 240 | /root/nat64_start.sh 241 | 242 | ``` 243 | For those who prefer CLI, add the above two lines to `/etc/rc.local` 244 | 245 | Now when your router reboots, NAT64 will be automatically enabled! 246 | 247 | - - - 248 | ### Background info 249 | 250 | #### So how does NAT64 work? 251 | 252 | **NAT64** relies on **DNS64** to provide a *fake* address to the client when it requests a DNS lookup. The *fake* address starts with the prefix `64:ff9b::/96` and the last 32 bits of the address are actually the IPv4 address of the DNS Query. 253 | 254 | The client (e.g. your laptop) then attempts to open a connection to the *fake* address, which your router will pickup, *see* the real IPv4 address embedded, and make a connection to the legacy connected site. It reverses the process for any data returned by the legacy connected site. 255 | 256 | You don't have to use Google's **DNS64** service, you can roll your own, but that is beyond the scope of this little nat64 start script. (see *Running your own DNS64 server* for more info) 257 | 258 | #### More info about tayga 259 | 260 | If you wish to know more about `tayga` please look at the official [tayga website](http://www.litech.org/tayga/). 261 | 262 | ### Limitations 263 | 264 | Dang those Limiations! 265 | 266 | It has been called to my attention that the forked project, LEDE, of OpenWrt does **not** support the older OpenWrt packages. Fortunately, the LEDE Dev team have ported **tayga** package. However it still requires some setup to run, and the `nat64_start.sh` script has been updated to support LEDE routers as well as OpenWrt. Update 2018: As OpenWrt and LEDE re-merge, this script has been tested to ensure it works with version of OpenWrt 18.04 & 19.07 267 | 268 | Some Topologies do not use a WAN GUA (Global Unique Address), and instead relay on link-local. This is also a correct topology. As of version 1.0, the script has been updated to support non-GUA-WAN topologies. 269 | 270 | 271 | 272 | ### About the Script Author 273 | 274 | Craig Miller has been an IPv6 advocate since 1998 when he then worked for Bay Networks. He has been working professionally in Telecom/Networking ever since. Look for his other OpenWRT projects, [v6 Brouter](https://github.com/cvmiller/v6brouter) a script to extend a /64 network (when upstream won't give you your own /64), [v6disc](https://github.com/cvmiller/v6disc) an IPv6 discovery script, and running a [Virtual OpenWrt in a Linux Container LXD](https://github.com/cvmiller/openwrt-lxd). 275 | 276 | 277 | 278 | 279 | 280 | -------------------------------------------------------------------------------- /nat64_start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ################################################################################## 4 | # 5 | # Copyright (C) 2016 Craig Miller 6 | # 7 | # See the file "LICENSE" for information on usage and redistribution 8 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. 9 | # Distributed under GPLv2 License 10 | # 11 | ################################################################################## 12 | 13 | 14 | # 15 | # Script to start tayga (NAT 64) server on OpenWRT 16 | # 17 | # Craig Miller 9 July 2016 18 | # 19 | 20 | # 21 | # Define interfaces 22 | # 23 | # get WAN interface from UCI 24 | WAN=$(/sbin/uci get network.wan.ifname) 25 | WAN6="" 26 | 27 | # Define files 28 | tayga_conf="/etc/tayga.conf" 29 | 30 | # Devine Vars 31 | NAT64_PREFIX="64:ff9b::/96" 32 | #NAT64_PREFIX="2001:470:ebbd:ff9b::/96" 33 | 34 | # script version 35 | VERSION=1.2 36 | 37 | 38 | usage () { 39 | # show help 40 | echo "help is here" 41 | echo " $0 - sets up tayga.conf, creates tun device, and starts tayga (NAT64)" 42 | echo " -w WAN interface of the router, typically eth1 or eth0.2 or pppoe_WAN_DSL" 43 | echo " -6 IPv6 WAN interface, if different from above" 44 | echo " -h this help" 45 | echo " " 46 | echo " By Craig Miller - Version: $VERSION" 47 | exit 1 48 | } 49 | 50 | 51 | 52 | # default options values 53 | DEBUG=0 54 | numopts=0 55 | # get args from CLI 56 | while getopts "?hdw:6:" options; do 57 | case $options in 58 | w ) WAN=$OPTARG 59 | numopts=$((numopts+2));; 60 | 6 ) WAN6="$OPTARG" 61 | numopts=$((numopts+2));; 62 | d ) DEBUG=1 63 | numopts=$((numopts+1));; 64 | h ) usage;; 65 | \? ) usage # show usage with flag and no value 66 | exit 1;; 67 | * ) usage # show usage with unknown flag 68 | exit 1;; 69 | esac 70 | done 71 | 72 | # remove the options as cli arguments 73 | shift $((numopts)) 74 | 75 | # check that there are no arguments left to process 76 | if [ $# -ne 0 ]; then 77 | usage 78 | exit 1 79 | fi 80 | 81 | # if no IPv6 WAN interface specified, use the normal WAN interface 82 | if [ -z "$WAN6" ]; then 83 | WAN6="$WAN" 84 | fi 85 | 86 | echo "=== Check that WAN interface is present and up" 87 | i=0 88 | max=5 89 | result=1 90 | while [ $result -ne 0 ] 91 | do 92 | i=$((i+1)) 93 | if [ $i -gt $max ]; then 94 | echo "=== Is $WAN the correct WAN interface?" 95 | # exit the script 96 | exit 1 97 | fi 98 | 99 | # is $WAN present and UP? 100 | ip link show dev "$WAN" | egrep 'state UP|UP,LOWER_UP' 101 | result=$? 102 | 103 | 104 | # sleep if not invoked from terminal 105 | if [ ! -t 1 ]; then 106 | sleep 10 107 | fi 108 | done 109 | 110 | 111 | 112 | # get some IP addresses from Router 113 | i=0 114 | max=6 115 | while [ $i -lt $max ]; do 116 | i=$((i+1)) 117 | 118 | # Are all required IP addresses available? 119 | LAN_IP6=$(ip -6 addr | grep '::1/' | grep 'global' | grep -v 'deprecated' | grep -v 'inet6 fd' | awk '{print $2}' | cut -f 1 -d '/' | tail -1) 120 | WAN_IP4=$(ip -4 addr show dev "$WAN" | grep 'inet' | awk '{print $2}' | cut -f 1 -d '/') 121 | WAN_IP6=$(ip -6 addr show dev "$WAN6" | grep -v 'deprecated' | grep 'global' | grep -v 'inet6 fd' | head -1| awk '{print $2}' | cut -f 1 -d '/') 122 | if [ -n "$WAN_IP4" ] && [ -n "$WAN_IP6" ] && [ -n "$LAN_IP6" ]; then 123 | break 124 | fi 125 | 126 | # sleep if not invoked from terminal 127 | if [ ! -t 1 ]; then 128 | echo "Waiting for IP address..." 129 | sleep 10 130 | fi 131 | done 132 | 133 | echo "=== Collected address info:" 134 | echo "=== WAN4 $WAN_IP4" 135 | echo "=== WAN6 $WAN_IP6" 136 | echo "=== LAN6 $LAN_IP6" 137 | echo "=== NAT64 Prefix $NAT64_PREFIX" 138 | 139 | # test no GUA on WAN 140 | #WAN_IP6="" 141 | 142 | 143 | # check that the addresses have been collected 144 | if [ -z "$LAN_IP6" ]; then 145 | echo "ERROR: LAN GUA IPv6 not detected. NAT64 requires end to end IPv6 connectivity" 146 | exit 1 147 | fi 148 | if [ -z "$WAN_IP6" ]; then 149 | echo "WARNING: WAN GUA IPv6 not detected. NAT64 requires end to end IPv6 connectivity, NAT64 may not work properly" 150 | #exit 1 151 | fi 152 | if [ -z "$WAN_IP4" ]; then 153 | echo "ERROR: WAN GUA IPv4 not detected. NAT64 requires WAN IPv4 connectivity" 154 | exit 1 155 | fi 156 | 157 | 158 | # remove old NAT64 firewall entries 159 | iptables -D forwarding_rule -i nat64 -j ACCEPT 160 | ip6tables -D forwarding_rule -o nat64 -j ACCEPT 161 | 162 | 163 | # tayga info from tayga website http://www.litech.org/tayga/ 164 | 165 | # kill any existing tayga to clean up 166 | killall tayga 167 | 168 | # make tayga db dir 169 | msg=$(mkdir -p /tmp/db/tayga 2>&1) 170 | 171 | # create tayga config file 172 | msg=$(mv $tayga_conf $tayga_conf.old 2>&1) 173 | 174 | touch $tayga_conf 175 | echo "tun-device nat64" >> $tayga_conf 176 | echo "ipv4-addr 192.168.2.1 " >> $tayga_conf 177 | echo "prefix $NAT64_PREFIX " >> $tayga_conf 178 | echo "ipv6-addr $LAN_IP6" >> $tayga_conf 179 | echo "dynamic-pool 192.168.2.0/24" >> $tayga_conf 180 | echo "data-dir /tmp/db/tayga" >> $tayga_conf 181 | 182 | if [ $DEBUG -eq 1 ]; then echo "=== tayga.conf file"; cat $tayga_conf; fi 183 | 184 | # configure tun interface and start tayga 185 | echo "=== Making tun device: nat64" 186 | tayga --mktun 187 | ip addr flush nat64 188 | ip link set nat64 up 189 | 190 | # clear nat64 dynamic map 191 | [ -s /tmp/db/tayga/dynamic.map ] && rm /tmp/db/tayga/dynamic.map 192 | 193 | ip addr add "$WAN_IP4" dev nat64 194 | #ip addr add "$WAN_IP6" dev nat64 195 | #ip addr add "192.168.2.1" dev nat64 196 | #ip addr add $LAN_IP6 dev nat64 197 | ip route add 192.168.2.0/24 dev nat64 198 | ip route add $NAT64_PREFIX dev nat64 199 | 200 | # add NAT64 firewall entries (required for LEDE) 201 | iptables -A forwarding_rule -i nat64 -j ACCEPT 202 | ip6tables -A forwarding_rule -o nat64 -j ACCEPT 203 | 204 | # start NAT64 205 | tayga & 206 | 207 | # test connection 208 | echo "=== Testing tayga" 209 | NAT64_FRONT=$(echo $NAT64_PREFIX | cut -d '/' -f 1) 210 | ping6 -c3 $NAT64_FRONT"8.8.4.4" 211 | 212 | echo "Pau!" 213 | 214 | 215 | 216 | 217 | --------------------------------------------------------------------------------