Appendix D. IP Route Management

Table of Contents

D.1. route
D.1.1. Displaying the routing table with route
D.1.2. Reading route's output
D.1.3. Using route to display the routing cache
D.1.4. Creating a static route with route add
D.1.5. Creating a default route with route add default
D.1.6. Removing routes with route del
D.2. ip route
D.2.1. Displaying a routing table with ip route show
D.2.2. Displaying the routing cache with ip route show cache
D.2.3. Using ip route add to populate a routing table
D.2.4. Adding a default route with ip route add default
D.2.5. Setting up NAT with ip route add nat
D.2.6. Removing routes with ip route del
D.2.7. Altering existing routes with ip route change
D.2.8. Programmatically fetching route information with ip route get
D.2.9. Clearing routing tables with ip route flush
D.2.10. ip route flush cache
D.2.11. Summary of the use of ip route
D.3. ip rule
D.3.1. ip rule show
D.3.2. Displaying the RPDB with ip rule show
D.3.3. Adding a rule to the RPDB with ip rule add
D.3.4. ip rule add nat
D.3.5. ip rule del

Routing and understanding routing in an IP network is one of the fundamentals you will need to grasp the flexibility of IP networking, and services which run on IP networks. It is not enough to address the machines and mix yourself a dirty martini. You'll need to verify that the machine has a route to any network with which it needs to exchange IP packets.

One key element to remember when designing networks, viewing routing tables, debugging networking problems, and viewing network traffic on the wire is that IP routing is stateless [46]. This means that every time a new packet hits the routing stage, the router makes an independent decision about where to send this packet.

In this section, we'll look at the tools available to manipulate and view the routing table(s). We'll start with the well known route command, and move on to the increasingly used ip route and ip rule tools which are part of the iproute2 package.



[46] For those who have some doubt, netfilter provides a connection tracking mechanism for packets passing through a linux router. This connection tracking, however, is independent of routing. It is important to not conflate the packet filtering connection tracking statefulness with the statelessness of IP routing. For an example of a complex networking setup where netfilter's statefulness and the statelessness of IP routing collide, see Section 10.4, “Multiple Connections to the Internet”.