Operations 7 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering the Linux ‘route’ Command: View, Add, and Delete IP Routes

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-tools

Basic 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   ens33

Column 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 -n

Add a static route

# route add -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33

After 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 ens33

Again, 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 gone
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem AdministrationIP routingroute command
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.