What's the meaning of link#4 in mac's route table?
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.
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
.
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.