It is inevitable that IPv6 addresses are going to eventually take over. When that happens you will need to know just how to assign an IPv6 address in your Linux operating system. Of course this will only be necessary on a system that uses a static IP address, but when you're using Linux that can happen fairly often. Having this knowledge on hand will make this transition seamless.
Of course you will have to have a kernel that is compiled with IPv6 support. Most modern Linux distributions already have this built in. You also have to have your IPv6 addresses handy. I use this simple web-based IPv6 calculator. With that tool select the IPv4 to IPv6 conversion and you should be good to go. So with everything in hand, you are ready to configure.
First make sure your kernel supports IPv6. To do this you can first run the command:
and search the listing to see if ipv6 is there. If not try loading it with the command:
sudo /sbin/modprobe ipv6
Now issue the lsmod command to see if it is there. It should be.
The file you want to configure will be the standard network interface configuration. Remember you are going to configure for static IP addresses. The file in question is /etc/network/interfaces. Most likely this is either not configured (if you are using DHCP) or set up for IPv4. We are going to blow that away now. We are also going to add something to this file that will ensure IPv6 is loaded properly and that your networking us making use of the new address scheme.
The details of our configuration:
IPv4 address: 192.168.1.10
IPv6 Address: 2002:c0a8:10a::
IPv4 gateway: 192.168.1.1
IPv6 gateway: 2002:c0a8:0101::
Now let's add this to the /etc/network/interfaces file. The new file will look like this:
#IPV6 static configuration
iface eth0 inet6 static
pre-up modprobe ipv6
Notice the "pre-up" command. That is where we ensure that IPv6 is added to the kernel, otherwise you run the risk of attempting to use an IPv6 address in a system that is looking for an IPv4 address.
Now you will want to restart networking with the command:
You should now have an IPv6 address enabled.
Before you assume everything is working, let's make sure first. You can check your IP routing with the command:
ip -6 route show
The above command should return something like:
2002:c0a8:0100/64 dev eth0 proto kernel scope link src 2002:c0a8:10a
You can also check by pinging with the ping6 tool. A good IPv6 address to try is the Google address. Issue this command:
If IPv6 isn't working you will get error:
Network is unreachable
If IPv6 is working you will see the standard ping results in your terminal window.
It's only a matter of time before IPv6 is the defacto standard for network addressing. When that happens you do not want to be behind the curve or you'll lose out fast. Make sure you know how to configure your Linux servers for IPv6 static addressing. You'll be glad you do when the time comes.Advertisement
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.