Linux route command

Linux route command

In Linux and Unix-like systems, a gateway is nothing but a device that connects two networks. Often it is called a router or gateway. In most cases your ISP’s modem act as a default router or gateway.

  1. route command: show / manipulate the IP routing table on Linux.
  2. IP command: show / manipulate routing, devices, policy routing, and tunnels on Linux.

Display your current routing table

Open the Terminal or login to the server using ssh/console. Type the following command to display the routing table:
# route
OR
# route -n

# ip route show
OR
# ip route list

Linux route Add Command Examples

I am going to show you both IP and route commands. Most modern Linux distro recommends using the IP command to set or display the default gateway IP address on Linux. Let us see some examples.

Linux add a default route using the route command

Route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
# route add default gw 192.168.1.254 eth0

Linux add a default gateway (route) using IP command

Route all traffic via 192.168.1.254 gateway connected via eth0 network interface:
# ip route add 192.168.1.0/24 dev eth0

Verify newly added route IP in the Linux kernel routing table

To verify the new routing table, enter:
# ip route list
OR
# route -n

Leave a Reply