22

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?

28

from http://linux-ip.net/html/tools-ip-address.html :

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. (...)

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.

6
  • 2
    Thanks for your answer. I alread had read that. What I really don't understand is what 'valid' means here. In other words: how will the scope argument impact the network device behaviour?
    – rolaf
    Sep 7 '09 at 12:46
  • Ip addresses and routes have a scope to indicate to the kernel the distance to other networks/addresses. See books.google.de/… :)
    – brengo
    Sep 7 '09 at 12:56
  • I should have added: "scope" is for routing decisions and sanity checks of the routing configuration. It helps the kernel to decide (faster) where the packets should go. Hope that helps?
    – brengo
    Sep 7 '09 at 13:01
  • 1
    Sorry brengo, your link is not consultable right now. But isn't the metric argument used to specify the distance?
    – rolaf
    Sep 7 '09 at 13:01
  • 1
    You should never see site being used, as these addresses were deprecated in 2004. Jan 6 '17 at 15:51
13

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

Link-local address are supposed to be used for addressing nodes on a single link. Packets originating from or destined to a link-local address will not be forwarded by a router.

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

Site-local address are supposed to be used within a site. Routers will not forward any packet with site-local source or destination address outside the 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.

2
  • 2
    What about the 192.168.0.0/16 block -- isn't that essentially site-local?
    – SamB
    May 4 '11 at 1:51
  • 2
    You should never see site being used, as these addresses were deprecated in 2004. Jan 6 '17 at 15:52
0

Find these comments in fib_semantics.c

 704  * Every prefix is assigned a "scope" value: "host" is local address,
 705  * "link" is direct route,
 706  * [ ... "site" ... "interior" ... ]
 707  * and "universe" is true gateway route with global meaning.
 708  *
 709  * Every prefix refers to a set of "nexthop"s (gw, oif),
 710  * where gw must have narrower scope. This recursion stops
 711  * when gw has LOCAL scope or if "nexthop" is declared ONLINK,
 712  * which means that gw is forced to be on link.
 ....
 719  * Normally it looks as following.
 720  *
 721  * {universe prefix}  -> (gw, oif) [scope link]
 722  *                |
 723  *                |-> {link prefix} -> (gw, oif) [scope local]
 724  *                                      |
 725  *                                      |-> {local prefix} (terminal node)
 726  */
0

okay. i will give real practical example not just theory.

i had on my notebook scope link in

/etc/network/interfaces

auto ens160
iface ens160 inet static
        address 172.16.102.33
        netmask 255.255.255.0
        network 172.16.102.0
        broadcast 172.16.102.255
        **scope link**
        gateway 172.16.102.1
    

when i tried

# ping 8.8.8.8

my gateway cisco asa blocked my packet and wrote in logs

Deny IP spoof from (0.0.0.0) to 8.8.8.8 on interface sandbox

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

auto ens160
iface ens160 inet static
        address 172.16.102.33
        netmask 255.255.255.0
        network 172.16.102.0
        broadcast 172.16.102.255
        **scope global**
        gateway 172.16.102.1

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

1
  • The scope definition is completely unnecessary. It can (and should) be omitted for virtually every conceivable configuration. Sep 29 '20 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.