ROUTE(8)

๐Ÿ“ฆ
version 2.10 ยท 6 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

๐ŸŽ€ ROUTE(8) ๐ŸŽ€

route is the Linux System Administrator's Manual tool for showing and messing with the IP routing table ๐Ÿ’…. Okay, let's get into it, bestie ๐Ÿฆ‹


โœจ NAME โœจ

route - show / manipulate the IP routing table


๐Ÿ—บ๏ธ SYNOPSIS ๐Ÿ—บ๏ธ

route [-CFvnNee] [-A family |-4|-6]

route  [-v] [-A family |-4|-6] add [-net|-host] target [netmask Nm] [gw
       Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod] [dyn]
       [reinstate] [[dev] If]

route  [-v] [-A family |-4|-6] del [-net|-host] target [gw Gw] [netmask
       Nm] [metric M] [[dev] If]

route  [-V] [--version] [-h] [--help]

๐Ÿ’– DESCRIPTION ๐Ÿ’–

okay so route is the tool that touches the kernel's IP routing tables ๐Ÿงš. Its main job is setting up static routes to specific hosts or networks through an interface, but only after that interface has been configured with the ifconfig(8) program. Order matters, bestie ๐Ÿซถ

When you use the add or del options, route actually changes the routing tables ๐Ÿ”ฅ. Without them, it just shows you what's currently in there, so no changes, just vibes ๐Ÿ‘€


๐Ÿ‘‘ OPTIONS ๐Ÿ‘‘

  • -A family โ€” use the address family you pick (like inet). Run route --help for the full list of families ๐ŸŒˆ. You can use -6 as a shortcut for --inet6, and -4 as a shortcut for -A inet โœจ
  • -F โ€” works on the kernel's FIB (Forwarding Information Base) routing table. This is the default, so you don't have to ask for it ๐Ÿ’…
  • -C โ€” works on the kernel's routing cache instead ๐Ÿฆ‹
  • -v โ€” turns on verbose mode, so it talks your ear off ๐Ÿ—ฃ๏ธ
  • -n โ€” shows numerical addresses instead of trying to figure out symbolic host names ๐Ÿ”ข. This is super useful if you're trying to find out why the route to your nameserver has vanished ๐Ÿ˜ญ
  • -e โ€” shows the table in netstat(8) format ๐ŸŽ€. -ee goes even harder and prints one very long line with every single parameter from the routing table ๐Ÿ™ˆ
  • del โ€” deletes a route ๐Ÿ—‘๏ธ
  • add โ€” adds a brand new route ๐Ÿ’œ
  • target โ€” the destination network or host ๐ŸŽฏ. You can give it an address or a symbolic network or host name. You can also use /prefixlen notation instead of the netmask option, which is very slay ๐Ÿ’…
  • -net โ€” tells route that the target is a network ๐ŸŒ
  • -host โ€” tells route that the target is a single host ๐Ÿงโ€โ™€๏ธ
  • netmask NM โ€” when you're adding a network route, this is the netmask to use ๐ŸŽญ
  • gw GW โ€” routes packets through a gateway ๐Ÿšช
NOTE: the gateway you pick has to be reachable first ๐Ÿšจ. This usually means you need to set up a static route to the gateway beforehand. If you give it the address of one of your own local interfaces, that interface gets used to decide where the packets go. This is a BSDism compatibility hack, so it's kinda a bit of a quirk ๐Ÿ™ˆ
  • metric M โ€” sets the metric field in the routing table (the one routing daemons care about) to M ๐Ÿ“. If you skip this, the metric defaults to 1 for the inet6 (IPv6) address family, and 0 for inet (IPv4). Honestly, always specify an explicit metric so you're not relying on those defaults ๐Ÿ˜ค. They also differ from iproute2, so be warned ๐Ÿ’€
  • mss M โ€” sets the MTU (Maximum Transmission Unit) of the route to M bytes ๐Ÿ“ฆ. Heads up though: the current route command can't actually set the Maximum Segment Size (MSS), even though this option exists ๐Ÿ™ƒ
  • window W โ€” sets the TCP window size for connections over this route to W bytes ๐ŸชŸ. This is usually only used on AX.25 networks and with drivers that can't handle back to back frames ๐Ÿ“ก
  • irtt I โ€” sets the initial round trip time (irtt) for TCP connections over this route to I milliseconds (1-12000) โฑ๏ธ. This is mostly an AX.25 thing too. If you leave it out, the RFC 1122 default of 300ms gets used ๐Ÿ“
  • reject โ€” installs a blocking route that forces route lookups to fail ๐Ÿšซ. This is handy for masking out networks before you use the default route, for example. This is NOT for firewalling, so don't even try ๐Ÿ™…โ€โ™€๏ธ
  • mod, dyn, reinstate โ€” install a modified, dynamic, or reinstated route ๐Ÿงช. These flags are for diagnostic purposes and are generally only set by routing daemons, so unless you're one of those, leave them alone ๐Ÿค“
  • dev If โ€” forces the route to be tied to the device you name ๐Ÿ”Œ. Otherwise the kernel tries to figure out the device on its own, by checking existing routes and device specs and seeing where the route gets added. Most normal networks won't need this ๐Ÿฅฐ

If dev If is the last thing on the command line, you can drop the word dev, since it's the default ๐Ÿ’…. Otherwise, the order of the route modifiers (metric, netmask, gw, dev) doesn't matter at all โœจ


๐Ÿงƒ EXAMPLES ๐Ÿงƒ

  • Adds the normal loopback entry:
route add -net 127.0.0.0 netmask 255.0.0.0 metric 1024 dev lo

Uses netmask 255.0.0.0 and ties it to the "lo" device (assuming you already set that up correctly with ifconfig(8)) ๐Ÿ”

  • Adds a route to your local network via eth0:
route add -net 192.56.76.0 netmask 255.255.255.0 metric 1024 dev eth0

This adds a route to the local network 192.56.76.x via "eth0". The word "dev" can be left out here ๐Ÿ™Œ

  • Deletes the default route:
route del default

Deletes the current default route, which shows up as "default" or 0.0.0.0 in the destination field of the routing table ๐Ÿ—‘๏ธ

  • Deletes a specific network route:
route del -net 192.56.76.0 netmask 255.255.255.0

Deletes the route. The Linux routing kernel uses classless addressing, so you pretty much always have to type the same netmask you see in the route -n listing ๐Ÿง

  • Adds a default route through a gateway named mango:
route add default gw mango

Adds a default route, which gets used when no other route matches ๐ŸŒ. All packets using this route get gatewayed through the address of a node named "mango". The device that actually gets used depends on how we can reach "mango", and "mango" has to be on a directly reachable route ๐Ÿ’ญ

  • Adds a route to the host mango via the SLIP interface:
route add mango sl0

Adds the route to the host named "mango" via the SLIP interface (assuming "mango" is the SLIP host) ๐Ÿ

  • Gateways a network through the SLIP route:
route add -net 192.57.66.0 netmask 255.255.255.0 gw mango

This adds the net "192.57.66.x" and has it gatewayed through the former route to the SLIP interface ๐Ÿช„

  • Sends all class D (multicast) routes through eth0:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

This one is obscure, documented so people know how to do it ๐Ÿคซ. It sets all of the class D (multicast) IP routes to go via "eth0". This is the correct normal config line with a multicasting kernel ๐Ÿ“ก

  • Installs a rejecting route for the private 10.x network:
route add -net 10.0.0.0 netmask 255.0.0.0 metric 1024 reject

This installs a rejecting route for the private network "10.x.x.x." ๐Ÿ›‘

  • Adds an IPv6 route:
route -6 add 2001:0002::/48 metric 1 dev eth0

This adds an IPv6 route with the specified metric, directly reachable via eth0 ๐ŸŒธ


๐Ÿ“Š OUTPUT ๐Ÿ“Š

okay the kernel routing table output comes in these columns ๐Ÿ’…

  • Destination โ€” the destination network or destination host ๐ŸŽฏ
  • Gateway โ€” the gateway address, or * if none is set ๐Ÿšช
  • Genmask โ€” the netmask for the destination net. It shows 255.255.255.255 for a host destination and 0.0.0.0 for the default route ๐ŸŽญ
  • Flags โ€” possible flags include:
    • U (route is up) ๐ŸŸข
    • H (target is a host) ๐Ÿงโ€โ™€๏ธ
    • G (use gateway) ๐Ÿšช
    • R (reinstate route for dynamic routing) ๐Ÿ”„
    • D (dynamically installed by daemon or redirect) โšก
    • M (modified from routing daemon or redirect) ๐Ÿงช
    • A (installed by addrconf) ๐Ÿ 
    • C (cache entry) ๐Ÿ’พ
    • ! (reject route) ๐Ÿšซ
  • Metric โ€” the 'distance' to the target, usually counted in hops ๐Ÿ“
  • Ref โ€” number of references to this route. (Not used in the Linux kernel, so it's just vibes ๐Ÿซ )
  • Use โ€” count of lookups for the route. Depending on whether you used -F or -C, this is either route cache misses (-F) or hits (-C) ๐ŸŽฏ
  • Iface โ€” the interface packets for this route get sent out of ๐Ÿ“ค
  • MSS โ€” default maximum segment size for TCP connections over this route ๐Ÿ“ฆ
  • Window โ€” default window size for TCP connections over this route ๐ŸชŸ
  • irtt โ€” initial RTT (Round Trip Time). The kernel uses this to guess the best TCP protocol parameters without waiting on (possibly slow) answers โฑ๏ธ
  • HH (cached only) โ€” the number of ARP entries and cached routes that refer to the hardware header cache for the cached route. It'll be -1 if a hardware address isn't needed for that interface, like lo ๐Ÿ”ข
  • Arp (cached only) โ€” whether or not the hardware address for the cached route is up to date ๐Ÿ•ฐ๏ธ

๐Ÿ“ FILES ๐Ÿ“

/proc/net/ipv6_route
/proc/net/route
/proc/net/rt_cache

๐Ÿ”— SEE ALSO ๐Ÿ”—

ethers(5), arp(8), rarp(8), route(8), ifconfig(8), netstat(8) ๐Ÿฆ‹


๐Ÿ“œ HISTORY ๐Ÿ“œ

okay so Route for Linux was originally written by Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>, and then modified by Johannes Stille and Linus Torvalds for pl15. Alan Cox added the mss and window options for Linux 1.1.22 ๐Ÿ’œ. irtt support and the merge with netstat came from Bernd Eckenfels ๐ŸŒˆ


๐Ÿง‘โ€๐Ÿ’ป AUTHOR ๐Ÿง‘โ€๐Ÿ’ป

Currently maintained by Phil Blundell <Philip.Blundell@pobox.com> and Bernd Eckenfels <net-tools@lina.inka.de> ๐Ÿซถ


Bestie, you now know everything about route ๐Ÿ’– Go route some packets and be iconic about it โœจ net-tools, 2014-02-17 ๐ŸŒธ