How to print global IPv6 using grep and awk?

2

There are already a few days that I am searching the Internet for such a response but I have not gotten any so far. I'm trying to figure out ifconfig's Global IPv6 to be used on MOTD on Ubuntu.

With IPv4 it was quite easy to do this with this command, since there is only one IPv4 in inet.

root@gamerno:/home/stalker# ifconfig | grep 'inet' -m1 | awk {'print $2'}
192.168.254.254

For inet6 there are 3 IPv6: local link, global link and loopback.

root@gamerno:/home/stalker# ifconfig | grep 'inet6' | awk {'print $2'}
fe80::222:4dff:feae:31fb < link local
b00b:cafe:face:628b::dead:beef < link global
::1 < loopback

Remembering that the Global link is in the second line.

    
asked by anonymous 16.02.2017 / 15:34

2 answers

1

If you are on the second or last line, just make a tail, as follows:

ifconfig | grep 'inet6' | tail -n1 | awk {'print $2'}
    
16.02.2017 / 15:58
0

(I do not have IPv6 to test ...) but try:

hostname -I
hostname -i
    
16.03.2017 / 11:59