How to сonfigure IPv6 in Linux?

(QuickPacket supports IPv6! Get a server from us with promo code PACKETS for 15% off your first invoice)

Internet Protocol version 6 (IPv6) is the latest version of the Internet Protocol (IP) intended to replace IPv4, which still carries more than 96% of the world’s Internet traffic as of May 2014. This article discusses how you can adapt and configure IPv6 in your Linux machines.


IPv6 Address Representation

The 128 bits of an IPv6 address are represented in 8 groups of 16 bits each. Each group is written as 4 hexadecimal digits and the groups are separated by colons (:).

Example: 2001:0db8:0000:0000:0000:ff00:0042:8329

An IPv6 address may be abbreviated to shorter notations by using the following rules where possible:

  • One or more leading zeroes from any group of hexadecimal digits are removed.
  • Consecutive sections of zeroes are replaced with a double colon (::), which can only be used once in an address, as multiple uses would render the address indeterminate. RFC 5952 recommends that a double colon must not be used to denote an omitted single section of zeroes.

See below for applications of these rules:

Initial address                                           2001:0db8:0000:0000:0000:ff00:0042:8329

After removing all leading zeroes                   2001:db8:0:0:0:ff00:42:8329

After omitting consecutive sections of zeroes    2001:db8::ff00:42:8329

 

The loopback address “0000:0000:0000:0000:0000:0000:0000:0001” may be abbreviated to “::1” by using both rules.

As an IPv6 address may have more than one representation, the Internet Engineering Task Force (IETF) has issued a proposed standard for representing them as text.

To display your machine’s current settings, use either of the following commands:

/sbin/ip -6 addr show dev <interface>

OR

/sbin/ifconfig <interface>

Note: IFCONFIG and ROUTE commands are deprecated and replaced by the IP command in Linux.

 

Address Assignment and Deletion

IPv6 has two types of auto-configuration:

  • Stateful auto-configuration is the IPV6 equivalent of DHCP. A new protocol, called DHCPv6 (based closely on DHCP), is used to pass out addressing and service information in the same way that DHCP is used in IPv4. It is called "stateful" because the DHCPv6 server and the client must both maintain state information to keep addresses from conflicting, to handle leases, and to renew addresses over time.
  • Stateless auto-configuration is suitable for small organizations and individuals because it is simpler in that it needs no server to approve the use of an address. With it, a host gains an address via an interface automatically "leasing" it and not requiring the establishment of a server to shell out address space. It allows a host to propose an address, which will probably be unique (based on the network prefix and its Ethernet MAC address) and propose its use on the network. It makes use of the IEEE EUI-64 standard to define the network ID portion of the address.

An IPv6 address consists of 64 bits showing the subnet prefix to which the host is connected and another 64 bits showing the identifier of the host's interface on the subnet. In IPv6 stateless configuration, the identifier need only be unique on the subnet to which the host is connected. This makes it easier for the host to check for uniqueness on its own.

To manually assign an address, use either of the following commands:

/sbin/ip -6 addr add <ipv6address>/<prefixlength> dev <interface>

OR

/sbin/ifconfig <interface> inet6 add <ipv6address>/<prefixlength>


To manually delete an address, use either of the following commands:

/sbin/ip -6 addr del <ipv6address>/<prefixlength> dev <interface>

OR

/sbin/ifconfig <interface> inet6 del <ipv6address>/<prefixlength>

 

Red Hat/CentOS IPv6 Configuration

The following configuration is applicable to Red Hat Enterprise Linux 6. You can configure IPv6 addresses with these files and parameter:

/etc/sysconfig/network-scripts/ifcfg-*

Parameter: IPC6INIT=yes

To add an IPv6 address in Linux, use the following command:

 
IPV6ADDR=<IPv6 address>[/<prefix length>]

Example: IPV6ADDR=fe80::2/64

Note: The prefix is optional.


To add the IPv6 gateway, use the following command:

IPV6_DEFAULTGW=<IPv6 address[%interface]>

Example: IPV6_DEFAULTGW=fe80::1/64


If you want to specify the gateway interfaces as well, you can add it as follows:

IPV6_DEFAULTGW=fe80::1/64%eth0


To add a DNS server, use the following command:


DNS{1,2}=<ip address>

Example:DNS1=fe80::1/64

Note that you cannot set the link-local address of IPv6 manually.

 

Routing Configuration

Start by displaying existing IPv6 routes using the following command:

# /sbin/ip -6 route show [dev <device>]

Example:
# /sbin/ip -6 route show dev eth0
2001:0db8:0:f101::/64 proto kernel metric 256 mtu 1500 advmss 1440
fe80::/10             proto kernel metric 256 mtu 1500 advmss 1440
ff00::/8              proto kernel metric 256 mtu 1500 advmss 1440
default               proto kernel metric 256 mtu 1500 advmss 1440


To add an IPv6 route through a gateway, use the following command:

# /sbin/ip -6 route add <ipv6network>/<prefixlength> via <ipv6address>
¬ [dev <device>]

Example:
# /sbin/ip -6 route add 2000::/3 via 2001:0db8:0:f101::1


To remove an IPv6 route through a gateway, use the following command:

# /sbin/ip -6 route del <ipv6network>/<prefixlength> via <ipv6address>
¬ [dev <device>]

Example:
# /sbin/ip -6 route del 2000::/3 via 2001:0db8:0:f101::1

Note: Doing this is not often needed manually as this is mostly done by network configure scripts on shutdown (full or per interface).

To add an IPv6 route through an interface, use the following command:

# /sbin/ip -6 route add <ipv6network>/<prefixlength> dev <device>
¬ metric 1

Example:
# /sbin/ip -6 route add 2000::/3 dev eth0 metric 1

Notes:

    • Metric “1” is used here to be compatible with the metric used by route because the default metric on using “ip” is “1024”.
    • Though not often needed, this is used in cases of dedicated point-to-point links.


To remove an IPv6 route through an interface, use the following command:

# /sbin/ip -6 route del <ipv6network>/<prefixlength> dev <device>

Example:
# /sbin/ip -6 route del 2000::/3 dev eth0

Note: Though not often needed, configuration scripts will use this on shutdown.

_____________________________________

For more information on interface configuration files, visit this link: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s1-networkscripts-interfaces.html

 

  • 91 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

Advanced Network Troubleshooting: Using traceroute

(Is your server's network not living up to its potential? Order a server from us with promo code...

Advanced Network Troubleshooting: Using Telnet

(Is your server's network not living up to its potential? Order a server from us with promo code...

Advanced Network Troubleshooting: Using My Traceroute (MTR)

(Is your server's network not living up to its potential? Order a server from us with promo code...

Basic Network Troubleshooting

(Is your server's network not living up to its potential? Order a server from us with promo code...

Basic Performance Analysis

(Is your server not living up to its potential? Order a server from us with promo code PACKETS...