How to print Ipv6 Global using grep and awk?

Asked

Viewed 81 times

2

It’s been a few days since I’ve been searching the Internet for such an answer, but I haven’t had one so far. I am trying to print Ipv6 Global from ifconfig to be used in MOTD on Ubuntu.

With Ipv4 it was very easy to do this process with this command, because 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.

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'}
  • Thanks for the return, but a friend gave me a light. Talking so much about Global that I ended up using it to get what I wanted. ifconfig | grep 'global' | awk {'print $2'}

0

(I don’t have Ipv6 to test...) but try:

hostname -I
hostname -i

Browser other questions tagged

You are not signed in. Login or sign up in order to post.