Assign IPv6 addresses in Linux

Jack Wallen
Jul 8, 2009
Updated • Nov 30, 2012

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:

sudo lsmod|less

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:

IPv6 Address: 2002:c0a8:10a::

IPv4 gateway:

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
address 2002:c0a8:10a::

netmask 64
gateway 2002:c0a8:0101::

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:

/etc/init.d/networking restart

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.

Final thoughts

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.


Previous Post: «
Next Post: «


  1. saurav said on February 17, 2011 at 9:00 am

    The IPv6 address assigned in linux Os with following command:
    Command: ip(8)

    Add the following command into ur /root/.bashrc file
    run the bashrc file
    ip -6 addr add 2001:db8:0:66::130/64 dev eth0
    ip -6 route add 2000::/3 dev metric 1

    Note:where the 2001:db8:0:66::130/64 is the IPv6 addr of my machine
    Thats it needed to enable IPv6 address of ur Linux OS

  2. Paul said on July 10, 2009 at 6:17 pm

    There’s nothing wrong with the generator, you’re just misusing it. An RFC1918 IPv4 address should not be used to generate a 6to4 address; it doesn’t make any sense. Addresses of that form contain no information describing how the packets should be routed to your network.

    It’s as if I mailed you a letter with a destination address of “Jack’s Living Room”

  3. jack said on July 10, 2009 at 3:23 pm

    Paul: This tutorial wasn’t about generating IPv6 addresses…it was about how to assign an address to a linux system. If the addresses are incorrect, they are incorrect from the address generator i used.

  4. thedude said on July 9, 2009 at 3:08 pm


  5. Paul said on July 9, 2009 at 4:57 am

    This tutorial is mostly wrong. First, you can’t generate an IPv6 prefix by concatenating 2002:[private IPv4 address]. There’s no way that will be globally unique.

    Second, if you put your hosts on different /64s, they won’t be able to talk to each other.

    Third, you’ve provided no means by which the hosts can communicate to the external world. This setup will never let you ping, or any other site on the Internet.

    Your IPv6 prefix should either be:
    1. Assigned by your ISP, or a tunnel broker.
    2. A 6to4 address, calculated from your global IPv4 address.
    3. A unique-local address, starting with “fd”. This one won’t let you access external sites.

    In summary, I suggest you figure out what you’re talking about before sharing the knowledge with others.

  6. Debian Rules said on July 8, 2009 at 1:36 pm

    Nice howto.

    Don’t forget to install IPv6 tools and config ipv6-ish firewall

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.