slashms
slashms

Reputation: 978

What is the global attribute of a network interface?

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

Upvotes: 1

Views: 1145

Answers (1)

fghj
fghj

Reputation: 9394

ip addr just convert ifa_scope from struct ifaddrmsg to string, struct ifaddrmsg is the how the ip command get information from kernel (http://man7.org/linux/man-pages/man7/rtnetlink.7.html).

About ifa_scope:

Scope of the address. The default is RT_SCOPE_UNIVERSE (which corresponds to the value 0) and the field is usually set to that value by ifconfig/ip, although a diferent value can be chosen. The main exception is an address in the reange 127.x.x.x, which is given the RT_SCOPE_HOST scop. See Chapter 30 for more details.

(C) Understanding Linux Network Internals

And actually RT_SCOPE_UNIVERSE converted by ip to string with value "global".

About scope of address, it helps to decide use or not this interface for some job. For example if you want communication inside machine, you can choose one of network interfaces with scope host, if you talk with outside world you can choose interface with scope global etc.

To detail understanding I advise book from which I give quote.

Upvotes: 1

Related Questions