pritam123456
asked on
About TCP/IP
how does a routher know that an ip datagram should be sent to the destination directly or via a router?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you assign an IP to a device you assign a netmask to it too. The netmask is a bitfield that is used to determine the "network" the ip / device is on.
Here is an example
ip : 192.168.1.1
netmask :255.255.255.0
in binary thats
11000000.10101000.00000001 .00000001 --> Your IP
11111111.11111111.11111111 .00000000 --> Mask
Any binary part of the masked off adress is not "allowed" to change if you want to remain on the devices physical network. so if you destination is 192.168.1.5 you are fine because
11000000.10101000.00000001 .00000001 --> Your IP
11111111.11111111.11111111 .00000000 --> Mask
11000000.10101000.00000001 .00000101 --> Destination IP
none of the address bits have changed in the masked off section of the address.
If your destination is for example 192.168.2.1, then thats a diffrent story.
11000000.10101000.00000001 .00000001 --> Your IP
11111111.11111111.11111111 .00000000 --> Mask
11000000.10101000.00000010 .00000001 --> Destination IP
As you can see the first(aka last) 2 bits of the 3rd digit have changed. If you look at the mask they are not "allowed" to change. this puts your destination on a diffrent physical network.
Your networking core does this for every packet.. Iit checks the destination address agains all of its locally addressed interfaces and makes a routing descision.. It either sends the packet out directly to an IP number or if it cant find a match it sends it to the default gateway.
HOW DOES IT SEND TO AN IP OR A GATEWAY?
This is an often misunderstood portion of tcp/ip. So far we have only looked at the logical addressing using tcpip. There is an underlying physical layer that needs to be adressed. TCP/IP only has 1 destination address field in its header, so how do we "send" a packet to a router.
Well when your network stack sends a packet it passes it on to your network card. In the case of your ethernet device it has a MAC address which is a unique 6 byte number. You can see this number by typing "ipconfig /all" under a windows command prompt. This layer is how traffic is actually delivered. Once the networking core decides that a packet should go out on a local wire loop, it looks up the MAC address of the destination device and sends the IP packet on its way to that MAC address regardless of the ip number.
To look up the MAC adress of the destination device the system uses ARP. This stands for Adress resolution protocol and is used to change ip numbers into MAC adresses. You can see your current list of cached adresses on yoru machine by typing "ARP -a" into a windows command prompt.
WHAT THE HELL? WHAT ABOUT MY GATEWAY?
Basically, once TCP/IP has decided that it cant reach a device directly on any of its local interfaces, ie the device isnt on any of its wires, It then proceeds to send the IP packet to a gateway device. This device will have an IP number on one of its interfaces so your machine DOES an ARP and finds the gateways PHYSICAL address and sends the IP Packet to the gateway MAC address WITHOUT changing the destination address of the IP Packet. So basically the gateway ends up getting packets that are not destined for it but that it then passes on to other gateways.
Hope it helps.
Here is an example
ip : 192.168.1.1
netmask :255.255.255.0
in binary thats
11000000.10101000.00000001
11111111.11111111.11111111
Any binary part of the masked off adress is not "allowed" to change if you want to remain on the devices physical network. so if you destination is 192.168.1.5 you are fine because
11000000.10101000.00000001
11111111.11111111.11111111
11000000.10101000.00000001
none of the address bits have changed in the masked off section of the address.
If your destination is for example 192.168.2.1, then thats a diffrent story.
11000000.10101000.00000001
11111111.11111111.11111111
11000000.10101000.00000010
As you can see the first(aka last) 2 bits of the 3rd digit have changed. If you look at the mask they are not "allowed" to change. this puts your destination on a diffrent physical network.
Your networking core does this for every packet.. Iit checks the destination address agains all of its locally addressed interfaces and makes a routing descision.. It either sends the packet out directly to an IP number or if it cant find a match it sends it to the default gateway.
HOW DOES IT SEND TO AN IP OR A GATEWAY?
This is an often misunderstood portion of tcp/ip. So far we have only looked at the logical addressing using tcpip. There is an underlying physical layer that needs to be adressed. TCP/IP only has 1 destination address field in its header, so how do we "send" a packet to a router.
Well when your network stack sends a packet it passes it on to your network card. In the case of your ethernet device it has a MAC address which is a unique 6 byte number. You can see this number by typing "ipconfig /all" under a windows command prompt. This layer is how traffic is actually delivered. Once the networking core decides that a packet should go out on a local wire loop, it looks up the MAC address of the destination device and sends the IP packet on its way to that MAC address regardless of the ip number.
To look up the MAC adress of the destination device the system uses ARP. This stands for Adress resolution protocol and is used to change ip numbers into MAC adresses. You can see your current list of cached adresses on yoru machine by typing "ARP -a" into a windows command prompt.
WHAT THE HELL? WHAT ABOUT MY GATEWAY?
Basically, once TCP/IP has decided that it cant reach a device directly on any of its local interfaces, ie the device isnt on any of its wires, It then proceeds to send the IP packet to a gateway device. This device will have an IP number on one of its interfaces so your machine DOES an ARP and finds the gateways PHYSICAL address and sends the IP Packet to the gateway MAC address WITHOUT changing the destination address of the IP Packet. So basically the gateway ends up getting packets that are not destined for it but that it then passes on to other gateways.
Hope it helps.
which will rock your mind up with the router how router works in a handy dandy way