-1

I saw the following line of code in a code repo I work on:

ip addr | grep 'inet .*global' | cut -f 6 -d ' ' | cut -f1 -d '/' | head -n 1

I want to understand what does the "global" attribute mean as part of the network interface attribute?

I hope i am asking it in the right place...

Thanks a lot, Matan

slashms
  • 111
  • 1
  • 2

1 Answers1

2

Did it occur to you to just run the line?

$ ip addr | grep 'inet .*global'
inet xx.xx.xx.xx/24 brd xx.xx.xx.255 scope global eth0

So, we are talking about the "scope" of the interface here, a term you could just google, which might end you up here, explaining

The possible values for scope are outlined in the following table.

Table C.2. IP Scope under ip address
Scope Description
global    valid everywhere
site  valid only within this site (IPv6)
link  valid only on this device
host  valid only inside this host (machine)

Scope is normally determined by the ip utility without explicit use on the command line. For example, an IP address in the 127.0.0.0/8 range falls in the range of localhost IPs, so should not be routed out any device. This explains the presence of the host scope for addresses bound to interface lo. Usually, addresses on other interfaces are public interfaces, which means that their scope will be global. We will revisit scope again when we discuss routing with ip route, and there we will also encounter the link scope.

Sven
  • 98,649
  • 14
  • 180
  • 226