Operations 7 min read

Master the Linux route Command: Manage IP Routing Tables Like a Pro

This guide explains how to install, use, and interpret the Linux route command for displaying and manipulating the kernel IP routing table, covering options, output fields, persistence tricks, and practical examples for querying, adding, deleting, and rejecting routes.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master the Linux route Command: Manage IP Routing Tables Like a Pro

Overview

The route utility displays and manipulates the kernel IP routing table, allowing you to add static routes after configuring interfaces with ifconfig. Without options it shows the current table; with add or del it modifies the table.

Installation

yum install net-tools

Command Syntax

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

Common flags: -c – show more information -n – do not resolve names -v – verbose processing details -F – display sent packets -C – display route cache -f – flush all routing entries -p – make the route permanent when used with add Key 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 Fields Explanation

The kernel routing table is displayed in columns:

Destination – target network or host

Gateway – gateway address or ‘*’ if none

Genmask – subnet mask (e.g., 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 (usually hop count)

Ref – reference count (unused in Linux kernel)

Use – number of lookups (helps identify cache hits/misses)

Iface – outgoing interface for the route

Persistence

Routes added directly on the command line disappear after a network‑interface or system reboot. To make them permanent, place the route commands in /etc/rc.local or use the -p flag where supported.

Examples

Query the routing table: route -n Add a static network route:

route add -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33

Verify the addition: route -n Delete the previously added route:

route del -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33

Add a reject (blackhole) route and then remove 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
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.

LinuxroutingSystem Administrationiproute 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.