Note: A 2022 tutorial on the many aspects of IPv6 can be found in this All Things TECH IPv6 on Linux article.

The Debian Wiki has a web page devoted to IPv6 called the Debian IPv6 Project.
The Ubuntu Wiki has a web page devoted to IPv6 called simply IPv6.

Enabling IPv6

The ipv6 module is loaded by default in Debian 2.6.x and later and in Ubuntu 6.10 and later, so steps (1) and (2) below should not be necessary on these systems. IPv4 will continue to run. You must be logged in as root to make these changes.

The following steps describe the changes needed to enable Internet Protocol version 6 (IPv6) on Debian Linux. Ubuntu is based very closely on Debian, so these directions should work as well for Ubuntu systems, but have not been tested.

If you depend on iptables for securing the system make sure to appropriately apply ip6tables rules. The Enabling IPv6 in ip6tables and other Linux-based Firewalls article in the Security section describes the differences between iptables and ip6tables.

To see if you already have an IPv6 address type the command:

ifconfig.

To get to root on Ubuntu type the command;

sudu -H -s

and enter your user password. To get to root on Debian type the command:

su

and enter your root password.

1) To make sure you have the proper ipv6 support packages installed, type the command:

apt-get install iproute iputils-ping iputils-tracepath

For documentation on using the apt-get command, type the command:

man 8 apt-get.

Other ipv6 related packages can be found by typing the command:

apt-cache search ipv6.

2) To confirm that the ipv6 kernel module is loaded, type the command:

lsmod  |grep ipv6.

2.a) If the module is not loaded, type the command:

modprobe ipv6.

2.b) Add ipv6 to /etc/modules to have the module load at boot time. For documentation on this file’s format, type the command:

man 5 modules.

3) By default, an IPv6 address is configured for all interfaces in Debian using Stateless Address Autoconfiguration (SLAAC). Prior to version 12.04 of Ubuntu, SLAAC was also the default. In version 12.04, privacy addressing became the default for all interfaces.

The default IPv6 address(es) for a system’s network interface(s) can be changed to:

(1) manually assigned (static addressing),
(2) dynamically calculated each time the system boots or reboots (privacy addressing), or
(3) reassigned at any time during system operation using Dynamic Host Configuration Protocol (DHCPv6) (dynamic addressing).

To manually assign static IPv6 address(es), see step 3.a below.
To manually enable privacy addressing, see step 3.b below.
To configure the use of dynamic addressing, see step 3.c below.

3.a) To configure static addressing on a specific interface, edit the /etc/network/interfaces file. Type the command

man 5 interfaces

for documentation on this file’s format. For example:

iface eth0 inet6 static
address 2001:480:230::42
netmask 64
gateway 2001:480:230::1

Proceed to step 4.

3.b) To enable privacy addressing for all network interfaces, add this line to /etc/sysctl.conf

net.ipv6.conf.all.use_tempaddr=2

and restart the system. Privacy addressing will remain in effect on all interfaces until the next system reboot or restart after this line has been changed or removed. Depending on your system release level, the above command may not work properly for network interfaces attached after the initial boot process (USB Network cards or SD-IO and PC-CARD Network interfaces) completes. This bug will eventually be fixed. On such systems, typing the command:

sudo sysctl net.ipv6.conf.all.use_tempaddr=2

after such network interfaces are attached will temporarily enable privacy addresses on them. Again, success depends on your system release level.

To temporarily enable privacy addressing for a specific network interface (for example, ‘eth0’) until the next system boot or reboot, type the commands:

sudo sysctl net.ipv6.conf.eth0.use_tempaddr=2
sudo /etc/init.d/networking restart 

When privacy addresses are enabled, the ifconfig command will often indicate "global temporary dynamic" or "global secondary dynamic" for such addresses.

Proceed to step 4.

3.c) To enable SLAAC for a specific interface on a system where privacy addressing is the default, add this line to /etc/sysctl.conf for that network interface (for example, ‘eth0’) (or change its value if the line already exists):

net.ipv6.conf.eth0.use_tempaddr=0

and then restart the system. SLAAC will not be enabled for that interface until the next system restart. To enable SLAAC for all network interfaces on a system where privacy addressing is the default, add this line to /etc/sysctl.conf (or change its value if the line already exists):

net.ipv6.conf.all.use_tempaddr=0

and then restart the system. SLAAC will not be enabled for any network interfaces until the next system restart. The caveats about system release level mentioned in step 3.b above apply.

Proceed to step 4.

3.d) To configure dynamic addressing requires the installation and configuration of an additional package, such as dibbler. Documentation for dibbler is available here: sourceforge.net/projects/dibbler.

4) The Essential IPv6 for the Linux Systems Administrator presentation discusses additional aspects of enabling IPv6, such as routing and DNS.

5) To restart networking on all interfaces, type the command:

/etc/init.d/network restart

This may disconnect you temporarily as networking reloads. To restart networking for a specific interface, type the commands:

ifdown $IFACE
ifup $IFACE

(where $IFACE is the interface name). For documentation on using the ifdown command, type the command:

man 8 ifdown.

and for documentation on using the ifup command, type the command:

man 8 ifup.

6) To verify that IPv6 is working, type the command:

ping6 -n ipv6.test-ipv6.com

The output should be similar to this:

Pinging ipv6.test-ipv6.com [2001:470:1:18::115] with 32 bytes of data:
Reply from 2001:470:1:18::115: time=687ms
Reply from 2001:470:1:18::115: time=719ms
Reply from 2001:470:1:18::115: time=702ms
Reply from 2001:470:1:18::115: time=700ms

Notes:

The kernel will automatically assign a Scope:link address (fe80:: prefix) to your system. If an IPv6 router is advertising on your network, a Scope:Global address will be assigned if /proc/sys/net/ipv6/conf/*/accept_ra = 1. This can be configured to occur at boot time by editing the /etc/sysctl.conf file, adding the line

net.ipv6.conf.$IFACE.accept_ra = $VAL

and then rebooting, where:

$IFACE can be any interface name on your system, or ‘all’ (for every interface) or ‘default’
        (default settings before interface specific settings are applied).
$VAL can be either 0 (off) or 1 (on).

Autoconfigure addresses can also be configured via /proc/sys/net/ipv6/conf/*/autoconf . Read the article

Documentation/networking/ip-sysctl.txt

in the documentation that comes with the Linux kernel source for more information on these and other kernel configuration options.

Debian has an IPv6 setup page (last updated Feb, 2013) along with an IPv6 Project Page.

Also, checkout the Linux IPv6 HOWTO website.

Disabling IPv6

In Debian/Ubuntu releases built on a 2.6.x or later Linux kernel, IPv6 is enabled by default. This includes Debian 2.6.x and later and Ubuntu 6.10 and later. IPv4 will continue to run. You must be logged in as root to make such changes. To disable IPv6,

1. Edit the file /etc/modprobe.d/aliases.
2. Find the existing line

alias net-pf-10 ipv6

and edit it so that it looks like

alias net-pf-10 off
alias ipv6 off.

3. Write the file, save it, and exit the editor.
4. Restart the system.