You will not find this very often … sometimes, you will come across a network where there are two routers on the same broadcast segment, each responsible for different networks. So how do you get your hosts to know which gateway should they use? You could setup two default gateways – both Windows and Linux allow that. However, you could also rely on ICMP Redirects – this feature is enabled by default on Cisco routers.
I will be working on the following topology:
Host1 is set with one single gateway of 192.168.1.254 (Router1). When Host1 tries to reach Host4 by sending a ping to 192.168.3.4, Host1 identifies the destination IP is not on the same LAN so it sends to its default gateway. Router1, knows how to reach 192.168.3.0 network through Router2. – so Router1 forwards the packet to Router2 – it does so by using the same interface as where the packet was received! This will then trigger Router1 sending the ICMP Redirect message to Host1 saying – “Next time you need to send a packet to 192.168.3.0 network, just use Router2 straight, since it’s on the same segment as I am!”
Let’s see this in action …
The routing table on Host1 and Router1 look like this:
You can see that Router1 routes packets for network 192.168.3.0 through 192.168.1.253 (Router2); also, Host1 routes any packet through its default gateway which is set to 192.168.1.254 (Router1). Let’s send a ping to 192.168.3.1 now …
Router1 receives the packet since it is the default gateway to Host1; Router1 then forwards the packet to Router2 as per it’s own routing table; in doing so, it used the same interface on which the same packet was received – so Router1 will also send a redirect message to the sender. As a result, you can see that Host1, automatically adds a route in its routing table pointing to 192.168.1.253 – despite its default gateway being 192.168.1.254!
Next time Host1 sends a packet to host 192.168.3.1, it will use the gateway of 192.168.1.253.
You can also disable this behaviour by using the interface command “no ip redirects“.