22
jichaodeiMac:~ jichaoyang$ netstat -r
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            openwrt.lan        UGSc           10        0     en0
127                localhost          UCS             1        0     lo0
localhost          localhost          UH              2       54     lo0
169.254            link#4             UCS             1        0     en0
192.168.1          link#4             UCS             2        0     en0
192.168.1.1/32     link#4             UCS             2        0     en0
openwrt.lan        46:94:fc:63:fc:7   UHLWIir        11     3610     en0   1200
192.168.1.125/32   link#4             UCS             2        0     en0
jichaodeimac.lan   d0:50:99:14:b7:a3  UHLWIi          1        1     lo0
yangjicdeiphone.la link#4             UHLWIi          1        0     en0
224.0.0            link#4             UmCS            1        0     en0
255.255.255.255/32 link#4             UCS             1        0     en0

What's the meaning of link#4 in the table?

Jichao
  • 7,145
  • 12
  • 52
  • 62

3 Answers3

22

The expression link#x, where x is some digit, is used to indicate that the corresponding address is a link-level address, .i.e, an address that operates only on the network the host is physically connected to.

Thus these addresses are not used to reach hosts outside your local network, or, in technical lingo, they are not routable: once packets with these addresses reach a gateway (the junction between 2 or more distinct networks), the gateway discards them. It also follows that these addresses do not need any gateway, because they are not even supposed to evade into a different network.

Link-level addresses belong to the so called Link Layer, which is a mix of OSI Layer 1 (physical) and OSI Layer 2 (Data Link Layer) concepts. Several useful protocols operate at the Link Layer level, like ARP, OSPF, PPP, MAC (including Ethernet).

Basically, at the Link-Layer level, you need no routing because packets destined to other hosts are sent on the wire for anyone to listen to; all hosts on the physical connection receive the packet, those to which it is not addressed discard it, while only the true addressee keeps it to read it.

Real routing takes advantage of Layer 2 by encapsulating a packet destined to a remote host into a Layer-2 packet destined to the router, which unwraps it of the Layer-2 encapsulation, checks that it is destined to a different network, moves it to an outward-facing interface, and sends it on once again as a Layer-2 packet on the outside local network destined to the next-hop router. And so on.

MariusMatutiae
  • 46,990
  • 12
  • 80
  • 129
  • 8
    This is a great answer, but I still wonder what is the meaning of x. Does `link#4` indicate a _particular_ link (i..e, network interface) different from `link#5`? If so, then is there a way to know _which_ interface `link#4` designates? For instances, is there a natural ordering to the interfaces reported by `ifconfig`, so that `link#4` is simply the fourth interface by this ordering? – algal Sep 04 '18 at 05:18
  • 2
    @Marius when we see `169.254` in above example , does this mean `169.254.0.0` as network Id ? If yes , what will be it subnet mask as it is not specified ? – Number945 Aug 20 '19 at 13:00
13

Regarding your second question Is there a way to know which interface link#4 designates?, one could use the netstat command with the -i switch (state of interfaces). [Note: I prefer netstat not to resolve IP addresses, so in addition to the switch of interest I usually include -n]. So a sample (partial) output would be:

][ netstat -ni 
Name  Mtu   Network       Address            Ipkts Ierrs    Opkts Oerrs  Coll
lo0   16384 <Link#1>                       2030140     0  2030140     0     0
lo0   16384 127           127.0.0.1        2030140     -  2030140     -     -
lo0   16384 ::1/128       ::1              2030140     -  2030140     -     -

In this example Link#1 is associated to the loopback interface lo0, that operates on the 127 network (AF_NET family--IP4) with the address 127.0.0.1 and on the ::1/128 network (AF_NET6 family--IP6) with address ::1.

Omar S
  • 131
  • 1
  • 2
3

link#4 means the ip range is on the local segment, and no routing is necessary. if the entry was not a range of ips, netstat -r shows the mac address of that single ip address. In all other cases it will show the ip (or hostname) of the router it could possibly send the packet to.

Jake
  • 859
  • 1
  • 9
  • 9