Iproute2

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 02:20, 8 June 2007 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Advanced Routing and iproute2 - the ip routing utility


iproute2.txt research document, details may be sketchy and incomplete. v0.02



ifconfig and route use iproute2 syscalls. However, the 'ip' tool is the key to access advanced iproute2 syscalls.

[ Usage examples of the ip tool ]

ip link list                    : shows links including MAC but not IP address
ip address show                 : more info including IP and queueing disipline
ip route show                   : equivalent to route -n except uses iproute2



Address Resolution Protocol (ARP) resolves the hardware address of another machine on the same local network. ARP determines where a machine is at on the LAN (really it determines what the MAC is of that machine).

synonymous terminology: MAC address = location = hardware address

IP address is Layer 3 networking, Media Access Control (MAC) is Layer 2.

An IP address knows not the location of a machine, ARP does. Machines on the Internet have DNS names which resolve to IP addresses, not to be confused with knowing the location (MAC address).

When computer A wants to find computer B on the same LAN, computer A does an ARP broadcast with IP (layer 3). Computer B with matching IP answers with its MAC address. Further communication is layer 2 by MAC. The ARP entry for computer B remains in the ARP cache of computer A for a limited duration.

When computer A wants to find computer C, which is on another network across the Internet, 'A' knows the subnet is different from its own and therefore references its gateway (the router) and asks it for the location (MAC) of computer C. Through Internet routing the local router finds the remote router which is the gateway for computer C and asks it what the MAC address is for computer C. If the remote router does not know, it does an ARP broadcast on the LAN of computer C. Computer C answers telling its router its MAC address. That remote router then sends the MAC back to the local router for computer A and informs computer A of the MAC address for 'C'. Further communication is layer 2 from local machine to local router and layer 3 between routers.

synonymous terminology: arp cache = neighbor cache = neigh

[ Usage examples of ip relating to ARP ]

ip neigh show                    : view current ARP cache table
ip neigh delete X.X.X.X dev ethX : delete IP X.X.X.X from APR cache 



Of the three routing tables which are part of iproute2, the traditional 'route' command only modifies the main table. The 'ip' tool can modify all three tables but modifies the main table by default.

ip route ls                     : shows only the main route table
ip rule list                    : display current route rules and priority
ip route list table local       : shows necessary stuff in the local table
ip route list table main        : same as 'ip route ls'
ip route flush cache            : clear all route cache, do after modification

You can create your own route tables. To create a custom table:


echo 200 tablename >> /etc/iproute2/rt_tables

(above: creates a route table in rt_tables)


ip rule add from X.X.X.X table tablename

(above: source IP or computer on LAN)


ip route add default via Y.Y.Y.Y dev ethX table tablename

(above: assigns route for computer on LAN)



Example: Two Internet Providers - Multihoming

A business may have two Internet providers. To set up routing for two ISPs on linux consider this example a generic guide.

192.168.0.1 = IP of Internal network (irrelevant) on eth1
64.21.10.250 = IP of first ISP on eth0
  gw 64.21.10.1  network 255.255.255.0
128.42.20.250 = IP of second ISP on eth2
  gw 128.42.20.1 network 255.255.255.0

1. create two tables and set up routing

ip route add 255.255.255.0 dev eth0 src 64.21.10.250 table T1
ip route add default via 64.21.10.1 table T1
ip route add 255.255.255.0 dev eth2 src 128.42.20.250 table T2
ip route add default via 128.42.20.1 table T2

2. set up main routing table

ip route add 255.255.255.0 dev eth0 src 64.21.10.250
ip route add 255.255.255.0 dev eth2 src 128.42.20.250

3. set the preference for the default route

ip route add default via 64.21.10.1

4. routing rules for interfaces

ip rule add from 64.21.10.250 table T1
ip rule add from 128.42.20.250 table T2
  • . load balancing between the two providers
ip route add default scope global nexthop via 64.21.10.1 dev eth0 weight 1 nexthop via 128.42.20.1 dev eth2 weight 1



Thu Oct 23 11:48:27 CDT 2003