Appendix D. IP Route Management

Table of Contents

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