Linux servers and desktops rely on routing tables to determine how network packets move between interfaces and destinations. Incorrect routing configuration leads to connectivity problems, inefficient network paths, and service downtime. Adjusting routing settings allows you to control which network interfaces handle specific traffic, set up gateways, and implement advanced policies for complex environments.
Configuring Routing with ip Command
ip route show
This command lists all routes, including default gateways and interface-specific paths. Reviewing this output helps you avoid conflicts when adding new routes.
192.168.10.0/24 via gateway 10.0.0.1 on interface eth1:
sudo ip route add 192.168.10.0/24 via 10.0.0.1 dev eth1
This command tells Linux to send packets for the specified subnet through the provided gateway and interface. Adjust the subnet, gateway, and interface names as needed for your environment.
sudo ip route replace default via 192.168.1.1 dev eth0
This command replaces any existing default route with the new gateway and interface. Only one default route should exist at a time to avoid routing conflicts.
ip are temporary and reset after a reboot. To save them permanently, edit your network configuration files. On most distributions, add static routes to /etc/network/interfaces (Debian/Ubuntu) or /etc/sysconfig/network-scripts/route-ethX (CentOS/RHEL), replacing ethX with your actual interface name.Join readers who trust AllThings.How
Add us as a preferred source on Google so our practical guides show up first next time you search.
Add to Google Preferences →Setting Up Policy-Based Routing with ip rule
Policy-based routing lets you define routing rules based on source addresses, interfaces, or other criteria, rather than just destination IPs. This is useful in multi-homed systems or advanced network setups.
100 customtable
This assigns the name customtable to table number 100 for easy reference.
10.20.30.0/24 through gateway 192.168.2.1 on eth2:
sudo ip route add 10.20.30.0/24 via 192.168.2.1 dev eth2 table customtable
This places the route in your custom routing table, not the main table.
192.168.100.5 through your custom table:
sudo ip rule add from 192.168.100.5/32 table customtable
This rule tells Linux to consult the customtable for traffic from the specified source address. Multiple rules can be stacked for complex scenarios.
ip rule show
Rules are evaluated in sequence, so order can affect routing behavior. Adjust priorities as needed using the priority option.
Configuring Routing with route Command (Legacy Method)
The route command is an older tool for managing routes, still available on many systems but generally replaced by ip. If required, you can use it as follows:
route -n
This provides a numeric table of current routes.
sudo route add -net 192.168.10.0 netmask 255.255.255.0 gw 10.0.0.1 dev eth1
This command works similarly to the ip route add example, but uses older syntax.
route must also be added to network configuration files, as described previously.With proper routing configuration, Linux systems direct traffic efficiently, support multi-homed setups, and avoid common networking pitfalls. Regularly review and update routing tables to adapt to network changes and maintain optimal connectivity.






