IP forwarding

From Infogalactic: the planetary knowledge core
Jump to: navigation, search

IP forwarding also known as Internet routing is a process used to determine which path a packet or datagram can be sent. The process uses routing information to make decisions and is designed to send a packet over multiple networks.

Generally, networks are separated from each other by routers. For packets to travel between networks, they must be “routed” from one network to another. These routers contain a routing table that can contain specific instructions on how to send packets to a destination network (known as a route), or a set of generic instructions on where to send packets that do not match any of the other specified routes (called a default route), or both. These routes can either be hard-coded into the router by the network administrator (called a static route), or learned dynamically via a routing protocol. These routes give the routers instructions on how to utilize the physical network infrastructure that is in place to get packets to their destination, regardless of the number of hops that they must take to get there.

Ideally, IP forwarding algorithms would take into account a datagram's length, the type of service specified in the datagram's header, and the network load to determine the best path to send a packet to its intended destination. In general, most routing software determines its route through a shortest path algorithm. However, there are other routing protocols that use other factors (known as metrics) to determine the best path. Each path is given a “cost,” and the algorithms within a router’s operating system use this cost to determine where and how to send the packets. The calculation of these costs can include the bandwidth or utilization of the link between routers, or the speed that the connection is operating at. Different protocols are also used for different applications (for example, protocols such as Open Shortest Path First are generally used for routing packets between subnetworks within an organization’s network, and protocols such as Border Gateway Protocol are used for routing outside of them).[1]

In addition to calculating route cost, routing protocols also broadcast and share their known routes to other routers. This functionality comes with several benefits. Instead of requiring a network administrator to program each individual router with the relevant routes, he or she would only need to program a small number of routers (from which the other would learn the programmed routes). This has the added flexibility of being able to recover from an outage automatically. If a route becomes unavailable for some reason, the routing protocol can detect this and automatically send packets over an alternate route. This functionality can be invaluable in situations where network redundancy is required.

IP routing algorithm

The IP forwarding algorithm, commonly known as IP routing, is a specific implementation of routing for IP networks. In order to achieve a successful transfer of data the algorithm uses a routing table to select a next-hop router as the next destination for a datagram. The IP address that is selected is known as the next-hop address.[2]

When several destinations are matching, the route with the longest subnet mask is chosen (the most specific one). There can be only one default route.

The IP forwarding algorithm states:

Given a destination IP address, D, and network prefix, N:

if ( N matches a directly connected network address )

    Deliver datagram to D over that network link;

else if ( The routing table contains a route for N )

    Send datagram to the next-hop address listed in the routing table;

else if ( There exists a default route )

    Send datagram to the default route;

else

    Send a forwarding error message to the originator;

When there is no route available an ICMP error message is sent to the originator of the packet, to inform that host that the packet could not be delivered, and to avoid unnecessary retransmission and possibly subsequent network congestion. The sending host should either stop transmitting, or choose another address or route.

IP routing types

Link layer

A host's own subnet is immediately reachable over the local network link. An Ethernet Address Resolution Protocol (ARP) and MAC addressing broadcasting technique is used to send packets to the target system.

The following subnets cannot be routed (by definition), so they need to always be reacheable via a direct attached network device, via a NIC, a hub, a bridge, or a switch.

There is no next-hop address, because those subnets are not routeable over the Internet.

route add -net 169.254.0.0 netmask 255.255.0.0 dev eth0
route add -net 192.168.0.0 netmask 255.255.0.0 dev eth0
route add -net 172.16.0.0  netmask 255.240.0.0 dev eth0
route add -net 10.0.0.0    netmask 255.0.0.0   dev eth0

Internet Layer

The next two route types involve the Internet Layer for routing across network boundaries. Each destination network may have a specific router node that forwards packets:

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.96.1

When no specific router is specified for a destination, the default router is used:

route add default gw 71.46.14.1

Example

Example of a routing table:

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         71.46.14.1      0.0.0.0         UG    0      0        0 ppp0
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0
71.46.14.1      0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
172.16.0.0      0.0.0.0         255.240.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.1.0     192.168.96.1    255.255.255.0   UG    0      0        0 eth0
192.168.96.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0

Network interfaces:

A default route is recognized by Destination 0.0.0.0 and Flag G.

A network router is identified by a network mask 255.255.255.255 and a Flag H.

Routing flags

Most common Routing Flags
Flag Description
G Use Gateway (gateway filled in)
H Target is a Host (bit mask of 32 bits)
U Route is Up

Subnet masks

Newer kernels support a simplified syntax:

route add -net 169.254.0.0/16 dev eth0
route add -net 192.168.0.0/16 dev eth0
route add -net 172.16.0.0/12 dev eth0
route add -net 10.0.0.0/8 dev eth0

Kernel routing tables

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         217.136.39.1    0.0.0.0         UG    0      0        0 ppp0
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
172.16.0.0      0.0.0.0         255.240.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
217.136.39.1    0.0.0.0         255.255.255.255 UH    0      0        0 ppp0

In the Linux kernel, the route table is accessible via the /proc file system:

cat /proc/net/route
Iface   Destination     Gateway         Flags   RefCnt  Use     Metric  Mask            MTU     Window  IRTT              
ppp0    00000000        012788D9        0003    0       0       0       00000000        0       0       0                 
eth0    0000000A        00000000        0001    0       0       0       000000FF        0       0       0                 
eth0    0000FEA9        00000000        0001    0       0       0       0000FFFF        0       0       0                 
eth0    000010AC        00000000        0001    0       0       0       0000F0FF        0       0       0                 
eth0    0000A8C0        00000000        0001    0       0       0       0000FFFF        0       0       0                 
ppp0    012788D9        00000000        0005    0       0       0       FFFFFFFF        0       0       0             

Routing protocols


See also

References

  1. Comer, Douglas E. (2000). Internetworking with TCP/IP (4 ed.). Prentice Hall: Upper Saddle River, NJ.
  2. Internetworking with TCP/IP: Principles, protocols, and architecture By Douglas Comer


<templatestyles src="Asbox/styles.css"></templatestyles>