top of page

Troubleshooting Routing Issues Using the Route Command

Feb 12

9 min read

0

10

0

Troubleshooting Routing Issues Using the Route Command

The route command is a powerful tool for managing and troubleshooting network routing on Linux, Windows, and IBM OS/2 systems. It allows you to view and manipulate the IP routing table, which determines how network packets are forwarded between different hosts and networks 1 2. By understanding how to use the route command effectively, you can diagnose and resolve various routing problems and ensure smooth network communication.

Understanding the IP Routing Table

Before diving into the route command, it's essential to grasp the concept of the IP routing table. This table stores information about network destinations and the routes used to reach them 1. When your computer needs to send a packet to a specific destination, it consults the routing table to determine the appropriate path. Each entry in the routing table typically includes the following 2:

  • Destination: The network or host that you want to reach.

  • Netmask: A 32-bit value that helps determine which part of an IP address identifies the network and which part identifies the host.

  • Gateway: The IP address of the next hop or router used to forward packets toward the destination.

  • Interface: The network interface through which the destination can be reached.

  • Metric: A numerical value that represents the cost or preference of a particular route. Lower metric values indicate more preferred routes.

If no matching entry is found in the table for a given destination, and no default gateway is configured, the packet might be dropped 3.

Viewing the Routing Table

The most basic function of the route command is to display the current routing table. Here's how you can do it on different operating systems:

Linux:


Bash



route -n

The -n option displays numerical IP addresses instead of hostnames, which can be helpful for troubleshooting.

Windows:




route print

This command displays the entire contents of the IP routing table.

IBM OS/2:




route print

This command also displays the routing table.

The output of the route command will vary depending on your operating system and network configuration 2. For example, in Windows, the route print command output includes several columns with important information 3:

  • Network Destination: The destination network or host.

  • Netmask: The subnet mask associated with the destination.

  • Gateway: The IP address of the next hop or router.

  • Interface: The network interface used for the route.

  • Metric: The cost metric for the route.

Additionally, the output may include flags that indicate the state of the route, such as U (up), H (host route), G (gateway route), and D (dynamically created route) 4.

You can also use wildcards with the route print command to display specific routes. For example, route print 10.* displays routes in the IP routing table that begin with 10 2.

Adding Routes

You can add new routes to the routing table using the route add command. This is often necessary when you need to establish static routes for specific networks or hosts that are not automatically discovered by your system.

It's important to use the correct syntax for the route command based on the operating system 2 1. Here's a table summarizing the options and their descriptions for Linux and Windows:





Option

Linux Description

Windows Description

add

Adds a new route

Adds a new route

-net

Specifies a network route


-host

Specifies a host route


netmask

Specifies the network mask

mask specifies the subnet mask

gw

Specifies the gateway

Specifies the gateway

metric

Specifies the cost metric

metric specifies the cost metric

if

Specifies the interface index

if specifies the interface index

-p

Makes the route persistent

-p makes the route persistent

-4

Force using IPv4


-6

Force using IPv6


Linux:


Bash



sudo route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 metric 7

This command adds a route to the 192.168.1.0 network with a subnet mask of 255.255.255.0 via the gateway 192.168.1.1 and a cost metric of 7. The metric influences route selection, with lower metric values being preferred 2.

You can also specify the interface index for the interface over which the destination is reachable using the if option. For example, route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0x3 adds a route using the interface index 0x3 2.

Windows:




route add 192.168.1.0 mask 255.255.255.0 192.168.1.1

This command achieves the same result as the Linux example above, but without specifying the metric.

To add a persistent route in Windows, use the -p option. For example, route -p add 192.168.151.0 MASK 255.255.255.0 192.168.8.1 adds a persistent route. Persistent routes are stored in the registry location HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes and are used to initialize the IP routing table whenever the TCP/IP protocol is started 2.

You can also specify an address family with the route command. For example, route -6 add 2001:db8::/32 2001:db8::1 adds an IPv6 route 1.

When adding routes, it's important to consider the concept of "administrative distance," which refers to the trustworthiness of a route 5. If multiple routes for the same destination are available, the route with the lowest administrative distance is preferred.

In Cisco IOS, you can use the permanent parameter with the ip route command to ensure that the route remains in the routing table even if the interface goes down 5.

Deleting Routes

To remove a route from the routing table, you can use the route delete command. This can be useful when you want to remove a static route or when a route is no longer needed.

Linux:


Bash



sudo route del -net 192.168.1.0

This command deletes the route to the 192.168.1.0 network.

Windows:




route delete 192.168.1.0 mask 255.255.255.0

This command deletes the route to the 192.168.1.0 network with the specified subnet mask.

You can also use wildcards with the route delete command. For example, route delete 10.* deletes all routes in the IP routing table that begin with 10 2.

To clear the routing table of all gateway entries, use the -f option. For example, route -f clears the routing table 2.

You can also specify an address family with the route delete command. For example, route -6 delete 2001:db8::/32 deletes an IPv6 route 1.

Modifying Routes

In some cases, you may need to modify an existing route 6. This can be done by using the route change command in Windows or by deleting the existing route and adding a new one with the modified settings in Linux.

Windows:




route change 10.41.0.0 mask 255.255.0.0 10.27.0.25 metric 10

This command changes the next hop address of the route with the destination 10.41.0.0 and subnet mask 255.255.0.0 to 10.27.0.25 and sets the metric to 10 2.

The ip Command

The ip command in Linux provides a more modern and flexible way to manage network interfaces and routing 7. It offers a wider range of options and is generally preferred over the route command in newer Linux systems 8.

Here are some examples of how to use the ip command for routing:

  • Display the routing table: ip route show or ip r

  • Add a route: ip route add 192.168.1.0/24 via 192.168.1.1 dev eth0

  • Delete a route: ip route del 192.168.1.0/24

The ip command also allows you to modify interface parameters, such as MTU size or TX queue length. For example, ip link set mtu 1400 dev eth0 sets the MTU size of the eth0 interface to 1400 bytes, and ip link set txqueuelen 1000 dev eth0 sets the TX queue length to 1000 9.

The netstat Command

The netstat command displays various network-related information, including active connections, listening ports, and routing tables 10. It can be used to troubleshoot network connectivity issues and monitor network traffic.

Here are some examples of how to use the netstat command for routing and troubleshooting:

  • Display the routing table: netstat -r

  • Display interface statistics: netstat -i

  • Display extended interface statistics: netstat -ie 11

  • Display per-protocol statistics: netstat -s 12

  • Display masqueraded connections: netstat -M 11

  • Display multicast group memberships: netstat -g 11

  • Log network activity to a file: netstat -abf 5 > activity.txt 13

  • Continuously display network information: netstat -ic 11

  • Filter output with grep: netstat -an | grep ':80' 11

Other route Command Options

Besides the basic commands discussed earlier, the route command offers several other options for managing and troubleshooting routing:

  • route monitor (IBM OS/2): Reports any changes to the routing information base, routing lockup misses, or suspected network partitionings 14.

  • route get (IBM OS/2): Looks up and displays the route for a destination 14.

  • route set (IBM OS/2): Sets or modifies attributes of a route, such as weight and policy 14.

  • route flush (IBM OS/2): Removes all routes from the routing table 14.

Troubleshooting Routing Problems

Troubleshooting routing problems often involves a combination of techniques and tools. Here's a more cohesive approach to using the route command and other tools for troubleshooting:

  1. Identify the problem: Determine the specific routing issue you're experiencing. Are you unable to reach a particular network or host? Are you experiencing slow network performance or intermittent connectivity?

  2. Check the routing table: Use the route print command (Windows) or route -n command (Linux) to view the routing table. Look for any missing routes, incorrect gateways, or unusual metric values.

  3. Verify network interface status: Use the ip command or ifconfig command in Linux or the ipconfig command in Windows to check the status of your network interfaces. Ensure that the interfaces are up and running and have the correct IP addresses and subnet masks.

  4. Use ip route get to diagnose network paths: The ip route get command in Linux allows you to query the route that will be used to reach a specific IP address. For example, ip route get 8.8.8.8 shows the route to Google's DNS server 7.

  5. Use traceroute to diagnose network paths: The traceroute command sends packets to a destination and displays the path that the packets take through the network. This can help you identify any routing loops or points of failure along the path.

  6. Check for network congestion: Use the netstat command to monitor network traffic and identify any potential bottlenecks or congestion issues that may be affecting routing performance. For example, netstat -s displays per-protocol statistics, which can help you identify problems with specific protocols 12. You can also use netstat -i to display interface statistics, such as the number of packets received and transmitted, to identify potential issues with specific interfaces 4.

  7. Manage neighbor objects: Use the ip neigh command in Linux to manage neighbor objects (ARP or NDISC cache entries). This can be helpful for troubleshooting issues related to address resolution. For example, ip neigh show displays the neighbor cache, and ip neigh add 192.168.1.100 lladdr 00:11:22:33:44:55 dev eth0 adds a static ARP entry 9.

  8. Set default gateway: If you need to modify the default gateway, you can use the nmcli connection modify command in Linux. For example, sudo nmcli connection modify MyConnection ipv4.gateway 192.168.1.1 sets the default gateway for the connection named "MyConnection" to 192.168.1.1 7.

  9. Log network activity: For more in-depth troubleshooting, you can use netstat -abf 5 > activity.txt to log network activity to a file. This can be helpful for identifying patterns or anomalies in network traffic over time 13.

Remember that understanding the relationship between the route command and the underlying network configuration is crucial for effective troubleshooting 3 15. Factors such as IP addresses, subnet masks, and gateway settings all play a role in how routing decisions are made.

Research Methodology

The information for this article was gathered through a comprehensive research process involving the following steps:

  1. Information gathering: We collected information about the route command and its various options from reputable sources, including official documentation and technical websites.

  2. Example collection: We compiled examples of how to use the route command to view, add, delete, and modify routes in the routing table.

  3. Tool identification: We identified other tools and commands that can be used to display and change the routing table, such as the ip command and the netstat command.

  4. Troubleshooting research: We researched common routing problems and how to use the route command and other tools to troubleshoot them.

This multi-step approach ensured that the information presented in this article is accurate, comprehensive, and relevant to your needs.

Conclusion

The route command is a valuable tool for managing and troubleshooting network routing. By understanding its various options and how to interpret the output, you can effectively diagnose and resolve routing problems. Remember to use the appropriate syntax for your operating system and always exercise caution when making changes to the routing table, as incorrect configurations can disrupt network connectivity.

In addition to the route command, tools like the ip command and netstat command provide further capabilities for managing and troubleshooting network routing. By combining these tools and techniques, you can gain a deeper understanding of your network's routing behavior and ensure smooth and efficient communication.

Works cited

1. route (command) - Wikipedia, accessed on February 12, 2025, https://en.wikipedia.org/wiki/Route_(command)

2. route | Microsoft Learn, accessed on February 12, 2025, https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/route_ws2008

3. How to Troubleshoot Routing Problems - Auvik Networks, accessed on February 12, 2025, https://www.auvik.com/franklyit/blog/how-to-troubleshoot-routing-problems/

4. netstat command - IBM, accessed on February 12, 2025, https://www.ibm.com/docs/HW4L4/p8hcg/p8hcg_netstat.htm

5. IP Route command Explained with Examples - Computer Networking Notes, accessed on February 12, 2025, https://www.computernetworkingnotes.com/ccna-study-guide/ip-route-command-explained-with-examples.html

6. Windows 10 route change a single route - Server Fault, accessed on February 12, 2025, https://serverfault.com/questions/953593/windows-10-route-change-a-single-route

7. ip route add network command for Linux explained - nixCraft, accessed on February 12, 2025, https://www.cyberciti.biz/faq/ip-route-add-network-command-for-linux-explained/

8. Linux ip Command Examples - nixCraft, accessed on February 12, 2025, https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/

9. Linux ip Command with Examples {+ ip Cheat Sheet} - phoenixNAP, accessed on February 12, 2025, https://phoenixnap.com/kb/linux-ip-command-examples

10. Monitoring Network Status With the netstat Command, accessed on February 12, 2025, https://docs.oracle.com/cd/E19253-01/816-4554/ipconfig-142/index.html

11. Netstat Command in Linux - 25 Commands with Examples - phoenixNAP, accessed on February 12, 2025, https://phoenixnap.com/kb/netstat-command

12. Netstat Command Guide | Arguments, Examples, and Uses - IOFLOOD.com, accessed on February 12, 2025, https://ioflood.com/blog/netstat-linux-command/

13. Understanding and troubleshooting with the netstat command - Site24x7, accessed on February 12, 2025, https://www.site24x7.com/learn/linux/netstat-command.html

14. route Command - IBM, accessed on February 12, 2025, https://www.ibm.com/docs/ssw_aix_71/r_commands/route.html

15. Solved: Routing troubleshooting - Cisco Community, accessed on February 12, 2025, https://community.cisco.com/t5/routing/routing-troubleshooting/td-p/4664692


Feb 12

9 min read

0

10

0

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page