Tecmint: Linux Howtos, Tutorials & Guides

A Beginner’s Guide to Configuring IPv4 and IPv6 Addresses in Linux

As a systems administrator, you will occasionally be tasked with configuring or setting up the IP addresses of your servers to keep up with changing network requirements. As such, having fundamental skills in assigning IP addresses and configuring hostname resolution is crucial in ensuring that servers conform with the network topology.

Table of Contents

What is an IP Address?

An IP address, which stands for Internet Protocol , is a unique numerical identifier or address that identifies a device in a TCP/IP network. This could be a local area network ( LAN ) or the internet.

The IP address allows communication between devices in a network such as servers, routers, switches, and any other network device connected to the network.

Difference Between IPv4 vs IPv6

An IP address can be broadly categorized into two: IPv4 and IPv6 .

IPv4 Address

An IPv4 (IP version 4) address is a 32-bit number that is split into four octets, with each octet separated by a period or a decimal point. This is usually referred to as dotted-decimal format.

Each octet is made up of 8 bits which collectively represent a byte. An IPv4 address can further be divided into two sections. The first part represents the network section, while the remaining part defines the host section.

Network Section

The network section of an IP address identifies the class the IP address belongs. There are 3 distinct classes of IP addresses used in computer networks: Class A , Class B , and Class C .

What is IPv4 Class A

In Class A type of network, the first 8 bits (octet) define the network, while the remaining 24 bits are reserved for the hosts in the network.

  • The Public IP addresses range from 1.0.0.0 to 127.0.0.0.
  • The Private IP addresses range from 10.0.0.0 to 10.255.255.255.

Addresses 127.0.0.0 to 127.255.255.255 are reserved for loopback and other diagnostic purposes, and hence are not allocated to hosts in a network.

The default subnet mask of class A is 255.0.0.0 with the first 8 bits used to identify the network. The remaining 24 bits are designated for hosts. This class is used in networks that command a large number of hosts. It yields a maximum of 16,777,214 hosts and 126 networks.

What is IPv4 Class B

In Class B , the first two octets, or 16 bits are used to define the network ID.

  • The Public IP addresses range from 128.0.0.0 to 191.255.0.0.
  • The private IP range is from 172.16.0.0 to 172.31.255.255.

The default subnet mask is 255.255.0.0 where the first 16 bits define the network ID. This class of IP is typically used for medium-large networks and yields 65,534 hosts per network with a total of 16,382 networks.

What is IPv4 Class C

This class of IP is mostly used for small networks such as a home network or a small office or business.

In a Class C network, the first two network bits are set to 1 while the third is set to 0, i.e. 1 1 0. The remaining 21 bits of the first three octets define the network ID, and the last octet defines the number of hosts.

As such, Class C IP address produces the highest number of networks amounting to 2,097,150 , and the least number of hosts per network which is 254 hosts.

  • The public IP addresses range from 192.0.0.0 to 223.255.255.0.
  • The private IP range is from 192.168.0.0 to 192.168.255.255.

The subnet mast is 255.255.255.0.

Host Portion

The remaining section of the IP address is the host portion, which is the section that determines the number of hosts in a network. This part uniquely identifies a host in a network. All hosts in the same network share the same network portion.

For example, the following host IP addresses belong to the same network.

IPv6 Address

An IPv6 address is an alphanumeric address that is 128 bits long, arranged in eight groups, each of which contains 16 bits.

Like an IPv4 address, it is split into two parts: the network and host component. The network part makes up the first 64 bits and is used for routing purposes. The remaining 64 bits identified the address on the nodes.

Below is an example of a full IPv6 address.

This can be further shortened as follows.

IPv6 was developed as a solution to the imminent exhaustion of addresses in IPv4. As you know by now, IPv6 contains 128 bits which is four times more than the number of bits in IPv4 (32 bits). These extra bits provide more addressing space which will supplement the address provided by IPV4.

Although IPv6 is set to take over from IPv4 addressing in the near future, many organizations and ISPs still use and largely rely on IPv4 addresses.

In fact, you’ll hardly ever need to configure an IPv6 on your device to provide connectivity. The fact is, it will take a while before IPv6 replaces or phases out IPv4.

Dynamic (DHCP) and Static IP Configuration

IP allocation on client machines or any end-point devices connected to a network is done either using the DHCP protocol or manual configuration where IP addresses are statically allocated.

DHCP IP Address

DHCP ( Dynamic Host Configuration Protocol ) is a client-server protocol that dynamically allocates IP addresses to client systems on a network. The DHCP server, which in most cases is a router, contains a pool of addresses that it leases out to client devices on a network for a certain period of time. Thus, it simplifies and makes the configuration of IP addresses more efficient. Once the lease time lapses, the client acquires a new IP address.

Most systems, by default, are configured to obtain an IP automatically using the DHCP protocol. This eliminates the possibility of IP conflicts in a network where two devices share the same IP address.

The drawback of DHCP is that the IP addresses change once the lease expires. If a server is set to acquire an IP via DHCP, this will lead to connectivity issues once the IP address changes. And this is where static IP configuration comes in.

Static IP Address

In static IP configuration, IP addresses are manually configured on a client system, especially servers. Unlike dynamically allocated addresses, statically configured IP addresses remain the same and do not change.

However, the static configuration requires a lot of work from network admins. They have to manually log in and configure the static IP along with other details such as subnet mask, DNS servers, and gateway IP. In addition, they need to keep track of all the client systems with static IP addresses.

In this tutorial, we will focus on how to statically configure IP addresses on various systems.

How to Configure IPv4 Networking in Linux

In this section, we will shift focus and see how to configure an IPv4 address on Linux. We will look at how you can do this on Debian , Ubuntu , and later on RHEL and Red Hat distributions .

Configure IPv4 Address on Debian

To get started, it’s always a good idea to check your current IP configuration of the Linux system.

This displays the IP addresses and status of your network interfaces. From the output, we have two interfaces.

Find IP Address in Linux

The first one is the lo interface which is a loopback address reserved for testing purposes only and is always designated the address 127.0.0.1 . The loopback address is not associated with any physical network interface.

The second interface is enp0s3 (this might be different in your case). This is the active network interface that maps to the physical network card on the server.

Its IPv4 address is denoted by the inet parameter, and in this case is 192.168.2.113 , which is assigned via the DHCP protocol.

In Debian, the network configuration is contained in the /etc/network/interfaces file. You can view it using the nano or vim editor .

Debian Network Configuration

To configure a static IPv4 address, remove or comment the allow-hotplug and dhcp lines, Then add the following configuration.

In this configuration, 192.168.2.150 will be our new IPv4 address with a netmask or network subnet of 255.255.255.0. The default gateway, which also happens to be the router’s IP, is 192.168.2.1 while the DNS nameservers are 192.168.2.1 and 8.8.8.8 .

Set Static IP Address in Debian

Save the changes and exit the file.

To apply the changes, restart the networking service.

Then confirm no errors were encountered

Start Network in Debian

To confirm that the server has acquired the new IP, run the following command:

The output below confirms that we have successfully configured the static IPv4 address.

Find IP Address in Debian

Configure IPv4 Address on Ubuntu

In Ubuntu 18.04 and later versions, Netplan is the default network configuration tool, which enables easy configuration of network settings via YAML files. According to Canonical, netplan processes the YAML files and generates network configurations for systemd-network or NetworkManager .

The network configuration file for modern Ubuntu distributions is located in the /etc/netplan directory. For the desktop system, the configuration file in this directory is 01-network-manager-all.yaml . For servers, the file is /etc/netplan/01-netcfg.yaml .

Once again, let’s check our current IP address which is auto-assigned by DHCP.

Our current IP is 192.168.2.106 . We will set this to 192.168.2.180 .

Check IP Address in Ubuntu

To assign an IPv4 address, we will open the network configuration file.

By default, the following lines automatically set the system to use DHCP for IP assignment.

Ubuntu Network Configuration

Add the following lines to assign a static IP.

Set Static IP Address in Ubuntu

Let us break down the parameters used:

  • enp0s3 – is the name of the network interface.
  • addresses – This configures the IPv4 address on the interface. This is followed by the CIDR, in this case,/24 which implies a network subnet of 255.255.255.0.
  • nameservers – This specifies the DNS servers to be used. In this case, we are using 8.8.8.8 and 8.8.4.4 which are Google’s name servers.
  • routes – This sets the gateway on your system.

Remember to replace the interface name and IP configuration to match your network environment.

Save the changes and exit.

To apply the changes made, run the following command:

Once again, verify if the changes have been reflected as shown.

Find IP Address in Ubuntu

Configure IPv4 Address on RHEL

In Red Hat distributions , the nmcli (NetworkManager Command Line Interface) command-line tool is one of the most preferred ways of configuring an IPv4 address. It does so using the NetworkManager service.

To view the network interface name attached to your system, execute the command:

To display the active connection, run the command:

Find Network Interface in RHEL

In RHEL 9 and other Red Hat distributions based on RHEL, the network configuration file resides in the /etc/sysconfig/network-scripts directory. In our case, the configuration file is ifcfg-enp0s3 .

We will assign a static IPv4 address on the interface ‘ enp0s3 ‘ as shown:

To do so, we will run the following commands:

Set Static IP Address in RHEL

The commands save the changes inside the associated network configuration file. You can view the file using your preferred text editor

RHEL Network Configuration

To confirm the new IP address, run the following command

You can also run the nmcli command without any command-line options and the active interface will be displayed at the top.

Find IP Address in RHEL

How to Configure Hostname in Linux

A well-configured system should be able to resolve its hostname or domain name to the IP address configured. Usually, the hostname and IP address mapping is done in the /etc/hosts file.

To configure hostname resolution, add a host’s entry to the /etc/hosts file. This entry includes the host’s IP address and the hostname as shown.

Be sure to update the /etc/hosts file on every Linux system that you intend to connect to the system on the same local network.

Once done, you can successfully ping the hostname of the Linux machine.

Ping Hostname in Linux

In this tutorial, we have covered IPv4 and IPv6 IP addresses and explored how you can configure IPv4 networking and hostname resolution on Linux.

Previous article:

Next article:

Photo of author

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Related Posts

Compile Kernel in Debian

How to Install and Compile Kernel in Debian

Proxmox Create Container

How to Create Containers in Proxmox

Best Debian-based Linux Distributions

The 12 Best Debian-based Linux Distributions

Create VM on Proxmox

How to Create a Virtual Machine in Proxmox

Install TFTP Server on Ubuntu

How to Install and Configure TFTP Server on Ubuntu and Debian

Install Proxmox VE Debian

How to Install Proxmox (Server Virtualization) on Debian 12

8 thoughts on “A Beginner’s Guide to Configuring IPv4 and IPv6 Addresses in Linux”

Ah, it is working like this:

I only have to put into an init script.

I face the following situation: The Internet provider has switched to IPv6.

This means the first 4 blocks, e.g., a02:560:4c19:cd00……. are changing time by time.

The Internet router is able to configure “port forwarding” for IPv6. Indeed, it is not port forwarding, but routing to an IPv6 address in my network.

Unfortunately, the Internet router is not able to route the dynamic part of the IPv6 address of my internal server. I can only configure a fix postfix of the IPv6 address:

let it be: …….. 2001:db8:1234:abcd

While the prefix is changing by the internet provider, the postfix I set it to fix.

To make a service from my internal address available to the internet, I must configure the IPv6 address of my server with the dynamic prefix of the router and the fix postfix configured for routing.

Is it possible to configure it?

Clear, it is a bug in my internet router.

Another way, maybe I will try at the weekend, while the server is getting up, I can call via IPv4 DNS to get the current IPv6 address, put it into the configuration, and restart the network stack.

Title says “Configuring IPv4 and IPv6 Addresses”.

What happened to the “ configure IPv6 section ?”

The pool of IPv4 addresses has already been exhausted so we will have to use IPv6 from now on. I may “hardly ever need to configure an IPv6” but, nevertheless, there WILL be times that I will have to configure IPv6.

It would be handy to know how to do the configuration ahead of time unless IPv6 is self-configuring.

@Dragonmouth,

To assign an IPv6 address temporarily to the network interface, run the following command:

Replace <IPv6_ADDRESS> with the desired IPv6 address, <PREFIX_LENGTH> with the appropriate prefix length and <INTERFACE_NAME> should be replaced with the actual interface name.

For example:

To assign an IPv6 address permanently to the network interface, use the following instructions:

1. Open the configuration file for the desired network interface.

The file name will usually be in the format ifcfg-<INTERFACE_NAME> . For example, if the interface name is eth0 , the file would be ifcfg-eth0 .

Add the following lines to the configuration file.

Restart the network service to apply the changes.

You can confirm your IP address by running ip command.

How to configure IPv6 static IP address using Netplan?

To configure an IPv6 address using Netplan, you can follow these steps:

1. Open the Netplan configuration file using a text editor.

Add the following network configuration to configure an IPv6 address.

In the above example, the interface eth0 is configured with the static IPv6 address 2001:db8:1234:abcd::1 with a prefix length of /64 . The IPv6 gateway is set to 2001:db8:1234:abcd::a .

2. Apply the changes by running the following command:

Thank you, it may help users with old Ubuntu versions.

In newer versions, gateway6 is deprecated.

I don’t think the gateway6 parameter is deprecated in the netplan configuration. Any source you have please share…

Got something to say? Join the discussion. Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Save my name, email, and website in this browser for the next time I comment.

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How do I add an additional IPv6 address to /etc/network/interfaces?

this question How do I add an additional IP address to /etc/network/interfaces? mostly asks what i want except that i want to add more IPv6 addresses in the same interface eth0 without incrementing to eth0.1 and so on. the ifconfig command does IPv6 like ifconfig eth0 add ... so ... how can i add more IPv6 addresses to eth0 ?

Community's user avatar

  • it would be nice if there was a practical way to do a whole /64 –  Skaperen May 1, 2015 at 13:22
  • You can find some information about using a full /64 block on a single host here: serverfault.com/questions/590038/… –  kasperd May 3, 2015 at 15:04

4 Answers 4

It would appear (tested with ifupdown version 0.7.53.1) that we can add several iface eth0 inet6 stanzas to the interfaces file, which is more declarative than the accepted answer. The following code instructs the ifupdown suite to use stateless autoconfiguration and two additional static IPv6 addresses for the eth0 network interface:

Witiko's user avatar

  • 5 This is the "proper" answer - for IPv6 and IPv4! –  Michael Hampton Jul 7, 2016 at 20:50
  • in my case your answer did not work, but the approved one above did work. I am not sure why it might since it is a virtual machine (xen)? –  Sverre Feb 1, 2018 at 13:43
  • It would be useful to know what version of ifupdown you use. Can you look into the manpage of ifconfig? –  Witiko Feb 1, 2018 at 14:31
  • 1 While this works, it may not do what you want with respect to private addressing and router advertisements. See salsa.debian.org/debian/ifupdown/blob/master/inet6.defn for what actually happens. It seems like the order matters here for each of the inet6 statements. It may make sense to have a single auto declaration and then use post-up to add the addresses via ip -6 add and pre-down to remove it. –  AngerClown Jan 14, 2020 at 2:26
  • 2 Props for the dead:beef and c0de:d00d . –  Markus Zeller Aug 25, 2021 at 7:38

In the question you reference, the second answer shows the equivalent solution for IPv4. In the case of IPv6, the /etc/network/interfaces file should contain something like this:

You will need the iproute2 package installed, but you should use ip instead of ifconfig anyway.

For adding a whole /64 to an interface: There are some Q&As in serverfault.se , like " Adding a whole IPv6 /64 block to an network interface on debian " or " Can I bind a (large) block of addresses to an interface? ". Maybe they can help you.

Dubu's user avatar

  • that local block route feature works so all i need to do now is get that added so it puts it back on reboot –  Skaperen May 6, 2015 at 9:25

Here is what I did for multiple v6 addresses in interfaces file. First thing to consider is there cannot be two gateways, so you add a route below the second address.

UndyingThanos's user avatar

I was puzzled, too. But you can just give as many address lines you like. And it works.

Apply without interruption with:

You can also remove addresses this way. No need for ifdown .

You can even use IPv4 addresses to improve readability. For example on ProxMox I map the IPv6 of a VM based on the internal IPv4 of the VM, which gives addresses like:

fd01:7e57::192.168.0.1/64 provided your IPv6 prefix is /64 .

fd12:3456:789a in the example above is from the private IPv6 area fd00::/8 , which is similar to a private net on IPv4 like 10.0.0.0/8 . Replace 12:3456:789a with 40 random bits. This leaves 16 bits for subnets to form a /64 (in IPv6, networks cannot go beyond /64 , so this should always be the biggest address mask you can see on properly IPv6 enabled networks).

RIPE even writes:

Assigning prefixes longer than /56 is strongly discouraged, so your choices are: If you want a simple addressing plan use a /48 for each end-user
  • "Official" (static) allocations from your ISP should give you a /48.
  • Dynamic allocations (from the ISP to your router), usually give you a /56.
  • And internally on our network, you use a /64, so you can split up the /56 into 256 distinct networks for your own needs.

If you see a /64 on your router this does not mean, your ISP is nuts. Many routers default to /64 if not configured otherwise. Usually all ISPs allow routers to request a /56.

So on the other side (Server) you can safely assume, that all IPs which use the same prefix according to /56 come from the same network.

Tino's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged networking server ethernet ipv6 ..

  • The Overflow Blog
  • Would you trust an AI bot to find the fix for vulnerabilities in your code?
  • Who owns this tool? You need a software component catalog
  • Featured on Meta
  • Upcoming privacy updates: removal of the Activity data section and Google...
  • Changing how community leadership works on Stack Exchange: a proposal and...
  • Notifying users about the policy on AU concerning AI-generated content
  • AI-generated content is not permitted on Ask Ubuntu

Hot Network Questions

  • Are flights in fast jet streams more dangerous?
  • How to not fear the supernatural?
  • How to find a "short" walk that visits all vertices of a strongly connected directed graph
  • Distorted QR code generated using \qrcode
  • Which Potentials lead to Kepler's second Law?
  • Can I walk to the Netherlands from Weeze, Germany (NRN)?
  • QGIS: expression in attribute table between greater than and less than with different categories in one field
  • What is the most logical way to have my dragon breathe lightning?
  • How to find the band gap energy value in Quantum ESPRESSO?
  • What was the ‘obvious’ new answer to Asimov’s Pâté de Foie Gras made possible by scientific advance?
  • Based on ranges, for a given number, I want to increment it by another number
  • How do I compute a probability from the MGF?
  • Should long PCB traces be treated as transmission lines?
  • Could Israel's PM Netanyahu be served with an arrest warrant from the ICC for war crimes, like Putin was because of Ukraine?
  • How to "factor out" units?
  • What is this bottom bracket tool called?
  • How to line-break a big equation with a big square root term?
  • Is it legal for a bank to trap you in an ATM vestibule?
  • Effectiveness of Requiring Students to Repeat Proofs Presented in Class
  • Why are there numbers before each paragraph in a complaint in the US?
  • May one eat limb of a living Ben pekuah
  • How to match a pattern only when it is not used as a head?
  • Strings without twin letters
  • Did Ronald Fisher ever say anything on varying the threshold of significance level?

how to assign ipv6 address to interface in linux

Select Your Language

Infrastructure and management.

  • Red Hat Enterprise Linux
  • Red Hat Satellite
  • Red Hat Subscription Management
  • Red Hat Insights
  • Red Hat Ansible Automation Platform

Cloud Computing

  • Red Hat OpenShift
  • Red Hat OpenStack Platform
  • Red Hat OpenShift Container Platform
  • Red Hat OpenShift Data Science
  • Red Hat OpenShift Dedicated
  • Red Hat Advanced Cluster Security for Kubernetes
  • Red Hat Advanced Cluster Management for Kubernetes
  • Red Hat Quay
  • OpenShift Dev Spaces
  • Red Hat OpenShift Service on AWS
  • Red Hat Gluster Storage
  • Red Hat Hyperconverged Infrastructure
  • Red Hat Ceph Storage
  • Red Hat OpenShift Data Foundation
  • Red Hat Runtimes
  • Red Hat JBoss Enterprise Application Platform
  • Red Hat Data Grid
  • Red Hat JBoss Web Server
  • Red Hat Single Sign On
  • Red Hat support for Spring Boot
  • Red Hat build of Node.js
  • Red Hat build of Quarkus

Integration and Automation

  • Red Hat Application Foundations
  • Red Hat Fuse
  • Red Hat AMQ
  • Red Hat 3scale API Management
  • How do I configure a network interface for IPv6?

Environment

  • Red Hat Enterprise Linux 6
  • How do I configure IPv6 IP addressing?
  • How do I do basic IPv6 setup?

You can configure an IPv6 interface with the /etc/sysconfig/network-scripts/ifcfg-* files just like IPv4 addresses.

The following parameter is needed when configuring IPv6:

You can add an IPv6 address with:

  • The prefix is optional.

You can add the IPv6 gateway with:

Or if you want to specify the gateway interfaces as well, you can add it:

You add a DNS server like normal:

Further reading

These options are described in /usr/share/doc/initscripts-*/sysconfig.txt , you can search for "IPV6" to see the relevant options.

We can not set the link local address of IPv6 manually.

Diagnostic Steps

  • Example of ipv6 working with ipv4 in Red Hat Enterprise Linux 7 with NetworkManager.
  • initscripts

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Formatting Tips

Here are the common uses of Markdown.

Request a English Translation

Generating machine translation.

Configure IPv6 Addresses in Linux - /etc/network/interfaces

Learn how to configure IPv6 addresses in Debian with this concise guide. Set up your network interface and enjoy the benefits of IPv6 connectivity.

Check for IPv6 support: Before configuring IPv6 addresses, ensure that your Debian system has IPv6 support enabled. You can verify this by running the following command in the terminal:

If the command returns output with IPv6 addresses, it means IPv6 is supported.

Edit network interface configuration: Open the network interface configuration file using a text editor. The file is usually located at /etc/network/interfaces . For example:

Configure the network interface: Add the following lines to the interface configuration block:

Replace <interface_name> with the name of your network interface, <IPv6_address> with the desired IPv6 address, <IPv6_netmask> with the appropriate netmask, and <IPv6_gateway> with the IPv6 gateway address.

Save and exit the file: After making the necessary changes, save the file and exit the text editor.

Restart the networking service: To apply the changes, restart the networking service using the following command:

Verify the configuration: You can verify the IPv6 configuration by running the ip -6 addr command in the terminal. It will display the assigned IPv6 addresses for your network interface.

Remember to replace <interface_name> , <IPv6_address> , <IPv6_netmask> , and <IPv6_gateway> with the appropriate values specific to your network configuration. Additionally, it's important to consult your network administrator or Internet Service Provider (ISP) for the correct IPv6 settings if you're connecting to an external network.

 A DynDNS Service from IPv64.net

The DynDNS service of IPv64.net is free of charge and usable in all common routers and systems. You have the choice between many different domain names.

  Healthcheck und Monitoring Service

The IPv64.net Healthchecks monitor your services, servers and endpoints. Receive notifications when your services fail. This monitoring service is free with all features.

Register now

Registration with IPv64 is free of charge and immediately available for you.

Our Homelab recommendation

  • Articles Automation Career Cloud Containers Kubernetes Linux Programming Security

Configuring an IPv6 address in Red Hat Enterprise Linux 7 and 8

%t min read | by Valentin Bajrami (Sudoer alumni)

Configuring an IPv6 Address in RHEL 7 and 8

As I mentioned in What you need to know about IPv6 , different methods exist to configure an IPv6 address on a machine. We will mainly focus on configuring an IPv6 address on a Red Hat Enterprise Linux (RHEL) 7 and 8 systems and briefly explain different assignment methods.

[Want to try out Red Hat Enterprise Linux?  Download  it now for free.]

Configuring IPv6 on RHEL 7 and 8

A Red Hat Enterprise Linux system is configured to obtain an IPv6 address automatically. These are the lines in the configuration file where the magic happens (I am adding some explanation to each line):

For more information on what those connection settings do, run:

Stateless address autoconfiguration (SLAAC)

If the IPV6_AUTOCONF variable is set to yes , then the SLAAC method is used to configure the host’s IPv6 address by using the Neighbor Discovery Protocol (NDP) . The technique applied here is the one explained in the previous article’s Multicast section, where there is an exchange of client solicitation and router advertisement ICMPv6 messages.

We use the term stateless because there is no service to keep track of what IPv6 addresses have been assigned to clients. Rather, the IPv6 address is composed with a technique called the Extended Unique Identifier (EUI-64) where 16 bits are added to the Media Access Control (MAC) address (which has 48 bits), thus creating a globally unique IPv6 address.

To use DHCPv6, the following should appear within the configuration file:

If the DHCPv6 variable is set to yes , then a client obtains an IP address from the DHCPv6 pool. The DHCPv6 service then keeps track of what IPv6 addresses are assigned to what clients. Among the IP address, other information like DNS servers, lease time, hostnames, and other attributes are pushed to the client. An administrator must configure the IPv6 address pool to be able to serve clients.

It is also possible (but not recommended) to configure an IPv6 address manually. Manual configuration requires a lot of effort, is error-prone, and it’s hard to keep track of what IPv6 addresses are assigned to what clients. On a large network, a DHCPv6 server is preferable for performing this task.

To configure IPv6 on Red Hat Enterprise Linux 7 and 8 manually, your version of the following needs to added to the configuration file:

Or, you can manually configure through NetworkManager:

Testing IPv6 connectivity

To test IPv6 connectivity, we can run a ping6 on www.redhat.com :

While the ping was running, I ran Wireshark in the background to see what’s happening under the hood. Here is the ICMPv6 request packet (sent by me) and the ICMPv6 reply packet I received back.

ICMPv6 request

Icmpv6 reply.

Note that many organizations choose to block ping requests for security reasons, so it’s generally a good idea to try pinging several sites when testing your connectivity.

Ethernet cables

Valentin Bajrami

Valentin is a system engineer with more than six years of experience in networking, storage, high-performing clusters, and automation. He is involved in different open source projects like bash, Fedora, Ceph, FreeBSD and is a member of Red Hat Accelerators. More about me

Try Red Hat Enterprise Linux

Download it at no charge from the red hat developer program., related content.

A blue cable plugged into a green Raspberry Pi

  • Red Hat Certified Engineer (RHCE) 7 EX300 Study Guide
  • Red Hat Certified System Administrator (RHCSA) 9 EX200 Study Guide
  • Microsoft 70-744 Securing Windows Server 2016 Study Guide

Guides, tutorials, reviews and news for System Administrators.

Configure ipv6 addresses and basic troubleshooting in linux.

In the past many system administrators have simply resorted to disabling IPv6 rather than properly configuring it, continuing to rely on the older IPv4 which has worked just fine for a very long time. As the IPv4 address space has since become exhausted, administrators are starting to slowly take up IPv6 out of necessity.

Here we’re going to cover how to configure IPv6 addressing in Linux and provide some basic tips and advice for troubleshooting IPv6 network issues.

Red Hat Certified Engineer RHCE Video Course

In this example we are working with CentOS 7.

Configuring IPv6 Addresses

IPv6 addresses can be configured in a few additional ways when compared with IPv4, some of these are listed below.

  • Manual Configuration: This is fairly similar to the way IPv4 is manually configured, essentially we manually edit an interface file in the /etc/sysconfig/network-scripts/ifcfg-<interface> format.
  • DHCPv6: Dynamic Host Protocol Version 6 is similar to DHCP for IPv4 in that it will automatically configure our interface.
  • Stateless Address Autoconfiguration (SLAAC): This works similar to DHCP, however it works by receiving router advertisement messages from a local IPv6 router on the network.

Here we will primarily be focusing on manual IPv6 network configuration.

Manual IPv6 Configuration

First take a look in the /etc/sysconfig/network-scripts/ directory to see if there is already existing IPv6 configuration for the particular interface in question. The file name will be listed as ifcfg-<interface>, you can confirm the interface names by running ‘ip a’ or the deprecated ‘ifconfig’. Typical names may include eth0, or the newer ‘eno*’ format such as eno16777736. This file can contain both IPv4 and IPv6 configuration for the same interface.

Below is the configuration of my CentOS 7 /etc/sysconfig/network-scripts/ifcfg-eno16777736 file, note the settings that start with “IPV6”.

  • IPV6INIT=yes – This is needed when configuring IPv6 on the interface.
  • IPV6ADDR=<ipv6-address> – Specifies a primary static IPv6 address.
  • IPV6_DEFAULTGW=<ipv6-address>%eno16777736 – Adds a default route through the interface specified.

Note that if you manually edit these files, you’ll need to run ‘nmcli con reload’ to pickup the changes. Alternatively we can make changes with the nmcli command, which admitedly takes some getting used to, but is quite powerful and its tab autocomplete helps a lot.

The first command sets the IPv6 address, while the second ensures that this is a static address and is not lost from DHCP or SLAAC.

For further information, keep the ‘nmcli-examples’ man page in mind, as there are a number of different examples documented here that you can make use of.

Automatic IPv6 Configuration

Automatic configuration of IPv6 addresses can take place with DHCPv6 or SLAAC. Below is some default configuration from CentOS 7 which has IPV6_AUTOCONF enabled, this configures network settings using SLAAC router advertisements.

Alternatively we can set IPV6_AUTOCONF to no, and define DHCPV6C=yes to use DHCPv6 rather than SLAAC. When using SLAAC or DHCPv6, the manual configuration items such as IPV6ADDR and IPV6_DEFAULTGW can be removed as these will be automatically configured.

For further information on these variables you can check out the documentation in /usr/share/doc/initscripts-*/sysconfig.txt

Applying Network Changes

After making any changes to the files in /etc/sysconfig/network-scripts/ the network needs to be restarted for them to take effect.

You could also perform a system reboot however this will take longer, but will bring the interface up with the new configuration.

Basic IPv6 Troubleshooting

Here are some basic tools you can use to perform basic IPv6 troubleshooting, they work fairly similarly to their IPv4 counterparts.

The ping6 command works in the same way as the normal ping command, except that ping6 works with IPv6 addresses. This can be used to send ICMP traffic to an IPv6 address and check for reply, the below example pings the IPv6 localhost address.

We can also ping out of a specified interface, the below command pings everything connected to eno1677736.

IPv6 Routes

The ‘ip -6 route show’ command can be used to display IPv6 routing.

IPv6 Traceroute

The traceroute6 command can be used to show all hops in the path to the specified destination in the same way as the traceroute command.

The tracepath6 command works in a similar manner.

View Current IPv6 Address Information

You can display current IPv6 configuration by running the ‘ip a’ command which is short for ‘ip address show’. This will show IPv6 interfaces as ‘inet6’ followed by their IP address.

View IPv6 Network Connections

By default the ‘netstat’ command shows both IPv4 and IPv6, however with the -6 option we can select to only display the ports that the server is listening on with its IPv6 addresses as well as any connections.

Configuring IPv6 addresses is not that much different to configuring IPv4 addresses, the main difference is simply the structure of the IP addresses is different. Once you pick up the basics of IPv6 you can easily configure IPv6 networking. Most of the troubleshooting tools are also pretty similar, you can still view the current IP address information, routing tables, and perform pings and traceroutes in a very similar manner.

This post is part of our Red Hat Certified Engineer (RHCE) exam study guide series. For more RHCE related posts and information check out our full RHCE study guide .

Share this:

  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to email a link to a friend (Opens in new window)

5 Comments.

I’d advise to use nmcli rather than edit files manually. For example:

# nmcli c mod eth0 ipv6.method manual ipv6.addresses fc00::a:a:a:10/64

I’ve ended up here looking to figure out how to troubleshoot traceroute6 returning “Network is unreachable”, and ironically in your troubleshooting section, it shows that same response. For references for others who end up here and puzzled, it is (most likely) due to the route to gateway is invalid or not added (or removed). A simple ‘route add -A inet6 default gw {your_local_IPv6_GW} dev {your_iface}’ should do the job to quick fix, though I’m still trying to troubleshoot the root cause of the routing table to not get configured correctly.

Thanks for letting me know, I hope you can sort it out.

I dont prefer using nmcli because in “real job” situations most companys have NM disabled. But for just passing an exam it,s ok…

a good article about IPv6 DHCP

Leave a Comment Cancel reply

NOTE - You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Website URL

Notify me of follow-up comments by email.

Notify me of new posts by email.

Receive new post notifications by email for free! Unsubscribe any time.

Email Address

Recent Posts

  • How To Enable Ping In Windows Server 2022 Firewall
  • How To Enable Remote Desktop In Windows Server 2022
  • How To Install IIS In Windows Server 2022
  • How To Enable Telnet Client in Windows Server 2022
  • How To Fix TP-Link TL-SX1008 Switch Fan Noise
  • Command Examples
  • Exam Guides
  • Uncategorized

Copyright © 2024 RootUsers | Privacy Policy | Terms and Conditions

How to Do IT

Information Technology Explained

how to configure ipv6 address in linux

Step-by-Step Guide: How to Configure IPv6 Address in Linux

how to assign ipv6 address to interface in linux

Table of Contents

Configuring an IPv6 address in Linux is a straightforward process that can be easily accomplished by following these step-by-step instructions.

To configure an IPv6 address in Linux, you can follow these step-by-step instructions:

  • Create an IPv6 VPC: Before configuring an IPv6 address for an instance, create an IPv6 VPC for the instance.
  • Assign an IPv6 address: Assign the IPv6 address to the instance either by assigning a new IP or by using auto-assignment.
  • Enable IPv6 public bandwidth: If you want to provide connectivity over IPv6 to and from the internet, enable IPv6 public bandwidth.
  • Configure an IPv6 address: You can configure an IPv6 address for a network interface controller ( NIC ) of an instance manually or automatically using tools.

For Linux instances, you can automate IPv6 address configuration using the ecs-util-ipv6 tool. First, download the tool using the wget command. Then, make the tool executable using the chmod command. Finally, run the tool using the ./ecs-utils-ipv6 command.

Alternatively, you can configure an IPv6 address for a Linux instance by editing the /etc/sysconfig/network-scripts/ifcfg-eth0 file and adding the necessary configurations. Make sure to configure the IPv6 address, subnet prefix length, and IPv6 gateway.

These instructions should help you configure an IPv6 address in Linux.

Key Takeaways:

  • Creating an IPv6 VPC is a necessary step before configuring an IPv6 address in Linux.
  • Assigning an IPv6 address can be done by assigning a new IP or using auto-assignment.
  • Enabling IPv6 public bandwidth allows for connectivity over IPv6 to and from the internet.
  • The ecs-util-ipv6 tool provides an automated way to configure an IPv6 address on Linux instances.
  • Manually configuring an IPv6 address involves editing the ifcfg-eth0 file and adding the necessary configurations.

Creating an IPv6 VPC

To begin configuring an IPv6 address in Linux, the first step is to create an IPv6 Virtual Private Cloud (VPC) for your instance. The VPC will provide the necessary network infrastructure to support IPv6 address configuration.

To create an IPv6 VPC, follow these steps:

  • Login to your Linux instance and open the terminal .

to initiate the creation process.

  • Specify the VPC name, desired IPv6 CIDR block, and any additional parameters as prompted.
  • Review the configuration details and confirm the creation.

Once the IPv6 VPC is successfully created, you can proceed to assign an IPv6 address to your Linux instance.

Example VPC creation command:

1 sudo vpc-create-ipv6 --vpc-name my-ipv6-vpc --ipv6-cidr-block 2001:0db8:1234::/48 --region us-west-2

By following these steps, you can create an IPv6 VPC and proceed with configuring the IPv6 address on your Linux machine. Stay tuned for the next section on assigning an IPv6 address!

Assigning an IPv6 Address

After creating the IPv6 VPC, the next step is to assign an IPv6 address to the Linux instance. There are two methods to assign an IPv6 address: manual configuration or automated configuration using the ecs-util-ipv6 tool.

Manual Configuration

file using a text editor.

with the desired IPv6 address.

with the desired prefix length (usually 64).

with the IPv6 gateway.

  • Save the file and exit the text editor.

Automated Configuration using ecs-util-ipv6 Tool

To automate the IPv6 address configuration, follow these steps:

  • Download the ecs-util-ipv6 tool using the wget command:
1 wget https://example.com/ecs-util-ipv6
  • Make the downloaded tool executable using the chmod command:
1 chmod +x ecs-util-ipv6
  • Run the tool using the following command:
1 ./ecs-util-ipv6 --apply

These steps should successfully assign an IPv6 address to the Linux instance. Make sure to choose the appropriate method based on your preference and requirements. With the IPv6 address assigned, your Linux machine will be ready to connect and communicate over the IPv6 network.

Enabling IPv6 Public Bandwidth

To establish connectivity over IPv6 with the internet, it is necessary to enable IPv6 public bandwidth on the Linux machine. This can be done by following these steps:

  • Open the terminal and access the Linux machine.
  • Save the changes and exit the text editor.

Once you have completed these steps, IPv6 public bandwidth will be enabled on your Linux machine, allowing for connectivity over IPv6 to and from the internet.

Table: Explanation of Configuration Steps

By following these steps and enabling IPv6 public bandwidth, you can ensure that your Linux machine is ready for connectivity over IPv6 with the internet.

Configuring IPv6 Address Using ecs-util-ipv6 Tool

An efficient method to automate IPv6 address configuration on Linux machines is by using the ecs-util-ipv6 tool. This tool provides a simple and convenient way to configure IPv6 addresses without the need for manual configurations. Follow these steps to configure an IPv6 address using ecs-util-ipv6:

  • Download the ecs-util-ipv6 tool by running the following command:
wget https://example.com/ecs-util-ipv6
  • Make the tool executable by using the chmod command:
chmod +x ecs-util-ipv6
  • Run the tool to configure the IPv6 address:
./ecs-util-ipv6 configure

By following these steps, you can easily automate the configuration of IPv6 addresses on Linux machines. The ecs-util-ipv6 tool simplifies the process and ensures accurate setup without the need for manual intervention.

Benefits of Using ecs-util-ipv6 Tool

There are several benefits to using the ecs-util-ipv6 tool for configuring IPv6 addresses on Linux machines:

  • Automation: The tool automates the entire configuration process, saving time and effort.
  • Accuracy: With the tool, you can be confident that the IPv6 address configuration is done correctly.
  • Simplicity: The tool’s user-friendly interface makes it easy to configure IPv6 addresses, even for beginners.
  • Efficiency: By automating the process, the ecs-util-ipv6 tool ensures efficient IPv6 address configuration.

With the ecs-util-ipv6 tool, configuring IPv6 addresses on Linux machines becomes a hassle-free process. Use this tool and experience the convenience of automated IPv6 address configuration.

Configuring IPv6 Address Manually

Another option to configure an IPv6 address for a Linux instance is to manually edit the necessary configuration file. This method provides more control over the configuration process and allows for specific customization.

To begin, open the

file using a text editor. This file contains the configuration settings for the network interface controller (NIC) of the instance.

Within the file, locate the section that corresponds to the IPv6 configuration. You will need to add the following configurations:

Save the changes and exit the text editor. Finally, restart the network service to apply the new IPv6 configuration to the Linux instance.

Configuring an IPv6 address in Linux is a simple process that can be accomplished by following the step-by-step instructions provided in this guide.

To begin, create an IPv6 Virtual Private Cloud (VPC) for the Linux instance. This ensures a secure network environment for the address configuration.

Next, assign an IPv6 address to the instance. You have the option to either assign a new IP or use auto-assignment. This step is crucial for establishing network connectivity.

If you want to enable connectivity over IPv6 to and from the internet, it’s important to enable IPv6 public bandwidth. This allows for seamless communication with other devices and networks.

There are two ways to configure an IPv6 address for a Linux instance. You can either use the ecs-util-ipv6 tool or manually configure the address. The ecs-util-ipv6 tool provides an automated and efficient way to configure the address, while manual configuration involves editing the necessary files.

By following these instructions, you should be able to successfully configure an IPv6 address in Linux. Enjoy the benefits of IPv6 connectivity and enhance your network capabilities!

How do I configure an IPv6 address in Linux?

To configure an IPv6 address in Linux, you can follow these steps:

  • Create an IPv6 VPC for the instance.
  • Assign an IPv6 address to the instance.
  • Enable IPv6 public bandwidth for connectivity over IPv6 to and from the internet.
  • Configure an IPv6 address for a network interface controller (NIC) of the instance manually or using the ecs-util-ipv6 tool.
  • Alternatively, edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file to manually configure the IPv6 address, subnet prefix length, and IPv6 gateway.

How do I create an IPv6 VPC in Linux?

To create an IPv6 Virtual Private Cloud (VPC) in Linux, follow these steps:

  • Before configuring an IPv6 address, ensure you have created an IPv6 VPC for the instance.
  • Refer to the documentation or guides provided by your network service provider or cloud platform for specific instructions on creating an IPv6 VPC.

How do I assign an IPv6 address in Linux?

To assign an IPv6 address in Linux, follow these steps:

  • Once the IPv6 VPC is created, assign an IPv6 address to the instance.
  • Choose to assign a new IPv6 address or use auto-assignment depending on your requirements and network configuration.
  • Refer to the documentation or guides provided by your network service provider or cloud platform for specific instructions on assigning an IPv6 address.

How do I enable IPv6 public bandwidth in Linux?

To enable IPv6 public bandwidth in Linux, follow these steps:

  • If you want to provide connectivity over IPv6 to and from the internet, enable IPv6 public bandwidth.
  • Refer to the documentation or guides provided by your network service provider or cloud platform for specific instructions on enabling IPv6 public bandwidth.

How do I configure an IPv6 address using the ecs-util-ipv6 tool in Linux?

To configure an IPv6 address using the ecs-util-ipv6 tool in Linux, follow these steps:

  • Download the ecs-util-ipv6 tool using the wget command.
  • Make the tool executable using the chmod command.
  • Run the tool using the ./ecs-util-ipv6 command.
  • Refer to the documentation or guides provided by your network service provider or cloud platform for specific instructions on using the ecs-util-ipv6 tool for IPv6 address configuration.

How do I configure an IPv6 address manually in Linux?

To configure an IPv6 address manually in Linux, follow these steps:

  • Edit the /etc/sysconfig/network-scripts/ifcfg-eth0 file.
  • Add the necessary configurations, including the IPv6 address, subnet prefix length, and IPv6 gateway.
  • Save the file.
  • Refer to the documentation or guides provided by your network service provider or cloud platform for specific instructions on manually configuring an IPv6 address.
  • About the Author
  • Latest Posts

Avatar of Mark

Mark is a senior content editor at Text-Center.com and has more than 20 years of experience with linux and windows operating systems. He also writes for Biteno.com

  • Understanding What is InfluxDB - A Quick Guide
  • What is Aurora AWS: High-Performance Database Solution
  • Exploring SQLite: A Quick Guide to Databases

Similar Posts

Step-by-Step Guide: How to Shutdown Raspberry Pi Remotely in Minutes

Step-by-Step Guide: How to Shutdown Raspberry Pi Remotely in Minutes

Your Guide on How to Install Chrome in Kali Linux Explained

Your Guide on How to Install Chrome in Kali Linux Explained

What is ZFS: Next-Gen File System Explained

What is ZFS: Next-Gen File System Explained

Easy Steps to Change Raspberry Pi Locale: A Guide

Easy Steps to Change Raspberry Pi Locale: A Guide

Understanding Raspberry Pi SD Card Wear Out: A Guide

Understanding Raspberry Pi SD Card Wear Out: A Guide

Unraveling the Mysteries: What is AlmaLinux?

Unraveling the Mysteries: What is AlmaLinux?

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How to get the IPv6 IP address in Linux

I have a Linux server and I want to find the main IPv6 address via one single command line.

My command so far:

which shows:

But I want only one occurrence , so that the output reads:

K7AAY's user avatar

  • write a shell script and put those commands in there: voila, you have now created a "single" command. –  akira Aug 31, 2012 at 17:13
  • 4 When dealing with IPv6 it is not really recommended to limit to a single addresses. There can be multiple global addresses, multiple link-local addresses, multiple site-local addresses... –  u1686_grawity Aug 31, 2012 at 17:25

14 Answers 14

will show your IPv6 addresses.

Jim G.'s user avatar

  • 1 % ip -6 addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 inet6 ::1/128 scope host valid_lft forever preferred_lft forever ... still greppable –  akira Aug 31, 2012 at 17:13
  • 12 This does not solve the stated question. OP wants a single command line to retrieve one IPv6 (which probably means the primary public one). So either ip -6 addr show dev eth0 | sed -n 's|^.*inet6 \([^ ]*/64\).*$|\1|p' or ip -6 addr show dev eth0 | awk '/inet6/{print $2}' could be used as a base and OP can extend/edit them for his specific use case. –  rwenz3l Oct 30, 2018 at 21:04

/sbin/ip -6 addr | grep inet6 | awk -F '[ \t]+|/' '{print $3}' | grep -v ^::1 | grep -v ^fe80

The output of /sbin/ip -6 addr | grep inet6 looks something like this:

awk -F '[ \t]+|/' '{print $3}' splits each line setting delimiters to be either one or more white spaces or a forward slash. The part we need is the $3.

grep -v ^::1 | grep -v ^fe80 to exclude any line starting with ::1 or fe80 .

Qian Chen's user avatar

  • 1 there is way too much piping of grep into awk, this could be collaspe into a single awk ` awk -F '[ \t]+|/' '$3 == "::1" { next;} $3 ~ /^fe80::/ { next ; } /inet6/ {print $3} '` –  Archemar Mar 26, 2016 at 9:02
  • That command outputs nothing on Ubuntu server 20.10 –  Link14 Jan 29, 2022 at 18:09

To get only the IPv6 addresses you use the ip addr command and filter already with -6 for IPv6 addresses only.

If you want to specify a network adapter you might append show dev eth0 while eth0 should be replaced by your network adapter.

Since you are looking only for the external IP address you should add a scope global .

finally you pipe this into your sed command.

LUXS's user avatar

If you want a random selection of one IPv6 address

If you want the IPv6 address of the most common name for the first Ethernet adapter

If you just want the address

RedGrittyBrick's user avatar

Use the following command to view your IP address on Linux :

Normally, Ipv6 address looks like 2001:5c0:9168::/48 . If you are facing any conflict in your IP, follow the below steps to set an IP address again:

  • To assign IPv6 IPs, make sure you have the iproute2 tools installed.
  • Using them, let's start to assign your IPs.
  • Make sure that the ipv6 module installed or not.

Then, use the following command to add new ip:

Afterwards, add default ip via

After completing your installation, just reconfigure/restart your IPv6 enabled services, like Apache, SSH etc.

Malvineous's user avatar

  • 1 ifconfig is obsolete on Linux and should no longer be used. Modern Linux distros don't even install it by default anymore (unless some ancient package requires it). –  Michael Hampton Oct 30, 2018 at 22:47

First, you need to remember that with IPv6 any machine may have several IPv6 addresses, and they may be on separate networks, and any of them might be used, depending on where you want to reach.

So, before you can answer the question of what is your source IP address you have to decide where you're sending the traffic. Then you can just ask Linux to tell you which IPv6 address will be the source when you send traffic to that destination.

If you're sending it to "the Internet" then just pick a global IPv6 address at random, e.g. Google's Public DNS address.

This asks Linux for the route to that destination. Perl parses the result looking for src and then prints the next field.

By providing a different destination, you may receive a different source address:

Michael Hampton's user avatar

I know this is an old question, but no-one has mentioned that ip can produce JSON output which is easy to query:

Avoids all that mucking around with sed/awk/perl/ruby/COBOL/your-text-tool-of-choice. This will always return a global IP6 address if there is one. It's also easy to adapt to other address families and scopes.

Tom's user avatar

  • 1 Good call regarding -json ! Alternative to your version: ip -json -6 addr show enp0s25 scope global | jq -r '.[0].addr_info[0].local' –  Matthias Braun Jul 8, 2023 at 15:28
  • @MatthiasBraun good call - I always forget you can limit scope on the ip commandline. –  Tom Jul 12, 2023 at 8:42

With a few small tweaks, your original attempt would've worked:

The big change there is the addition of the -o flag to causes the entries to be printed out, one per line, which make it easier to run sed over them.

Keith Gaughan's user avatar

Here a way with ip and awk:

Althor49's user avatar

This works on Debian / Raspbian (raspberry OS).

hostname -I returns a line formatted: internal_ipv4 ipv6 the IPs attributed to the current used interface (eventually eth0 or wlan0, I think...). just like the following one, (note: fake numbers for demonstration purposes):

192.168.0.64 2001:8905:6322:8401:a63b:35c1:9d20:9a4a

Then just pick the second column using

cut -d " " -f 2

that is, cut using d elimiter space and choose f ield 2 .

Dave M's user avatar

This returns the IPv6 of the very first used interface:

head -n 2 | tail -1 would return the second and head -n 3 | tail -1 the third result.

mgutt's user avatar

ip -6 a show

is a good and effective way to show all the IPv6 addresses unfortunately including some that are only use locally (loopback)

so a better alternative is to filter some specific scope ('global', 'dynamic' and 'up') :

ip -o -6 a show scope global dynamic up (one per line)

finally, it can be easily grepable with IPv6 pattern matching

ip -6 a show scope global dynamic up|egrep -o '([0-9a-f:]+:+)+[0-9a-f]+'

...or use the -m 1 grep option to keep only the first match

unfortunately it is not necessarily the main one nor the most used address

Finally, to show only the main/preferred interface used, select the mngtmpaddr scope:

ip -6 addr show scope global dynamic mngtmpaddr up|egrep -o '([0-9a-f:]+:+)+[0-9a-f]+'

Cyril Chaboisseau's user avatar

If you want to find the public IPv6 address you can do this with the dig command and then piping this into the sed command to remove the closing quotes.

willowen100's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged linux ipv6 ..

  • The Overflow Blog
  • Would you trust an AI bot to find the fix for vulnerabilities in your code?
  • Who owns this tool? You need a software component catalog
  • Featured on Meta
  • Upcoming privacy updates: removal of the Activity data section and Google...
  • Changing how community leadership works on Stack Exchange: a proposal and...

Hot Network Questions

  • Which Potentials lead to Kepler's second Law?
  • Find the n-th Fibonacci number in O(log n) time
  • Strings without twin letters
  • Optimal Solution for OddsBeforeEvens Wolfram Challenge
  • Is there a word for an object orbiting a brown dwarf?
  • Fingering for left hand accompaniment over two octaves piano
  • Industrial Geothermal smelting power
  • Maximal element w.r.t. abolute continuity of measures
  • My PhD supervisor gave up on me
  • The Devil's Shell Game
  • Writing expressions using permutations versus combinations
  • Is it possible to dynamically refresh journalctl with less?
  • Hiding public IP address while using free DynDns?
  • A co--ection of images
  • will one piece of sod immediately die?
  • Restoring collapsed buried pex line?
  • Is there a no-go theorem for or an upper bound on code threshold?
  • What does cleanliness have to do with vines in John 15?
  • Old romantic horror movie about a guy that fell in love with a girl and later found out she's a ghost
  • How to find the band gap energy value in Quantum ESPRESSO?
  • How do I properly present dialogue in a scene with two female characters?
  • What are the differences between a synagogue and a temple?
  • Can I run wires from separate panels through the same conduit?
  • Valid reason for not having plate armor in early medieval, low-magic fantasy setting?

how to assign ipv6 address to interface in linux

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How can I assign multiple IPv6 addresses with DHCPv6 to a single interface?

This seems to be possible based on the spec rfc 3315 page 23 :

The configuration information in an IA consists of one or more IPv6 addresses along with the times T1 and T2 for the IA. See section 22.4 for the representation of an IA in a DHCP message.

Yet, I haven't been able to configure my DHCPv6 client to request these multiple IP addresses on an interface.

Does anyone know how to do this for a Linux DHCPv6 client (preferably running RedHat 6+, CentOS 6+, or Fedora), or on Windows?

My end goal is to do some testing with PCAP files. I would prefer to be able to generate these files myself, but if I can't get my client configured, I would like to find some PCAP files on the internet that I could use. So far, I haven't found anything.

Community's user avatar

  • 3 My 2 cents: Every DHCPv6 Client I've used so far is notably lacking in feature completeness. I would not be surprised if most do not support requesting multiple IA addresses. –  Chris S May 14, 2014 at 14:10
  • 1 The standard dhclient seems to be supporting multiple addresses already. Did you set DHCPV6C=yes in the network card ifcfg script? –  stoned May 14, 2014 at 16:19
  • If the dhcp client doesn´t support this feature yet, you can add an Interface alias, I don´t know if you al look for this. –  POLLOX May 20, 2014 at 9:54
  • 3 @POLLOX Interface aliases are not supported with IPv6. Instead with IPv6 you can assign multiple addresses directly to an interface. But I have no idea if you can get an DHCPv6 client to do that. –  kasperd May 20, 2014 at 17:17

I haven't tried this, but here's what I think would work:

Use brctl addbr to create a virtual switch. Create two virtual interfaces (with commands like ip tuntap add mode tap ). Then add both tap interfaces and your physical interface to the bridge (e.g. brctl addif tap0 ). Now you have two interfaces on which to run dhcp clients.

TheAmigo's user avatar

  • Interesting, I will look into this. –  Trenin Jun 27, 2014 at 18:01

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged linux dhcp ipv6 pcap ..

  • The Overflow Blog
  • Would you trust an AI bot to find the fix for vulnerabilities in your code?
  • Who owns this tool? You need a software component catalog
  • Featured on Meta
  • Upcoming privacy updates: removal of the Activity data section and Google...
  • Changing how community leadership works on Stack Exchange: a proposal and...

Hot Network Questions

  • Has the Niger junta explained why they expelled French but not US troops?
  • How does EXT4 handle sudden lack of space in the underlying storage?
  • Manager asked for home address without giving a reason. Should I have provided it?
  • Restoring collapsed buried pex line?
  • What were Auguste Comte's contributions to mathematics (if any)?
  • What's wrong with this derivation of the volume of a hemisphere?
  • Fingering for left hand accompaniment over two octaves piano
  • Did Ronald Fisher ever say anything on varying the threshold of significance level?
  • Find the n-th Fibonacci number in O(log n) time
  • Why are there numbers before each paragraph in a complaint in the US?
  • A co--ection of images
  • How to not fear the supernatural?
  • Why is the Map of Earth on the Ringworld?
  • Valid reason for not having plate armor in early medieval, low-magic fantasy setting?
  • Effectiveness of Requiring Students to Repeat Proofs Presented in Class
  • How do I compute a probability from the MGF?
  • My PhD supervisor gave up on me
  • Which Potentials lead to Kepler's second Law?
  • Which type of female connector is this?
  • Why is the SSH server asking for a password even if I specify a valid key?
  • What are the differences between a synagogue and a temple?
  • Confusing use of はじめる and how to "start being something"
  • Median of a set with even number of elements
  • Can I take a gas canister on the MS Sarfaq Ittuk ferry?

how to assign ipv6 address to interface in linux

IMAGES

  1. IPv6 Address Assigning to Linux Interface RHCE

    how to assign ipv6 address to interface in linux

  2. configuration

    how to assign ipv6 address to interface in linux

  3. How to Set-up IPv6 on Ubuntu Linux Server?

    how to assign ipv6 address to interface in linux

  4. Manipulate IPv6 Addresses with ipv6calc

    how to assign ipv6 address to interface in linux

  5. How to Ping IPv6 Address from Windows and Linux CLI

    how to assign ipv6 address to interface in linux

  6. IPv6 on Linux

    how to assign ipv6 address to interface in linux

VIDEO

  1. Understanding IPv4 Addressing

  2. 23- IPv4 Routing

  3. How to configure IPv6 in Linux? (Bangla)

  4. Static IPv4 and IPv6 Configuration

  5. Quickly assignment of IP address in Redhat Linux

  6. HOW TO ASSIGN IP ADDRESS ON MIKROTIK ROUTER INTERFACE

COMMENTS

  1. How to Configure IPv4 and IPv6 Addresses in Linux

    Table of Contents What is an IP Address? Difference Between IPv4 vs IPv6 IPv4 Address Network Section What is IPv4 Class A What is IPv4 Class B What is IPv4 Class C Host Portion IPv6 Address Dynamic (DHCP) and Static IP Configuration DHCP IP Address Static IP Address How to Configure IPv4 Networking in Linux Configure IPv4 Address on Debian

  2. How to configure ipv6 address in Linux (RHEL / CentOS 7/8)

    How to configure ipv6 address in Linux (RHEL / CentOS 7/8) Written By - admin January 2, 2024 Topics we will cover hide Pre-requisite before starting to configure IPv6 address Comparison of nm-setting and ifcfg-* directives Configure IPv6 address using Network Manager. Configure IPv6 address using CLI Modify existing IPv6 configuration

  3. How do I add an additional IPv6 address to /etc/network/interfaces?

    4 Answers Sorted by: 27 It would appear (tested with ifupdown version 0.7.53.1) that we can add several iface eth0 inet6 stanzas to the interfaces file, which is more declarative than the accepted answer.

  4. How do I configure a network interface for IPv6?

    Diagnostic Steps. Example of ipv6 working with ipv4 in Red Hat Enterprise Linux 7 with NetworkManager. This solution is part of Red Hat's fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available ...

  5. Configure IPv6 Addresses in Linux

    sudo nano /etc/network/interfaces Configure the network interface: Add the following lines to the interface configuration block: iface <interface_name> inet6 static address <IPv6_address>/<IPv6_netmask> gateway <IPv6_gateway>

  6. How to change the IPv6 link local address of an interface in Linux?

    1 I want to remove the default IPv6 link-local address of an interface and want to replace it with a customized IPv6 link-local address? Can you help me here? If I assign a new link-local IPv6 address as below, then the interface shows two link-local IPv6 addresses. /sbin/ip -6 addr add fe80::ade1:ac14:1334/64 dev eth0 scope link

  7. Configuring an IPv6 address in Red Hat Enterprise Linux 7 and 8

    IPV6INIT="yes" ← Enable initialization on the interface IPV6_AUTOCONF="yes" ← Accept Router Advertisements (RA's) IPV6_DEFROUTE="yes" ← The default IPv6 route is assigned to the interface IPV6_FAILURE_FATAL="no" ← Opposite of 'may-fail' IPV6_ADDR_GEN_MODE="stable-privacy" ← IPv6 stable-privacy addressing s (RFC7217) NAME="enp1s0" ……… ………

  8. Chapter 6. Configuring IPv6 addresses

    1. Displaying existing IPv6 addresses 1.1. Using "ip" 2. Add an IPv6 address 3.1. Using "ip" 4. Automatic IPv6 Address Configuration 5. Enable Privacy Extension There are different ways to configure an IPv6 address on an interface. You can use use "ifconfig" or "ip". Prev Next Home

  9. 2. Add an IPv6 address

    Add an IPv6 address 3. Removing an IPv6 address

  10. In Linux, how can I automatically assign an IPv6 address to an

    1 @Basil: this isn't going to help you. The network prefix will be the same (you're on the same subnet) and it is much easier to e.g. just take the last part of the IPv4 address and configure that manually. One of my machines is 37.77.56.75, and the IPv6 subnet it is in is 2a00:8640:1:1::/64. This mechanism would give it 2a00:8640:1:1:37:77:56:75.

  11. Configure IPv6 Addresses And Basic Troubleshooting In Linux

    Manual Configuration: This is fairly similar to the way IPv4 is manually configured, essentially we manually edit an interface file in the /etc/sysconfig/network-scripts/ifcfg-<interface> format. DHCPv6: Dynamic Host Protocol Version 6 is similar to DHCP for IPv4 in that it will automatically configure our interface.

  12. 16 Linux ip command examples to configure network interfaces

    1. Show IP Address of all the available interfaces using ip command 2. Show IP Address of individual interface 3. List interfaces based on interface type 4. Check if NIC's link state is enabled or disabled 5. Change NIC's Link state 6. Assign/Add IPv4 and IPv6 address 7. Un-Assign/Delete IPv4 and IPv6 address 8.

  13. Ubuntu Linux Add Static IPv6 Address Network Configuration

    Append configuration as follows: ### Start IPV6 static configuration iface eth0 inet6 static address 2607 :f0d0: 2001 :000a:0000:0000:0000:0010 netmask 64 gateway 2607 :f0d0: 2001 :000a:0000:0000:0000:0001 ### END IPV6 configuration Save and close the file. You can reboot the server or restart networking (Ubuntu server without systemd) service:

  14. Understanding and Configuring Linux Network Interfaces

    In short, we assign a special IP address (127.0.0.1). Here's the format for the declaration of an interface: iface <interface> <address_family> <method> For example, we could declare an interface eth0 and get an IP address dynamically using DHCP: iface eth0 inet dhcp. To configure an interface statically, we follow these steps.

  15. How to assign an IPv6 address to an interface

    June 19, 2017 · milosz · Command-line · Debian Stop running away from this, request and assign an IPv6 address to an external interface to make content available over both IPv4 and IPv6. Assign an IPv6 address to an interface using ip utility. $ ip -6 address add 2A00:0C98:2060:A000:0001:0000:1d1e:ca75/64 dev eth0

  16. Step-by-Step Guide: How to Configure IPv6 Address in Linux

    For Linux instances, you can automate IPv6 address configuration using the ecs-util-ipv6 tool. First, download the tool using the wget command. Then, make the tool executable using the chmod command. Finally, run the tool using the ./ecs-utils-ipv6 command.

  17. How to Configure an IPv6 Address in Ubuntu

    $ sudo vi /etc/network/interfaces

  18. Linux IPv6 HOWTO (en)

    2009-06-11 PB Revision 0.60 2007-05-31 PB Revision 0.51 2006-11-08 PB Abstract The goal of the Linux IPv6 HOWTO is to answer both basic and advanced questions about IPv6 on the Linux operating system. This HOWTO will provide the reader with enough information to install, configure, and use IPv6 applications on Linux machines.

  19. How to get the IPv6 IP address in Linux

    61 I have a Linux server and I want to find the main IPv6 address via one single command line. My command so far: $ ip addr show dev eth0 | sed -e's/^.*inet6 \ ( [^ ]*\)\/.*$/\1/;t;d' which shows: 2001:410:0:39:221:28ff:fe46:eef4 fe80::221:28ff:fe46:eef4 But I want only one occurrence, so that the output reads: 2001:410:0:39:221:28ff:fe46:eef4

  20. linux

    Use brctl addbr to create a virtual switch. Create two virtual interfaces (with commands like ip tuntap add mode tap ). Then add both tap interfaces and your physical interface to the bridge (e.g. brctl addif tap0 ). Now you have two interfaces on which to run dhcp clients. Share.

  21. linux

    4 I am writing a program that needs to set the ip address of an interface and set it UP and RUNNING. I could do it for ipv4 addresses using ioctl (SIOCSIFADDR), but same thing for ipv6 address gives an error. Following is the code snippet: