Operations 7 min read

Master Linux ‘route’ Command: Display, Add, Delete, and Persist Routes

This guide explains how to install the net-tools package, use the Linux route command to view the kernel IP routing table, add or delete static routes, make routes persistent, and interpret the output fields with practical examples.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux ‘route’ Command: Display, Add, Delete, and Persist Routes

Introduction

The route command manipulates the kernel IP routing table. It can display the current routes or add/delete static routes. Routes created from the command line are volatile and disappear after a network‑interface or system reboot unless they are saved (e.g., in /etc/rc.local).

Installation

yum install net-tools

Syntax

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]

Common options

-f

: flush all routing entries -p: make the route permanent when used with

add
-n

: numeric output (do not resolve names) -v: verbose output -c: show more information -F: display sent‑packet statistics -C: display route cache

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 metric (hop count)

Output columns

# 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      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 : next‑hop 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

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

The new entry appears with the UG flag.

Delete a route

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

The entry disappears from the table.

Add and remove a reject (blackhole) route

# route add -net 10.10.10.0 netmask 255.255.255.0 reject
# route -n   # shows flag ! for the reject entry
# route del -net 10.10.10.0 netmask 255.255.255.0 reject

The ! flag indicates traffic to that network will be dropped.

Reference

Original tutorial URL: https://www.cnblogs.com/du-z/p/16332641.html

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.

Linuxcommand-lineSystem AdministrationrouteIP routingnet-tools
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.