TheCableGuyDecember2001
UnderstandingtheIPRoutingTable
ByTheCableGuy
Foralistandadditionalinformationonall
TheCableGuy
columns,
clickhere
.
TopicsonthisPage
ContentsofanIPRoutingTable
RouteDeterminationProcess
NextHopAddressandInterfaceDetermination
Process
ForMoreInformation
AllcomputersrunninganyversionofWindowsandthesuppliedTCP/[Link]
[Link]
[Link]/IPutilitiesorentriescanbe
addeddynamicallythroughinteractionwithrouters.
WhenanIPpacketisforwarded,theIProutingtableisusedtodetermine:
1.
ThenexthopIPaddress
Foradirectdelivery(thedestinationisaneighboringnode),thenexthopIPaddressisthedestination
[Link](thedestinationisnotaneighboringnode),thenexthop
addressistheaddressofarouter.
2.
Thenexthopinterface
Thenexthopinterfaceidentifieseitheraphysicalinterface(forexample,anetworkadapter)oralogical
interface(forexample,atunnelinginterface)thatisusedtoforwardthepacket.
Afterthenexthopaddressandinterfacearedetermined,thepacketispassedtotheAddressResolution
Protocol(ARP).ForLANtechnologiessuchasEthernetandTokenRing,ARPattemptstoresolvethelinklayer
address(alsoknownasthemediaaccesscontrol[MAC]address)forthenexthopaddress,andforwardthe
packetbyusingthenexthopinterface.
ContentsofanIPRoutingTable
ThefollowingarethefieldsofatypicalIProutingtableentry:
Destination
ThedestinationcanbeeitheranIPaddressoraclassbased,subnetted,[Link]
theWindows2000IProutingtable,thiscolumnisnamedNetworkDestination.
NetworkMask
[Link]
Windows2000IProutingtable,thiscolumnisnamedNetmask.
NextHop
TheIPaddresstowhichthepacketisforwarded.IntheWindows2000IProutingtable,thiscolumnis
namedGateway.
Interface
ThenetworkinterfacethatisusedtoforwardtheIPpacket.
Metric
Anumberusedtoindicatethecostoftheroutesothatthebestroute,amongpotentiallymultipleroutes
tothesamedestination,[Link]
(thenumberoflinksorrouterstocross)enroutetothedestination.
Routingtableentriescanbeusedtostorethefollowingtypesofroutes:
Directlyattachednetworkroutes
[Link],the
NextHopfieldcaneitherbeblankorcontaintheIPaddressoftheinterfaceonthatsubnet.
Remotenetworkroutes
[Link]
networkroutes,theNextHopfieldistheIPaddressofalocalrouter.
Hostroutes
[Link]
routes,thenetworkIDisaspecificIPaddressandthenetworkmaskis255.255.255.255.
Defaultroute
[Link]
[Link]
typicallythedefaultgatewayofthenode.
RouteDeterminationProcess
Todeterminewhichroutingtableentryisusedforforwarding,IPusesthefollowingprocess:
Foreachentryintheroutingtable,abitwiselogicalANDoperationisperformedbetweenthedestination
[Link]
match.
ToperformabitwiselogicalANDbetweenthedestinationIPaddressandthenetworkmaskoftheroute,
[Link]
bitsare1's,theresultingbitis1otherwise,[Link]
isdefined,theresultofthebitwiselogicalANDoperationis:
Foreachbitinthesubnetmaskthatissetto1,thecorrespondingbitintheresultiscopiedfromthe
destinationIPaddress.
Foreachbitinthesubnetmaskthatissetto0,thecorrespondingbitintheresultissetto0.
AgoodexampleofperformingabitwiselogicalANDisindeterminingtheIPnetworkIDforanIPaddress
[Link],abitwiselogicalANDoftheassignedIPaddresswithits
[Link].
Forexample,fortheIPaddress192.168.98.112withthesubnetmask255.255.255.0,theresultofthe
bitwiselogicalANDis:
Forthefirst24bits,whichcorrespondtothe"255.255.255"portionofthesubnetmask,the
correspondingbitfromthedestinationIPaddressiscopied,resultingin192.168.98forthefirstthree
octets.
Forthelast8bits,whichcorrespondtothe"0"portionofthesubnetmask,thecorrespondingbitis
setto0,resultingin0forthelastoctet.
Therefore,192.168.98.112AND255.255.255.0is192.168.98.0.
[Link](thatis,theroutewiththe
highestnumberofbitssetto1inthesubnetmask)[Link]
[Link](forexample,
multipleroutestothesamenetworkID),[Link]
therearemultiplelongestmatchingrouteswiththelowestmetric,thenoderandomlyselectswhich
routingtableentrytouse.
[Link]
processfailstoselectaroute,[Link],anIProutingerrorisindicated
internallytoanupperlayerprotocol,[Link],anICMPDestinationUnreachableHost
Unreachablemessageissenttothesendinghostandthepacketisdiscarded.
NextHopAddressandInterfaceDeterminationProcess
Afterdeterminingthesinglerouteintheroutingtablewithwhichtoforwardthepacket,thenexthopaddress
andinterfacearedeterminedbythefollowingprocess:
IftheaddressintheNextHopfieldiseitherblankorisanaddressthatisassignedtoaninterfaceonthe
forwardingnode:
ThenexthopaddressissettothedestinationIPaddressoftheIPpacket.
ThenexthopinterfaceissettotheinterfacethatisspecifiedintheInterfacefield.
IftheaddressintheNextHopfieldisnotanaddressthatisassignedtoaninterfaceontheforwarding
node:
ThenexthopaddressissettotheaddressintheNextHopfieldfortheroute.
ThenexthopinterfaceissettotheinterfacethatisspecifiedintheInterfacefield.
ExampleIPRoutingTableforWindows2000
ThefollowingtableliststhedefaultroutingtableforaWindows2000basedhost(thatis,notarouter).The
hosthasasinglenetworkadapterandisconfiguredwiththeIPaddress157.60.136.41,subnetmask
[Link](/22),[Link]
runningWindows2000,type
routeprint
or
netstatr
atacommandprompt.
===========================================================================
InterfaceList
0x1...........................MSTCPLoopbackinterface
0x1000003...00b0d0e94143......3ComEtherLinkPCI
===========================================================================
===========================================================================
ActiveRoutes:
NetworkDestination
Netmask
[Link]
[Link]
[Link]
[Link]
[Link] [Link]
[Link] [Link]
[Link] [Link]
[Link]
[Link]
[Link] [Link]
Gateway
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Interface
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Metric
1
1
1
1
1
1
1
DefaultGateway:[Link]
===========================================================================
PersistentRoutes:
None
[Link](3ComEtherLink
PCI)andtheotherisaninternalloopbackinterface(MSTCPLoopbackInterface).
TheWindows2000IProutingtableusesanIPaddresstoidentifyaninterfaceintheInterfacefieldforthe
[Link],thefollowingprocessdeterminesthenexthopaddressandinterface:
IftheaddressintheGatewayfieldisanaddressthatisassignedtoaninterfaceontheforwardingnode:
ThenexthopaddressissettothedestinationIPaddressoftheIPpacket.
ThenexthopinterfaceissettotheinterfacetowhichtheaddressintheInterfacefieldisassigned.
IftheaddressintheGatewayfieldisnotanaddressthatisassignedtoaninterfaceontheforwarding
node:
ThenexthopaddressissettotheaddressintheGatewayfield.
ThenexthopinterfaceissettotheinterfacetowhichtheaddressintheInterfacefieldisassigned.
ThisWindows2000IProutingtablecontainsthefollowingentries:
Thefirstentry,networkdestinationof0.0.0.0andnetworkmask(netmask)of0.0.0.0(/0),isthedefault
route.AnydestinationIPaddressthatisbitwiselogicallyANDedwith0.0.0.0,resultsin0.0.0.0.
Therefore,[Link]
route,thenexthopaddressis157.60.136.1andthenexthopinterfaceisthenetworkadapterthatis
assignedtheIPaddress157.60.136.41.
Thesecondentry,networkdestinationof127.0.0.0andnetmaskof255.0.0.0(/8),istheloopback
networkroute.Forallpacketsthataresenttoanaddressoftheform127.
x.y.z
,thenexthopaddressis
setto127.0.0.1(theloopbackaddress)andthenexthopinterfaceistheinterfacethatisassignedthe
address127.0.0.1(theloopbackinterface).
Thethirdentry,networkdestinationof157.60.136.0andnetmaskof255.255.252.0(/22),isa
[Link],thenexthopaddressissetto
thedestinationaddressinthepacketandthenexthopinterfaceissettothenetworkadapterthatis
assignedtheIPaddress157.60.136.41.
Thefourthentry,networkdestinationof157.60.136.41andnetmaskof255.255.255.255(/32),isahost
routefortheIPaddressofthehost.ForallIPpacketssentto157.60.136.41,thenexthopaddressisset
to127.0.0.1andthenexthopinterfaceistheloopbackinterface.
Thefifthentry,networkdestinationof157.60.255.255andnetmaskof255.255.255.255(/32),isahost
routethatcorrespondstotheallsubnetsdirectedbroadcastaddressfortheclassBnetworkID
[Link]/16.ForallIPpacketssentto157.60.255.255,thenexthopaddressissetto157.60.255.255
andthenexthopinterfaceisthenetworkadapterthatisassignedtheIPaddress157.60.136.41.
Thesixthentry,networkdestinationof224.0.0.0andnetmaskof224.0.0.0(/3),isarouteformulticast
[Link],thenexthopaddressissettothedestination
addressandthenexthopinterfaceissettothenetworkadapterthatisassignedtheIPaddress
[Link].
Theseventhentry,networkdestinationof255.255.255.255andnetmaskof255.255.255.255(/32),isa
hostroutethatcorrespondstothelimitedbroadcastaddress.ForallIPpacketssentto255.255.255.255,
thenexthopaddressissetto255.255.255.255andthenexthopinterfaceisthenetworkadapterthatis
assignedtheIPaddress157.60.136.41.
ThefollowingareexamplesofhowthisroutingtableisusedtodeterminethenexthopIPaddressand
interfaceforseveraldifferentdestinations:
Unicastdestination157.60.136.48
Thelongestmatchingrouteistherouteforthedirectlyattachednetwork([Link]/22).The
nexthopIPaddressissettothedestinationIPaddress([Link])andthenexthopinterfaceisset
tothenetworkadapterthatisassignedtheIPaddress157.60.136.41.
Unicastdestination192.168.0.79
Thelongestmatchingrouteisthedefaultroute([Link]/0).ThenexthopIPaddressissettothedefault
gatewayaddress([Link])andthenexthopinterfaceisthenetworkadapterthatisassignedtheIP
address157.60.136.41.
Multicastdestination224.0.0.1
Thelongestmatchingrouteisthe224.0.0.0/[Link]
address([Link])andthenexthopinterfaceisthenetworkadapterthatisassignedtheIPaddress
[Link].
Subnetbroadcastdestination157.60.139.255
Thelongestmatchingrouteistherouteforthedirectlyattachednetwork([Link]/22).The
nexthopIPaddressissettothedestinationIPaddress([Link])andthenexthopinterfaceis
settothenetworkadapterthatisassignedtheIPaddress157.60.136.41.
Unicastdestination157.60.136.41
ThelongestmatchingrouteisthehostrouteforthelocallyassignedIPaddress([Link]/32).The
nexthopIPaddressissettothedestinationaddress([Link])andthenexthopinterfaceissetto
theloopbackadapter.