route
Display routing table
$ route # Displays list or routes and also resolves host names
$ route -n # Displays list of routes without resolving host names for faster results
Add/Delete route
Option | Description |
---|---|
add or del | Add or delete a route |
-host x.x.x.x | Add route to a single host identified by the IP address |
-net x.x.x.x | Add route to a network identified by the network address |
gw x.x.x.x | Specify the network gateway |
netmask x.x.x.x | Specify the network netmask |
default | Add a default route |
Examples:
$ route add -host x.x.x.x eth1
$ route add -net 2.2.2.0 netmask 255.255.255.0 eth0
route add -net 2.2.2.0/24 eth0
$ route add default gw 2.2.2.1 eth0
$ route del -net 2.2.2.0/24
ip
Display routing table
$ ip route show # List routing table
Add/Delete route
Option | Description |
---|---|
add or del or change or append or replace | Change a route |
show or flush | the command displays the contents of the routing tables or remove it |
restore | restore routing table information from stdin |
get | this command gets a single route to a destination and prints its contents exactly as the kernel sees it |
Examples:
$ ip route add default via 1.2.3.254
$ ip route add default via 192.168.1.1 dev eth0