Mastering the Linux ‘route’ Command: View, Add, and Delete IP Routes
This guide explains how to install the net-tools package, use the Linux route command to display the kernel IP routing table, and perform common operations such as adding, deleting, and rejecting routes with detailed option descriptions and practical examples.
Introduction
The route utility manipulates the kernel IP routing table, allowing you to display current routes or modify them with add and del options. Adding a route via the command line is temporary; to make it persistent you can place the command in /etc/rc.local.
Installation
yum install net-toolsBasic Usage
route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface] -c: show more information -n: do not resolve names -v: verbose output -F: display forwarding information -C: show route cache -f: flush all routes -p: make the route permanent when used with add Common sub‑commands: add: add a new route del: delete an existing route -net: destination is a network -host: destination is a host netmask: required when adding a network route gw: specify the gateway (must be reachable) metric: set the route’s distance (hop count)
Output Explanation
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.0.0 0.0.0.0 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33Column meanings:
Destination : target network or host
Gateway : gateway address or ‘*’ if none
Genmask : subnet mask (255.255.255.255 for host, 0.0.0.0 for default)
Flags : U (up), H (host), G (gateway), R (reinstate), D (dynamic), M (modified), A (addrconf), C (cache), ! (reject)
Metric : distance to the target (used by routing daemons)
Ref : reference count (unused in Linux kernel)
Use : number of lookups (helps identify cache hits/misses)
Iface : outgoing interface
Practical Examples
Query the routing table
# route -nAdd a static route
# route add -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33After adding, re‑run route -n to verify the new entry.
Delete a route
# route del -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33Again, use route -n to confirm removal.
Add a reject (blackhole) route and then delete it
# route add -net 10.10.10.0 netmask 255.255.255.0 reject
# route -n # shows a ‘!’ flag for the reject entry
# route del -net 10.10.10.0 netmask 255.255.255.0 reject
# route -n # reject entry is goneSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
