24
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?

4 Answers 4

23

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.

2
  • 11
    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
    Commented Sep 4, 2018 at 5: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
    Commented Aug 20, 2019 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.

1
  • 2
    It might be more informative if you could show an example of a link mapping to an interface other than the loopback interface. Commented Jan 7, 2019 at 17:09
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.

0

The digits after the link# prefix is the network interface index. Every network interface has a unique index and a unique name. See ifconfig -v.

% ifconfig -v | grep $'^[^\t]'
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 index 1
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 index 2
stf0: flags=0<> mtu 1280 index 3
anpi0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 4
anpi1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 5
en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 6
en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 7
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 index 8
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 index 9
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 10
ap1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 11
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 12
awdl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 13
llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 index 14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .