Networking: Mastering Routing in Ubuntu
Linux Networking: route, mastering routing in Ubuntu lies at the heart of any networked system, determining how data packets travel between devices and networks. For Linux administrators, mastering routing commands is essential to control network traffic and troubleshoot connectivity issues effectively.
In Ubuntu, the route
command offers a simple yet powerful way to view and manipulate the system’s routing table. Whether you’re adding static routes, analyzing traffic paths, or configuring network gateways, understanding this command is crucial for optimizing network performance and maintaining seamless connectivity.
In this guide, we’ll explore the basics of routing in Ubuntu, dive into practical examples using the route
command, and share tips to help you master Linux networking with confidence. Let’s get started!
Using the route
Command in Ubuntu
In Ubuntu, the route
command helps display and modify the IP routing table, which defines the paths network traffic takes to reach its destination. Network administrators frequently rely on this command to configure, troubleshoot, and optimize routes.
By default, the route
command belongs to the net-tools
package. However, on newer Ubuntu distributions, this package might not be pre-installed because net-tools
has been deprecated in favor of the iproute2
suite.

Installation
To install net-tools
(which contains route
) package type in the terminal:
sudo apt install net-tools
Check Routing Table
To display the current routing table use the following:
route
or
route -n
Output:
root@ubuntu-d-2022q1:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-15faf413e796
Route Output Explanation
This routing table entry defines the default route for all traffic. If a packet’s destination doesn’t match a more specific route, it will be forwarded to the gateway at 10.0.2.2
via the enp0s3
network interface. This setup is typical for systems connected to a network via NAT or bridge, such as in virtualized environments.
Destination
: This column indicates the network or host the route applies to.Gateway
: The IP address of the next hop or gateway through which packets should be routed.Genmask
: The subnet mask for the destination network.Flags
: These indicate various characteristics of the route- U: The route is up and operational.
- G: The route is to a gateway (as opposed to a directly connected device).
Metric
: The cost of the route. Lower metric values have higher priority.Ref
: This is the reference count (how many routes are referencing this entry).Use
: Indicates the number of times this route has been used to send packets.Iface (Interface)
: The network interface associated with this route.
Add/Delete Route
For instance, you can use route add
to define a new route or route del
to remove an existing route. These options are particularly helpful when you need to reroute traffic due to changes in the network topology or troubleshoot connectivity issues.
To add a route to a specfic network or host use the following:
sudo route add -net <network> netmask <netmask> gw <gateway> dev <interface>
For specific host:
sudo route add -host <host> gw <gateway> dev <interface>
# Example
sudo route add -net 192.168.10.0 netmask 255.255.255.0 gw 10.0.2.2 dev eth0
To delete a route:
sudo route del -host <host> gw <gateway> dev <interface>