route

View and modify the Linux kernel routing table

Syntax

route [options] [command] [target] [netmask Nm] [gw Gw] [metric M] [dev If]

Basic Usage

Display routing table

route

Shows the current routing table with hostnames.

Display routing table (numeric)

route -n

Shows the routing table with IP addresses instead of hostnames.

Add a network route

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.0.1

Add a host route

route add -host 192.168.1.100 gw 192.168.0.1

Common Options

  • -n: Show addresses in numeric format
  • -v: Verbose mode
  • -A family: Specify address family (inet, inet6)
  • -F: Display kernel FIB routing table
  • -C: Display routing cache
  • -e: Display routing table in netstat format
  • -ee: Display routing table with extended information

Practical Examples

View current routing table

route -n

Add default gateway

route add default gw 192.168.0.1

Add route for specific network

route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.0.10

Delete a route

route del -net 192.168.1.0 netmask 255.255.255.0

Add route with specific interface

route add -net 172.16.0.0 netmask 255.255.0.0 gw 192.168.0.5 dev eth0

Add route with metric

route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.0.2 metric 100

Understanding Output

Routing Table Columns

  • Destination: Target network or host
  • Gateway: Next hop router
  • Genmask: Network mask
  • Flags: Route characteristics (U=up, G=gateway, H=host, D=dynamic)
  • MSS: Maximum segment size
  • Window: TCP window size
  • irtt: Initial round trip time
  • Iface: Network interface

Best Practices

When to Use

  • Configuring static routes for specific networks
  • Setting up routing for multiple network interfaces
  • Network troubleshooting and diagnostics
  • Custom network configurations

Important Notes

  • Changes made with route are temporary and lost on reboot
  • Use ip route for persistent routing configuration
  • Be careful when modifying routing tables on production systems
  • Always verify routes before and after changes
  • Consider using ip route command for modern systems

See Also

  • ip - Modern network configuration tool
  • netstat - Network statistics and routing
  • ss - Socket statistics
  • ifconfig - Network interface configuration