When a ip addr is added, two unicat route entries are added to route table. ex: 10.10.2.9/24 dev eth0
a host route entry is added to local table. The packet to local host will be routed by this route entry. The route still is valid, even the related interface is shut down. 【local table】 10.10.2.9/32 dev eth0
a connected route is added to main table. It is used to forward the packet to the hosts in the same sub network, it will disappear when interface down 【main table】 10.10.2.0/24 dev eth0
~ # dmesg -c ~ # ifconfig ~ # ip link 1: lo: <LOOPBACK> mtu 16436 qdisc noop state DOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT link/ether 16:83:71:72:da:97 brd ff:ff:ff:ff:ff:ff 3: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000 link/ether 08:00:27:89:78:8f brd ff:ff:ff:ff:ff:ff 4: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000 link/ether 08:00:27:eb:21:53 brd ff:ff:ff:ff:ff:ff 5: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000 link/ether 08:00:27:2a:3f:e3 brd ff:ff:ff:ff:ff:ff 6: teql0: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 100 link/void 7: tunl0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT link/ipip 0.0.0.0 brd 0.0.0.0 8: sit0: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT link/sit 0.0.0.0 brd 0.0.0.0 9: ip6tnl0: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT link/tunnel6 :: brd ::
0.2.1. ip link set eth1 up
1 2 3 4 5 6
~ # ip link set dev eth1 up ~ # dmesg -c IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready e1000: eth1 NIC LinkisUp1000MbpsFullDuplex, FlowControl: RX IPv6: ADDRCONF(NETDEV_CHANGE): eth1: link becomes ready ~ #
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
~ # ip route show table local ~ # ip route show table main ~ # dmesg -c ~ # ~ # ip addr add dev eth1 10.10.2.9/24 <=== configure a ip address on a interface. ~ # ~ # dmesg -c <=== the related call trace. inet_rtm_newaddr: is called __inet_insert_ifa: ifa=ffff88003d1fa7e0, ifa_address:4802500a ifa_local=4802500a, ifa_mask=00ffffff __inet_insert_ifa: send rtm msg forifa=ffff88003d1fa7e0 fib_inetaddr_event: event=00000001 fib_add_ifaddr: call fib_magic RTM_NEWROUTE, RTN_LOCAL with addr=4802500a fib_magic: type=2, dst=4802500a, dst_len=32 fib_add_ifaddr: call fib_magic RTM_NEWROUTE, with frefixlen fib_magic: type=1, dst=0002500a, dst_len=24 fib_add_ifaddr: call fib_magic RTM_NEWROUTE, toadd two broadcast route fib_magic: type=3, dst=0002500a, dst_len=32 fib_magic: type=3, dst=ff02500a, dst_len=32
0.2.2. two broadcast routes are added.
1 2 3 4 5
~ # ip route list table local <=== two broadcast routes are added to local, a host route(ip_local_in) is added also. broadcast 10.10.2.0 dev eth1 proto kernel scope link src 10.10.2.9 local 10.10.2.9 dev eth1 proto kernel scope host src 10.10.2.9 broadcast 10.10.2.255 dev eth1 proto kernel scope link src 10.10.2.9 a connected route is added.
1 2 3
~ # ip route list table main <=== 10.10.2.0/24 dev eth1 proto kernel scope link src 10.10.2.9 <=== it will be deleteif interface down, whilelocal route will not be deleted. set eth1 down,
1 2 3 4 5
~ # ip link set dev eth1 down ~ # ip route showtable main <== nothing remain. ~ # ip route showtablelocal local10.10.2.9 dev eth1 proto kernel scope host src 10.10.2.9<== still there ping localhost ip address with lo up
1 2 3 4 5 6 7 8 9 10 11
~ # ip link set dev lo up <== MUST confirm lo up. ~ # ping -c 3 10.10.2.9 <== ping itself OK. PING 10.10.2.9 (10.10.2.9): 56 data bytes 64 bytes from 10.10.2.9: seq=0 ttl=64 time=0.068 ms 64 bytes from 10.10.2.9: seq=1 ttl=64 time=0.069 ms 64 bytes from 10.10.2.9: seq=2 ttl=64 time=0.088 ms