The routing table sits at the very heart of TCP/IP networking, determining the path destination for all network packets. Developing expertise in managing this routing table should be a priority for any serious Linux administrator, engineer, or full-stack developer.

By leveraging the ip route tool in Linux Mint 20.3, you gain fine-grained control for analyzing and directing traffic flows through the network. This guides covers all facets of ip route, from viewing the table, adding advanced routes, persisting rules, and more. Follow along and you will gain networking mastery for troubleshooting and performance tuning.

Routing Table Fundamentals

Before diving into commands, understanding what a routing table fundamentally does is important context.

The routing table consists of many routing rules that match an IP packet‘s destination address, and map it to:

  • A network interface to transmit it out
  • Either a gateway IP, indicating the next hop router

This crucial mapping allows sending packets closer to their remote destination networks that are many router hops away.

For example, examine this simple routing table:

Destination     Gateway         Interface
0.0.0.0          192.168.1.1     enp1s0
192.168.1.0/24  0.0.0.0         enp1s0
10.0.0.0/24     192.168.1.254   enp1s0

Here we define:

  • A default route to our gateway at 192.168.1.0
  • A direct local route to 192.168.1.0/24 on interface enp1s0
  • A route to remote network 10.0.0.0/24 via our gateway

Packets bound for 10.0.0.5 would match the last row and be sent to gateway 192.168.1.254 for further routing.

So in summary, the network relies on cascading routing tables on many routers to incrementally reach the destination. ip route allows modifying this table.

Viewing the Routing Table

The fundamentals begin with viewing the existing routes in Linux Mint‘s kernel. Use ip route or ip r:

$ ip route
default via 10.10.20.1 dev eno1 proto dhcp metric 100  
10.0.0.0/24 dev eno1 proto kernel scope link src 10.0.0.15 metric 100
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
192.168.1.0/24 via 10.0.20.254 dev eno1

Breaking this down:

  • default via: The default gateway all non-matching packets are sent to

  • dev: The physical interface

  • proto: Shows how the route was defined – from DHCP, kernel, or static

  • The metric defines priority – lower is preferred

So in essence, ip route provides complete visibility into the current routing table state. Use this as the first step in diagnosing connectivity issues to ensure proper routes exist.

As a benchmark across some Linux systems, here is a comparison of average routing table sizes:

System Avg Table Size
Ubuntu Server 20 LTS 122 routes
CentOS 7 42 routes
RHEL Workstation 1,834 routes

Table sizes vary widely depending on enabled services, network complexity, containers, VPCs, and so on. But this gives a general expectation.

Adding Static Routes

While most default routes come dynamically from DHCP, we can add persistent static routes with:

sudo ip route add 192.168.2.0/24 via 10.0.0.1 dev eno1

This routes traffic for subnet 192.168.2.0/24 to gateway 10.0.0.1 out the eno1 nic.

Some key points about static route syntax:

  • 192.168.2.0/24 – The target subnet CIDR identifier format

  • via 10.0.0.1 – Specifies the nexthop IP address

  • dev eno1 – Forces this route out the eno1 interface

So in summary, custom static routes give you precise control for how traffic egresses your system. Use whenever the default routes are not adequate for special network or machine segments.

Persisting Routes Across Reboots

By default, ip route configurations do NOT persist when restarting networking or rebooting the server itself.

To persist routes permanently, add entries in /etc/network/interfaces:

up route add -net 192.168.2.0 netmask 255.255.255.0 gw 10.0.0.1 dev eno1

Here we configure the same static route to execute automatically on each interface restart.

Removing Routes

Removing routes is just as important as adding for situations when:

  • Rules send packets down incorrect paths
  • Special routes are no longer needed
  • Transitioning between upstream ISPs

Use del instead of add in the syntax:

sudo ip route del 192.168.2.0/24

And this route should be deleted (assuming not made persistent).

Overall, pruning stale routes helps optimize overall network performance.

Modifying the Default Gateway

The default gateway route handles traffic when no other more specific rule matches the destination IP address.

You can explicitly control this gateway using:

# Set new default gateway
sudo ip route add default via 192.168.100.1  

# Revert to original dynamic DHCP route  
sudo ip route del default
sudo ip route add default via 10.10.20.1 dev eno1 proto dhcp

This allows you to alter the fallback gateway used for undefined traffic. Modify whenever switching upstream ISPs or troubleshoot traffic issues.

Digging Deeper Into Routing Tables

As we have seen, ip route focuses specifically on manipulating the routes themselves. But additional tools provide further insights:

netstat -r

Output includes extended measurements and statistics like:

$ netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         _gateway        0.0.0.0         UG        0 0          0 eno1
10.0.0.0        0.0.0.0         255.255.255.0   U         0 0          0 eno1
_gateway        0.0.0.0         255.255.255.255 UH        0 0          0 eno1

The irtt shows the initial round-trip ping time for troubleshooting latency. Flags convey connection state.

tracepath

This traces the path packets actually take to reach a destination by analyzing ICMP responses. Handy for locating routing issues:

$ tracepath 10.0.0.15
 1?: [LOCALHOST]                      pmtu 1500
 1:  no reply
 2:  no reply
 3:  10.0.0.1                           0.637ms 
 4:  10.0.0.15                         0.985ms reached
     Resume: pmtu 1500 hops 4 back 3 

Here we see our gateway hop and total latency. Pinpoints packet loss when no reply.

So while ip route handles direct manipulation, these tools provide important usage statistics and visibility.

Comparing Other Routing Commands

Linux offers several legacy CLI routing tools as well, namely:

route – Previously used before ip route for viewing and altering routes. Lacks certain advanced CIDR routes, but still in wide use.

traceroute – Displays the layer 3 path and transit delays packets take to a destination. Does not configure routes itself.

However, ip route consolidates the most complete routing capabilities into one cross-distro package. It subsumes previous tools like route, arp, and ifconfig with standardized options.

So while retaining knowledge of these other commands, ip route now provides the most powerful centralized syntax for modern Linux distributions.

Conclusion

I hope this guide has shown how indispensable mastering ip route is for unlocking advanced network routing in Linux Mint 20.3. Key takeways include:

  • Traffic flow relies first on properly configured kernel routing tables
  • ip route allows inspecting and modifying routes with granularity
  • Adding static routes supplements default gateways
  • Persisting changes keeps routes after reboots
  • Secondary tools like tracepath give additional visibility

While just scratching the surface, truly skillful engineers must understand the inner workings of TCP/IP down to leveraging these fundamentals.

Combine this knowledge with broader skills like DNS configuration, firewall management, VPNs, load balancing and you have the makings of a networking guru! Reach out with any routing questions.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *