Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get IPV6 address on my linux box. I know one command to get the IPV6 address.


$ ip addr show dev eth0 | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d'



But issue is that I want only one occurrence that means only 2001:410:0:39:221:28ff:fe46:eef4 by single command.

share|improve this question
write a shell script and put those commands in there: voila, you have now created a "single" command. – akira Aug 31 '12 at 17:13
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... – grawity Aug 31 '12 at 17:25
ip -6 addr

will show your IPv6 addresses.

share|improve this answer
% 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 '12 at 17:13
$ /sbin/ifconfig | grep inet6
      inet6 addr: fe80::2ff:19ff:fe60:1a00/64 Scope:Link
      inet6 addr: fe80::211:22ff:fe33:4455/64 Scope:Link
      inet6 addr: ::1/128 Scope:Host

If you want a random selection of one IPv6 address

$ /sbin/ifconfig | grep inet6 | head -n 1
      inet6 addr: fe80::2ff:19ff:fe60:1a00/64 Scope:Link

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

$ /sbin/ifconfig eth0 | grep inet6
      inet6 addr: fe80::2ff:19ff:fe60:1a00/64 Scope:Link

If you just want the address

$ /sbin/ifconfig eth0 |  awk '/inet6/{print $3}'
share|improve this answer

/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:

inet6 ::1/128 scope host 
inet6 2001:123:456:55f::1/64 scope global 
inet6 fe80::62eb:69ff:fed2:d2a6/64 scope link 

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.

share|improve this answer
This would be more useful if you could expand your answer to explain what the code does. Thanks. – fixer1234 Mar 25 at 17:02
@fixer1234 sure. I have updated my answer. – Elgs Qian Chen Mar 25 at 17:09
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 at 9:02

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




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

  1. To assign IPv6 IP addresses, make sure you have the iproute2 tools installed.
  2. Using them, let's start assign your IPs.
  3. Make sure that the IPv6 module installed or not. Then, use the following command to add new IP:

    ip -f inet6 addr add 2001:5c0:9168::2/64 dev eth0

    Afterwards, add default IP via

    ip -f inet6 ro add default via 2001:5c0:9168::1 dev eth0

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

share|improve this answer

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

ip -o -6 addr show eth0 | sed -e 's/^.*inet6 \([^ ]\+\).*/\1/'

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .