The ip route command in Linux is used to display, add, delete, and modify entries in the system routing table. It is part of the iproute2 package and replaces legacy networking tools like route and netstat.
Common ip route Syntax Patterns
Basic ip route syntax explained
The general syntax of the command is:
ip route { add | del | change | replace | show } DESTINATION OPTIONSWhere:
add→ Adds a new routedel→ Deletes a routechange→ Modifies an existing routereplace→ Updates or creates a routeshow→ Displays the routing table
Example:
ip route add 192.168.2.0/24 via 192.168.1.1Route management commands (add, del, change)
| Command | Description |
|---|---|
| ip route show | Display routing table |
| ip route add | Add a new route |
| ip route del | Delete an existing route |
| ip route change | Modify an existing route |
| ip route replace | Replace or create a route |
| ip route flush | Remove routes from table |
Route attributes and parameters
| Parameter | Description |
|---|---|
| via | Next-hop gateway |
| dev | Outgoing network interface |
| src | Preferred source IP address |
| metric | Route priority |
| table | Routing table ID |
| proto | Routing protocol identifier |
| scope | Route scope |
Example:
ip route add 192.168.10.0/24 via 192.168.1.1 dev eth0 metric 50Routing table identifiers
Linux systems can maintain multiple routing tables.
Common table identifiers include:
| Table | Description |
|---|---|
| main | Default routing table |
| local | Local interface routes |
| default | Default table used when no policy rule matches |
| custom tables | Defined in /etc/iproute2/rt_tables |
Example command:
ip route show table mainSpecial route types
Special route types control how packets are handled rather than forwarding them normally.
| Route Type | Description |
|---|---|
| blackhole | Silently drops packets |
| unreachable | Returns ICMP destination unreachable |
| prohibit | Returns ICMP communication prohibited |
Example:
ip route add blackhole 192.168.200.0/24This configuration discards all packets destined for the specified network.
Quick ip route Command Cheat Sheet
The following quick reference table summarizes the most commonly used ip route command syntax and options used by Linux administrators.
| Task / Description | Command |
|---|---|
| Display routing table | ip route show |
| Display routing table (short form) | ip route |
| Display routing table in specific table | ip route show table main |
| Display routes for specific interface | ip route show dev eth0 |
| Display routes to specific network | ip route show 192.168.1.0/24 |
| Show default gateway | ip route show default |
| Show routing decision for destination | ip route get 8.8.8.8 |
| Show routing decision using specific source IP | ip route get 8.8.8.8 from 192.168.1.10 |
| Add default gateway | ip route add default via 192.168.1.1 |
| Add default route via interface | ip route add default dev eth0 |
| Add route to network via gateway | ip route add 192.168.2.0/24 via 192.168.1.1 |
| Add route via specific interface | ip route add 192.168.2.0/24 dev eth1 |
| Add route with metric | ip route add 192.168.2.0/24 via 192.168.1.1 metric 100 |
| Add route with source address | ip route add 192.168.2.0/24 via 192.168.1.1 src 192.168.1.10 |
| Add route to specific routing table | ip route add 192.168.2.0/24 via 192.168.1.1 table 100 |
| Replace existing route | ip route replace 192.168.2.0/24 via 192.168.1.2 |
| Change gateway for existing route | ip route change 192.168.2.0/24 via 192.168.1.5 |
| Delete route to network | ip route del 192.168.2.0/24 |
| Delete default route | ip route del default |
| Delete route via gateway | ip route del 192.168.2.0/24 via 192.168.1.1 |
| Flush all routes in main table | ip route flush table main |
| Flush all routes | ip route flush cache |
| Add blackhole route (drop packets silently) | ip route add blackhole 192.168.3.0/24 |
| Add unreachable route (return error) | ip route add unreachable 192.168.4.0/24 |
| Add prohibit route (administratively blocked) | ip route add prohibit 192.168.5.0/24 |
| Add route with preferred source | ip route add 192.168.10.0/24 via 192.168.1.1 src 192.168.1.100 |
| Add multipath route (load balancing) | ip route add 10.0.0.0/24 nexthop via 192.168.1.1 nexthop via 192.168.1.2 |
| Add route with MTU setting | ip route add 192.168.20.0/24 via 192.168.1.1 mtu 1400 |
| Add route with protocol identifier | ip route add 192.168.30.0/24 via 192.168.1.1 proto static |
| Add route with scope | ip route add 192.168.40.0/24 dev eth0 scope link |
| Show all routing tables | ip route show table all |
View and Understand Routing Table in Linux
Understanding the routing table is the first step when troubleshooting network connectivity in Linux. The routing table determines how packets are forwarded between interfaces and gateways. Using the ip route command, administrators can quickly inspect the current routing configuration of the system.
Display routing table using ip route
To display the routing table in Linux:
ip routeExample output:
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10
10.0.0.0/8 via 192.168.1.2 dev eth1Explanation:
default→ Default route used when no other route matchesvia→ Next-hop gatewaydev→ Network interface used for the routesrc→ Preferred source IP address
This command is commonly used when verifying network configuration or connectivity issues.
Show routing table in detailed format
To display routes along with additional attributes:
ip route showYou can also display routes from the main routing table explicitly:
ip route show table mainThis helps when working with multiple routing tables or policy routing configurations.
Filter routes for specific interface
To view routes associated with a particular network interface:
ip route show dev eth0Example output:
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10This command is useful when diagnosing multi-interface servers or containers.
Show routes from specific routing table
Linux supports multiple routing tables used for advanced routing configurations.
To view routes from a specific table:
ip route show table 100To list all routing tables:
ip route show table allThis is commonly used in policy-based routing setups.
Understand default route in Linux
The default route defines where packets should be sent when no other route matches the destination network.
To display the default route:
ip route show defaultExample output:
default via 192.168.1.1 dev eth0Explanation:
default→ Catch-all routevia 192.168.1.1→ Gateway used to reach external networksdev eth0→ Interface used for outgoing traffic
Without a default route, the system cannot reach networks outside its local subnet.
Find Which Route a Packet Will Use
Sometimes multiple routes exist for the same destination. Linux decides which route to use based on metrics, routing tables, and policies. The ip route get command helps determine exactly which route the kernel will use.
Use ip route get to trace packet path
To check how the system routes packets to a destination:
ip route get 8.8.8.8Example output:
8.8.8.8 via 192.168.1.1 dev eth0 src 192.168.1.10Explanation:
via→ Gateway useddev→ Interface usedsrc→ Source IP chosen by the kernel
This command is extremely useful for debugging routing issues.
Determine gateway used for a destination
You can verify which gateway will be used to reach a host:
ip route get 1.1.1.1Example output:
1.1.1.1 via 192.168.1.1 dev eth0 src 192.168.1.10This confirms the next-hop gateway used by the system.
Check routing decision for a specific source IP
If a system has multiple IP addresses, Linux can choose different routes depending on the source IP.
To test this behavior:
ip route get 8.8.8.8 from 192.168.1.20This command simulates routing decisions for packets originating from the specified source address.
Troubleshoot asymmetric routing
Asymmetric routing occurs when incoming and outgoing traffic follow different paths.
Use the following command to analyze the outgoing route:
ip route get <destination-ip>Then verify incoming routes on the gateway or firewall.
This technique helps troubleshoot firewall drops and connection failures.
Add Routes in Linux
Adding routes allows administrators to control how traffic flows between networks. Static routes are often used in environments with multiple routers, VLANs, or isolated networks.
Add default gateway using ip route
To configure a default gateway:
ip route add default via 192.168.1.1This ensures all unknown network traffic is forwarded through the specified gateway.
Add route to a specific subnet
To route traffic to another network through a gateway:
ip route add 192.168.2.0/24 via 192.168.1.2Explanation:
192.168.2.0/24→ Destination network192.168.1.2→ Next-hop gateway
Add route through a specific network interface
If the network is directly reachable through an interface:
ip route add 10.10.0.0/16 dev eth1This route sends traffic directly through eth1.
Add route with custom metric value
Metrics determine route priority when multiple routes exist.
ip route add 192.168.3.0/24 via 192.168.1.2 metric 50Lower metric values are preferred over higher ones.
Example:
metric 10 → preferred
metric 50 → backup routeAdd persistent static route (distribution specific)
Routes added using ip route are temporary and will disappear after a reboot.
To make routes persistent, configure them in your network configuration:
Common locations:
| Distribution | Configuration File |
|---|---|
| Ubuntu | /etc/netplan/*.yaml |
| RHEL / Rocky Linux | /etc/sysconfig/network-scripts/route-eth0 |
| NetworkManager | nmcli connection modify |
| systemd-networkd | /etc/systemd/network/*.network |
Delete and Modify Existing Routes
Routing tables often need updates when network topology changes. The ip route command allows administrators to remove or modify routes dynamically.
Remove a route using ip route del
To delete a route:
ip route del 192.168.2.0/24If the route includes a gateway:
ip route del 192.168.2.0/24 via 192.168.1.2Replace existing route using ip route replace
To replace a route without manually deleting it first:
ip route replace 192.168.2.0/24 via 192.168.1.5This command safely updates the routing table.
Modify route gateway
If a gateway changes, update the route using:
ip route change 192.168.2.0/24 via 192.168.1.10This updates the next-hop gateway for the destination network.
Change route metric priority
To change the route priority:
ip route change 192.168.2.0/24 via 192.168.1.2 metric 100Routes with lower metric values are preferred by the Linux kernel.
Example scenario:
Primary route → metric 10
Backup route → metric 100If the primary route fails, Linux automatically uses the backup route.
Configure Multiple Default Routes
In environments with multiple internet connections or gateways, Linux can maintain more than one default route. This is commonly used for failover, redundancy, or load balancing. The ip route command allows administrators to configure multiple default routes with different priorities using route metrics.
Configure failover internet gateway
You can configure a primary and secondary gateway so that traffic automatically switches if the primary gateway becomes unreachable.
Example:
ip route add default via 192.168.1.1 metric 10
ip route add default via 192.168.2.1 metric 20Explanation:
192.168.1.1→ Primary gateway192.168.2.1→ Backup gateway- Lower metric routes are preferred
If the first gateway becomes unavailable, the system will automatically use the second route.
Configure backup default route with higher metric
Linux selects routes based on metric values. Lower metric values have higher priority.
Example configuration:
ip route add default via 10.0.0.1 metric 5
ip route add default via 10.0.1.1 metric 50In this setup:
- Traffic normally uses gateway
10.0.0.1 - Gateway
10.0.1.1acts as a backup path
Load balancing using multiple routes
Linux can distribute traffic across multiple gateways using Equal Cost Multi Path (ECMP) routing.
Example:
ip route add default \
nexthop via 192.168.1.1 dev eth0 \
nexthop via 192.168.2.1 dev eth1This configuration allows outgoing traffic to be balanced between the two gateways.
Configure Static Routes for Internal Networks
Static routes are used when networks must communicate through a specific router or interface. They are commonly used in multi-subnet environments, VLAN networks, and internal infrastructure networks.
Route traffic to internal subnets
To route traffic to another internal network through a gateway:
ip route add 10.10.0.0/16 via 192.168.1.2Explanation:
10.10.0.0/16→ Destination internal network192.168.1.2→ Router responsible for reaching that network
Configure routes between multiple network interfaces
If the destination network is reachable through another interface directly:
ip route add 172.16.0.0/16 dev eth1This route instructs Linux to send packets to the 172.16.0.0/16 network through the eth1 interface.
Route traffic between VLAN networks
When VLANs are separated into different networks, routing may be required between them.
Example:
ip route add 192.168.50.0/24 via 192.168.10.1This allows traffic to reach VLAN 192.168.50.0/24 through router 192.168.10.1.
Block or Control Traffic Using Special Routes
The ip route command supports special route types that can control or block network traffic. These routes are often used for security policies, traffic filtering, or preventing access to specific networks.
Drop packets using blackhole route
A blackhole route silently discards packets without notifying the sender.
Example:
ip route add blackhole 192.168.100.0/24Any traffic destined for 192.168.100.0/24 will be dropped.
Reject traffic using unreachable route
An unreachable route drops packets and returns an ICMP destination unreachable message.
Example:
ip route add unreachable 192.168.101.0/24The sender receives a notification that the destination cannot be reached.
Deny traffic using prohibit route
A prohibit route blocks access and returns an ICMP communication prohibited error.
Example:
ip route add prohibit 192.168.102.0/24Troubleshoot Network Connectivity Using ip route
When a system cannot reach another network or the internet, examining the routing table is often the first troubleshooting step. The ip route command provides essential insights into how packets are being forwarded.
Detect missing default gateway
If the system cannot reach external networks, verify the default route:
ip route show defaultIf no default route appears, external connectivity will fail.
Example fix:
ip route add default via 192.168.1.1Identify wrong gateway configuration
To verify which route the kernel will use:
ip route get 8.8.8.8Example output:
8.8.8.8 via 192.168.1.1 dev eth0 src 192.168.1.10If the gateway is incorrect, update the route accordingly.
Detect routing loops
Routing loops can occur when traffic repeatedly cycles between routers.
Inspect the routing table:
ip route showLook for routes pointing to gateways that may redirect traffic back to the originating host.
Verify routing changes after network restart
Routes configured using ip route are temporary. After a reboot or network restart, they may disappear.
Verify routes again:
ip routeIf routes are missing, configure them in the system’s persistent network configuration files.
Policy Based Routing (Advanced)
Policy-based routing (PBR) allows Linux to route traffic based on criteria such as source IP address, incoming interface, or routing tables, instead of relying only on the destination network. This approach is useful in complex networking environments where different traffic flows must use different gateways or network paths.
Create custom routing table
Linux supports multiple routing tables. To create a custom routing table, add an entry to the routing tables configuration file.
echo "100 customrt" >> /etc/iproute2/rt_tablesIn this example:
100is the table IDcustomrtis the name of the routing table
You can now reference this routing table when adding routes.
Example:
ip route add default via 192.168.2.1 table customrtAdd routing rules using ip rule
Routing rules determine which routing table should be used based on defined conditions.
Example rule:
ip rule add from 192.168.1.100 table customrtExplanation:
- Traffic originating from
192.168.1.100will use thecustomrtrouting table.
To view active rules:
ip rule showRoute traffic based on source IP
Policy-based routing allows different hosts or services to use different gateways.
Example:
ip rule add from 192.168.10.50 table customrt
ip route add default via 192.168.2.1 table customrtThis configuration forces traffic from 192.168.10.50 to use the gateway 192.168.2.1.
Route traffic based on network interface
Traffic can also be routed depending on which interface it arrives on.
Example:
ip rule add iif eth1 table customrtExplanation:
iifrepresents the incoming interface- Traffic entering through
eth1will follow routes defined incustomrt.
This technique is commonly used in firewall gateways and advanced routing environments.
Multi-homed Linux Server Configuration
A multi-homed server has multiple network interfaces connected to different networks or ISPs. Linux can manage multiple routes to control how traffic flows through these interfaces.
Configure multiple internet connections
To configure two internet gateways:
ip route add default via 192.168.1.1 metric 10
ip route add default via 192.168.2.1 metric 20Explanation:
192.168.1.1→ Primary ISP192.168.2.1→ Secondary ISP
The lower metric route is preferred.
Control outbound traffic per interface
Policy routing can force traffic from a specific interface or subnet to use a particular gateway.
Example:
ip rule add from 192.168.2.0/24 table isp2
ip route add default via 192.168.2.1 table isp2This configuration ensures that traffic from the 192.168.2.0/24 network uses the second ISP.
Use metrics to prioritize ISPs
Metrics determine which route the kernel prefers when multiple paths exist.
Example:
ip route add default via 10.0.0.1 metric 5
ip route add default via 10.0.1.1 metric 50In this setup:
10.0.0.1is the preferred ISP10.0.1.1acts as a backup connection
This configuration provides automatic failover.
Advanced Routing Features in Linux
Linux supports several advanced routing features that improve network redundancy, performance, and flexibility.
Equal Cost Multi Path (ECMP) routing
ECMP allows traffic to be distributed across multiple gateways with the same cost.
Example:
ip route add default \
nexthop via 192.168.1.1 dev eth0 \
nexthop via 192.168.2.1 dev eth1With ECMP, the system balances outgoing traffic across both gateways.
Route traffic through tunnel interface
When using VPN tunnels, traffic may need to be routed through a tunnel interface.
Example:
ip route add 10.10.0.0/16 dev tun0Explanation:
tun0represents a tunnel interface created by VPN software.
Traffic destined for 10.10.0.0/16 will now pass through the VPN tunnel.
Route traffic through VPN gateway
To route traffic through a VPN gateway:
ip route add 172.16.0.0/16 via 10.8.0.1 dev tun0This configuration ensures that traffic destined for the remote network uses the VPN gateway.
Make ip route Changes Persistent
Routes configured with ip route are temporary and will disappear after a reboot or network restart. To make routing changes persistent, they must be configured in the system’s network configuration files.
Persist routes in NetworkManager
Using NetworkManager CLI:
nmcli connection modify eth0 +ipv4.routes "192.168.50.0/24 192.168.1.1"
nmcli connection up eth0This permanently adds the route to the NetworkManager configuration.
Persist routes in Netplan (Ubuntu)
Edit the Netplan configuration file:
/etc/netplan/*.yamlExample configuration:
network:
version: 2
ethernets:
eth0:
routes:
- to: 192.168.50.0/24
via: 192.168.1.1Apply the configuration:
netplan applyPersist routes in RHEL / Rocky Linux
Edit the route configuration file for the interface:
/etc/sysconfig/network-scripts/route-eth0Example:
192.168.50.0/24 via 192.168.1.1Restart networking:
systemctl restart networkPersist routes using systemd-networkd
Create or edit the interface configuration file:
/etc/systemd/network/10-eth0.networkExample configuration:
[Route]
Destination=192.168.50.0/24
Gateway=192.168.1.1Restart the service:
systemctl restart systemd-networkdThis ensures the routing configuration is automatically applied after reboot.
Why route command is deprecated
The route command belongs to the legacy net-tools package, which is no longer actively maintained. Modern Linux distributions recommend using iproute2 utilities instead because they support newer networking features and kernel capabilities.
Limitations of the route command include:
- Limited support for advanced routing features
- No support for policy-based routing
- Less structured output compared to
ipcommands - Missing support for modern networking technologies
Because of these limitations, administrators are encouraged to use the ip route command for managing routing tables.
Example of legacy route command:
route -nModern equivalent:
ip routeDifferences between ip route and route
The following table highlights the key differences between the two tools.
| Feature | ip route | route |
|---|---|---|
| Package | iproute2 | net-tools |
| Maintenance status | Actively maintained | Deprecated |
| Policy routing support | Yes | No |
| Multipath routing support | Yes | No |
| Output format | Structured and script-friendly | Less structured |
| Modern kernel features | Supported | Limited |
Example comparison:
Display routing table:
ip routeLegacy command:
route -nWhen legacy route command may still appear
Although deprecated, the route command may still exist in some environments:
- Older Linux distributions
- Systems where the net-tools package is manually installed
- Legacy scripts written before iproute2 became standard
In such cases, administrators may still encounter commands like:
route add default gw 192.168.1.1Modern equivalent:
ip route add default via 192.168.1.1For new configurations and automation scripts, the ip command suite should always be preferred.
Frequently Asked Questions
1. What is the ip route command used for in Linux?
The ip route command is used to display and modify the routing table in Linux systems. It allows administrators to view routes, add static routes, delete routes, and control how packets are forwarded between networks.2. How do I display the routing table in Linux?
You can display the routing table using the command ip route or ip route show. This command lists all routes, gateways, interfaces, and routing priorities configured on the system.3. How do I add a route using ip route command?
To add a static route in Linux, use a command like ip route add 192.168.2.0/24 via 192.168.1.1. This instructs the system to send traffic destined for the specified network through the given gateway.4. What is the difference between ip route and route command?
The ip route command is part of the modern iproute2 networking suite and supports advanced routing features such as policy-based routing and multipath routing. The route command belongs to the older net-tools package and is considered deprecated on modern Linux systems.Summary
The ip route command is the modern and recommended tool for managing routing tables in Linux systems. It provides administrators with powerful capabilities to inspect routing behavior, configure static routes, manage multiple gateways, and implement advanced routing policies.
Key takeaways:
ip routeis part of the iproute2 suite and replaces legacy tools likeroute.- It allows administrators to view, add, modify, and delete routes dynamically.
- Advanced features such as policy-based routing, multipath routing, and special routes make it suitable for modern networking environments.
- Routes configured using
ip routeare typically temporary, so persistent configurations must be defined in system network configuration files.
Understanding how to use the ip route command effectively helps administrators troubleshoot connectivity problems and manage complex network environments with confidence.
Official Documentation
For more detailed information about Linux routing and the ip route command, refer to the official resources:


