In Linux, the command
ip address add [...]
has a scope
argument. The man page says that the scope is "the scope of the area where this address is valid". Follows the list of legal scopes:
- global
- site
- link
- host
What does this "area" of "validity" refer to?
from http://linux-ip.net/html/tools-ip-address.html :
Scope is normally determined by the ip utility without explicit use on the command line. (...)
The following citations are from the book Understanding Linux network internals by Christian Benvenuti, O'Reilly:
"The scope of a route in Linux is an indicator of the distance to the destination network. The scope of an IP address is an indicator of how far from the local host the address is known, which, to some extent also tells you how far the owner of that address is from the local host (...).
Host: An address has a host scope when it is used only to communicate within the host itself. Outside the host this address is not known and can not be used. An Example is the loopback address, 127.0.0.1
Link: An address has a link scope when it is meaningful and can be used only within a LAN. An example is a subnet's broadcast address.
Global: An address has global scope when it can be used anywhere. This is the default scope for most addresses. (...)"
The main reason to use scopes seems to be that a host with multiple interfaces and addresses has to decide when to use which address. For communication with itself a loopback address (scope host) can be used. With communication elswhere, a different address has to be selected.
To begin to understand the definition of scope you should start by knowing what link-local and site-local addresses are. Once those are cleared up then the others will fall into place. Quoting some snippets from IPv6 docs.
Link
An example of this is the range 169.254/16. Which you may have seen before when devices are unable to obtain a valid address from DHCP.
Site
This only applies to IPv6. There is no notion of site-local addresses in IPv4.
Host
A host address is something that will only exist within the host machine itself. For instance 127.0.0.1 is a host address commonly assigned to the loopback interface. The loopback interface has no external connectivity and so it's scope is confined to within that of the host machine.
Global
A global address is what you might currently consider a "normal" address. That is, a unicast address, which is visible on and routable across an external network.
Find these comments in fib_semantics.c
okay. i will give real practical example not just theory.
i had on my notebook scope link in
when i tried
my gateway cisco asa blocked my packet and wrote in logs
so i couldnt get 8.8.8.8
and if you use tcpdump you will see that linux indeed will send on LAN packets with scr ip = 0.0.0.0
tcpdump -n -vv icmp -i ens160
when i changed /etc/network/interfaces with scope global
i could succesfully get 8.8.8.8
that is how scope on network settings for example make real influence on ip packets
also for whom to want more detailed explanation about scopes pls take a look here - https://unix.stackexchange.com/a/611945/214557