Add, inspect and remove static routes from the shell to steer Linux traffic exactly where you need it. 16.11.2025 | reading time: 3 min Static routes tell the kernel how to reach specific networks without asking a dynamic protocol; use the "ip route" command from iproute2 to add, view and remove those rules directly from the shell. Real situation: reach a remote subnet Scenario: a server on 10.0.0.2/24 must reach 192.168.200.0/24 via a next hop 10.0.0.1 on eth0; execute the steps below to add and verify a static route. ```bash # look at the interface and address ip addr show dev eth0 # add the static route ip route add 192.168.200.0/24 via 10.0.0.1 dev eth0 # list routes to confirm ip route show # test which path will be used ip route get 192.168.200.45 ``` Example output after the add will include a line like "192.168.200.0/24 via 10.0.0.1 dev eth0" and `ip route get` reports the chosen src and gateway, which you can then test with ping or tcpdump. Change, remove and check To remove that route run `ip route del 192.168.200.0/24 via 10.0.0.1 dev eth0` and to replace an existing entry use `ip route replace`; include "metric" to prefer one route over another and use `ip route get` to see which address and device the kernel will use for a specific destination. Make routes survive reboots Routes added with "ip route" are ephemeral by default; persist them with your distro's network system: add "up ip route add ..." lines in Debian `/etc/network/interfaces`, put static-routes in CentOS `/etc/sysconfig/network-scripts/route-eth0`, supply a "routes:" section in Netplan YAML on modern Ubuntu, or use NetworkManager's connection settings or nmcli to define persistent routes. Advanced uses and behaviors Use multiple next hops for simple ECMP with "nexthop" entries, place rules in alternate routing tables and pair them with `ip rule` for policy routing, mark packets in iptables for advanced selection, and use special route types like "blackhole" or "prohibit" to drop or reject traffic intentionally. Where to look next Inspect the kernel routing cache and live changes with `ip monitor route` and correlate entries with `ip neigh` (ARP/ND) plus system logs; when troubleshooting, combine `tcpdump` with `ip route get` and `ss` to verify path, source IP and socket behavior. Mastering static routes is immediate and practical: add a route, test it, remove it — repeat until it feels natural; then persist the working recipe in your network configuration and automate with scripts or configuration management for production reliability. Join Bits & Bytes Academy First class LINUX exam preparation. network utilities troubleshooting infrastructure