in Computer Networks edited by
12,023 views
45 votes
45 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 {128.75.43.0} &  \text{255.255.255.0} & \text{Eth$0$} \\\hline\text {128.75.43.0} &  \text{255.255.255.128} & \text{Eth$1$} \\\hline\text {192.12.17.5} &  \text{255.255.255.255} & \text{Eth$3$}\\\hline \text {Default} &  \text{} & \text{Eth$2$}\\\hline\end{array}$$
On which interface will the router forward packets addressed to destinations $128.75.43.16$ and $192.12.17.10$ 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 edited by
12.0k views

4 Comments

No two destination have same IP address but two IP address are in same Network.
0
0
Two destination always have different IP address but more than one IP address can belong to same Network.
0
0

5 Answers

62 votes
62 votes
Best answer

The answer must be A.

(Using $\wedge$ to denote bitwise AND)

For 1$^{st}$packet,

$(128.75.43.16) \wedge (255.255.255.0) = (128.75.43.0)$ since $\{16 \wedge 0 = 0\}$, as well as 

$(128.75.43.16) \wedge (255.255.255.128) = (128.75.43.0)$ 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 $2^{nd}$ packet,

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

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

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

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

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

edited by

16 Comments

Why to select n/w id with greater number of one's here?
6
6
@saurabhrk

How default interface is Eth2.

I think it should be Eth3.
0
0
@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)
7
7
Any reference ?
0
0
edited by
What does default mean here? @ saurabhrk
0
0
What is meant for default here for class c the default address is 255.255.255.0 plzz any one clarify me
0
0

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.

https://en.wikipedia.org/wiki/Default_route

6
6

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.

 

0
0

@Sanjay Mahaveer

May be only one host connected to the router. 

0
0
Why does the router uses longest prefix matching technique when there is a multiple match ?
0
0
bitwise And operation done with which byte to which is it the first byte or with the last byte???
0
0

@Sanjay Mahaveer If subnet masks contain all 1’s then there are no host id bits remaining. i.e. 0 host id bits. So, no of hosts = 2^0 = 1. So, the network contains only one host.

1
1
edited by
network id and subnet mask for default entry are 0.0.0.0 and 0.0.0.0 for default entry.

if the IP doesn’t matches with any entry of routing table then, the packet should be forward to the default interface
0
0

@JAINchiNMay Why longest prefix match of subnet mask are always preferred over shorter one?

0
0

A network is divided in the many subnets,

But now the entries of the original network and new subnets both are present in routing tables
and the subnet mask of the new subnet will be longer. so it is more meaningful to send the data to subnet
Longest Prefix Matching in Routers - GeeksforGeeks here you can understand it better.

1
1

@Nisha Bharti Longest prefix match subnet mask is preferred because in Routing table Network ID are stored in decreasing order of Network ID.

1
1
11 votes
11 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 :- 128.75.43.0/24 (128.75.43.0 to 128.75.43.255)

interface eth1 :- 128.75.43.0/25 (128.75.43.0 to 128.75.43.127)

for 128.75.43.16 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.

https://en.wikipedia.org/wiki/Longest_prefix_match

https://stackoverflow.com/questions/9335504/network-longest-prefix-matching

2 Comments

"Longer prefixes are always preferred over shorter ones when forwarding a packet." why so ?
0
0

read about RIPv2

and packet forwarding

0
0
1 vote
1 vote
Start with the maximum mask:

128.75.43.16 while doing masking(bit wise AND operation) with

255.255.255.128 will give 128.75.43.0 .

we always takes the maximum mask so ans would be eth1
0 votes
0 votes
It'll be through eth1. If bit wise OR of packet address and subnet mask matches with more than one destination address then we go with the one with longer run of 1s.
Answer:

Related questions