Master Linux Routing: View, Add, and Delete Routes with the route Command
This guide explains how to use the Linux route command to display the IP routing table, install the necessary net‑tools package, and perform common operations such as adding, deleting, and blocking routes, including options for persistence and detailed output interpretation.
Introduction
route – show/manipulate the IP routing table.
It operates on the kernel's IP routing table, mainly used to create static routes to specific hosts or networks after configuring interfaces with ifconfig.
Using add or del options modifies the table; without them, route simply displays the current contents.
Adding a route directly from the command line is not permanent; the route disappears after a network‑interface or system reboot. To make it persistent, place the route command in /etc/rc.local.
Installation
yum install net-toolsUsage
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 Show sent information
-C Show route cache
-f Flush all routing entries
-p Make the route permanent when used with add
add : add a new route
del : delete a route
-net : destination is a network
-host : destination is a host
netmask : required when adding a network route
gw : gateway through which packets are sent (must be reachable)
metric : set route metric (hop count)Output
[root@master ~]# 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.10.0 - 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33Explanation of columns:
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 route.
Flags : U (up), H (host), G (gateway), R (reinstate dynamic), D (daemon), M (modified), A (addrconf), C (cache), ! (reject).
Metric : distance to target (usually hop count).
Ref : reference count (not used in Linux kernel).
Use : number of lookups (used with -F and -C to show cache misses/hits).
Iface : interface used to send packets.
Examples
Query route
[root@master ~]# 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
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33Add route
[root@master ~]# route add -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33
[root@master ~]# 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.10.0 192.168.209.2 255.255.255.0 UG 0 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33Delete route
[root@master ~]# route del -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33
[root@master ~]# 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
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33Add reject route and delete
[root@master ~]# route add -net 10.10.10.0 netmask 255.255.255.0 reject
[root@master ~]# 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.10.0 - 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@master ~]# route del -net 10.10.10.0 netmask 255.255.255.0 reject
[root@master ~]# 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
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33Signed-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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
