When a Linux server possesses multiple network interface cards (for example, one card connected to the public internet and a second card connected to a private database subnet), the Linux kernel must instantly decide which card to use every single time it transmits a packet. It makes this decision by consulting its internal routing table. If your server suddenly cannot reach the internet or cannot speak to the database, the routing table is likely broken or misconfigured. To view and manipulate this critical map, you must use the route command.
How to View the Kernel Routing Table
To simply view the current routing table without making any changes, you do not need administrative privileges. Open your terminal and run:
route -n
(Note: You should always use the -n numeric flag. If you omit it, the command will attempt to resolve every IP address into a human-readable hostname via DNS, which can cause the output to hang for several minutes if the network is down.)
The terminal will output a clean table. The most critical line is the Default Gateway. Look for the line where the “Destination” column is exactly 0.0.0.0. The IP address listed next to it under the “Gateway” column is the router your server is using to access the outside world. If that IP address is incorrect or missing, your server is completely isolated from the internet.
How to Add a Static Route
If you recently added a private subnet to your network (e.g., 10.0.5.0/24) and your server cannot reach it, you must manually insert a static route instructing the kernel exactly where to send that traffic.
Because you are modifying the kernel’s behavior, you must use sudo. To route all traffic destined for the 10.0.5.0 network through a specific internal router (e.g., 192.168.1.50), run:
sudo route add -net 10.0.5.0 netmask 255.255.255.0 gw 192.168.1.50
As soon as you press Enter, the kernel will update its internal map. Any packet destined for that subnet will immediately be fired at the 192.168.1.50 router.
How to Delete a Broken Route
If a route is incorrect and forcing traffic into a black hole, you must delete it. You use the exact same syntax as the add command, but you replace it with del.
To delete the route we just created above, run:
sudo route del -net 10.0.5.0 netmask 255.255.255.0 gw 192.168.1.50
Important Note: Changes made using the route command are strictly temporary. They are injected directly into live RAM. If you reboot the server, these custom routes will be wiped out. To make them permanent, you must add them to your distribution’s persistent network configuration files (e.g., Netplan for Ubuntu, or NetworkManager for RHEL).