Take the 2-minute tour ×

What command can I use to get IPv6 address of an interface in a script?

Update: Output of sed from one of answers.

$ ip -6 addr
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
    inet6 fe80::224:d7ff:fed0:4f5c/64 scope link 
       valid_lft forever preferred_lft forever

The other:

$ ip addr show dev eth0 | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d'
$ ip addr show dev eth0
  2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
  link/ether f0:de:f1:7b:e9:6c brd ff:ff:ff:ff:ff:ff
share|improve this question
Which IPv6 addresses? Your interfaces' IPv6 addresses? –  m0skit0 Feb 14 '12 at 13:27
Yes, edited, thx. –  Ondra Žižka Feb 21 '12 at 4:33
add comment

2 Answers

up vote 6 down vote accepted

You could use:

ip -6 addr

It will return all the IPv6 adresses you have configured.

share|improve this answer
add comment

There are lots of ways you could do this.

Here is one:


It is similar to Robert's answer, except strips out the address only.

share|improve this answer
add comment

Your Answer


