The Gateway to Computer Science Excellence
+23 votes

The routing table of a router  is shown below:
$$\begin{array}{|l|l|l|} \hline \textbf {Destination} & \textbf {Subnet Mask} & \textbf{Interface}  \\\hline \text {} &  \text{} & \text{Eth$0$} \\\hline\text {} &  \text{} & \text{Eth$1$} \\\hline\text {} &  \text{} & \text{Eth$3$}\\\hline \text {Default} &  \text{} & \text{Eth$2$}\\\hline\end{array}$$
On which interface will the router forward packets addressed to destinations $$ and $$ respectively?

  1. Eth$1$ and Eth$2$
  2. Eth$0$ and Eth$2$
  3. Eth$0$ and Eth$3$
  4. Eth$1$ and Eth$3$
in Computer Networks by Veteran (52.2k points)
edited by | 4.4k views

Entries in the routing table are stored in sorted manner based on subnet mask. the IP will be compared first with, match is found hence, packet will be forwarded to Eth1 instead to Eth0.

If more than one entry matches, then send the packets to one having larger subnet mask (more 1's in subnet mask).
but table should be sorted in descending order
but why is there any reason behind it

3 Answers

+47 votes
Best answer

The answer must be A.

(Using $\wedge$ to denote bitwise AND)

For 1$^{st}$packet,

$( \wedge ( = ($ since $\{16 \wedge 0 = 0\}$, as well as 

$( \wedge ( = ($ since $\{16 \wedge 128 = 0\}$.

Now, since both these subnet masks are producing the same Network ID, hence The one with greater number of ones will be selected, and the packet will be forwarded there. Hence packet $1$ will be forwarded to Eth$1$.

For 1$^{nd}$ packet,

$($ when ANDed with each of the subnet masks does not match with any of the network ID, since:

$( \wedge ( = ($ {Does not match with any of the network addresses}

$( \wedge ( = ($ {Does not match with any of the network addresses}

$( \wedge ( = ($ {Does not match with any of the network addresses}

Hence, default interface must be selected for packet $2$, i.e., Interface Eth$2.$

by Active (1.4k points)
edited by
Why to select n/w id with greater number of one's here?

How default interface is Eth2.

I think it should be Eth3.
@khushtak  If two interfaces matches with the given address, then we should send the data to the interface having longest prefix match which is nothing but the interface having large subnet mask (more number of 1's)
Any reference ?
What does default mean here? @ saurabhrk
What is meant for default here for class c the default address is plzz any one clarify me

The default route generally points to another router, which treats the packet the same way: if a route matches, the packet is forwarded accordingly, otherwise the packet is forwarded to the default route of that router. The route evaluation process in each router uses the longest prefix match method to obtain the most specific route. The network with the longest subnet mask that matches the destination IP address is the next-hop network gateway. The process repeats until a packet is delivered to the destination.


Can anyone please explain 'what does it mean if subnet mask contains all 1s'. Does it mean that there are no hosts in the network?. @Arjun Sir.



@Sanjay Mahaveer

May be only one host connected to the router. 

+6 votes

How router makes decisions ?

Router check the destination address by decapsulating packet and perform bitwise AND with subnet mask of all interfaces and if the resulting n/w address matches with corresponding interface n/w address then router send packet to this interface , in case of tie , router uses Longest prefix match

interface eth0 :- ( to

interface eth1 :- ( to

for we can see there is a tie as it falls within the n/w addresses for eth0 and eth1...which route would the router choose? It depends on the prefix length, or the number of bits set in the subnet mask. Longer prefixes are always preferred over shorter ones when forwarding a packet.

by Boss (14.4k points)
–2 votes
ans c)
by Loyal (5.2k points)
@Aditi , why you always write only option and option which is wrong(most of time).

May be your target is get maximum negative votes or downvotes . Good keep it up

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,461 answers
100,247 users