Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
    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

2 Answers 2

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

There are lots of ways you could do this.

Here is one:

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.