How to add a static route with ip route

Adding a static route with ip route add sends traffic for one destination prefix to a chosen next hop instead of leaving that traffic to the default route. This is useful for lab networks, site-to-site VPN subnets, and hosts that need a deliberate path to one remote network without changing every other route.

The command writes the route directly into the running kernel routing table. A typical static route names the destination prefix, the gateway with via, and the egress interface with dev; if no table is specified, the route is added to the main table, while policy-routing setups can add table 100 or another custom table ID.

A static route takes effect immediately, so a wrong prefix length or unreachable next hop can break access just as quickly as a correct route fixes it. Confirm the gateway is valid for the selected interface before adding the entry, and plan to update the system's persistent network configuration separately if the route should survive a restart.

Steps to add a static route with ip route:

  1. Check the current routing table before adding the new prefix.
    $ ip route show
    default via 192.0.2.1 dev eth0
    192.0.2.0/24 dev eth0 proto kernel scope link src 192.0.2.10
  2. Add the static route for the target subnet through the chosen gateway and interface.
    $ sudo ip route add 198.51.100.0/24 via 192.0.2.1 dev eth0

    Use dev eth0 without via only for an on-link destination. Add table 100 when the route belongs in a custom policy-routing table instead of the main table.

  3. Verify that the new route entry is present.
    $ ip route show 198.51.100.0/24
    198.51.100.0/24 via 192.0.2.1 dev eth0
  4. Confirm that the kernel now selects the new route for traffic to that subnet.
    $ ip route get 198.51.100.10
    198.51.100.10 via 192.0.2.1 dev eth0 src 192.0.2.10
        cache
  5. Persist the same route in the host's normal network configuration only after the runtime test works.

    Routes added with ip route add are usually lost after an interface restart or reboot until the network config is updated.