Copied to clipboard

route

This command is used to view and modify the routing table in a Linux computer network. It can display the contents of the current routing table, add or delete routing table entries, and set the default gateway.

View routing table

Add static route

For example: 192.168.10.0
For example: 255.255.255.0
For example: 192.168.10.1
For example: eth0

Delete static route

For example: 192.168.10.0
For example: 255.255.255.0
For example: 192.168.10.1
For example: eth0

Add default gateway

For example: 192.168.10.1
For example: eth0

Note

Please note that since Linux kernel version 4.20, the route command has been replaced by the ip route command. The ip route command provides more features and flexibility, so it is recommended to use the ip route command to manage the routing table on newer Linux systems.

Examples

  • Display the current routing table entries:
route -n
  • Add a new route:
route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.1.1
  • Delete a routing table entry:
route del -net 192.168.0.0 netmask 255.255.255.0
  • Set the default gateway:
route add default gw 192.168.1.1