What is gateway in route command?

You might want to add or delete routes in your routing table depending on the changes in your network. You can use the route command to modify the routing table.

Step

  1. Depending on whether you want to add or delete a route from the routing table, perform the following step:
    If you want to...Enter the following command...
    Add a route

    route add destination [gateway metric]

    destination is the IP address or host name of the destination for which the route is being added or deleted.

    gateway is the gateway for the specified destination.

    metric indicates the number of hops to the destination. The value of metric should be greater than zero when the route to the destination is through the gateway. The value of metric is zero when the destination is on a directly-attached network.

    Delete a route

    route delete destination [gateway metric]

    Attention: You must not delete a cloned route (denoted by the C flag) from the routing table; if you do, the network connectivity to that subnet is lost. If you have deleted a cloned route, you must add the route again to the routing table in either of the following ways:

    • Bring the interface that connects to the particular subnet first to the down state and then to the up state.

      You can change the state of the interface by using the ifconfig command.

    • Delete and reconfigure the IP address on the interface that connects to the particular subnet.

    For more information about the route command and options, see the na_route(1) man page.

Example

To add a destination with the IP address 192.0.2.25 to the routing table, enter the following command:

route add 192.0.2.25 gateway.com 1

You can verify that the route to this destination is added to the routing table by using the netstat -rn or route -sn command, as shown in the following output:

system1> netstat -rn
Routing tables

Internet:
Destination      Gateway            Flags     Refs     Use  Interface
default          192.0.2.1          UGS         4   184855  e0a
127.0.0.1        127.0.0.1          UH          0        0  lo
192.0.2/24       link#11            UC          2     1238  e0a
192.0.2.1        0:d0:d3:0:30:0     UHL         0       40  e0a
192.0.2.23       0:1:30:b8:30:c0    UHL         1        0  e0a
192.0.2.25       192.0.2.1          UHL         0     1285  lo

In this example, the subnet route, 192.0.2, is a cloned route.

Download Article

Download Article

If you need to find or change the IP address of your default gateway or router on Linux, you're in luck—it's super easy to do. This wikiHow article will show you how to use the route command to find the default gateway IP address on Linux, and how to set a new default gateway in your /etc/network/interfaces configuration file.

  1. What is gateway in route command?

    1

    Open the Terminal. You can open the Terminal from the side bar, or by pressing Ctrl+Alt+T.[1]

  2. What is gateway in route command?

    2

    View your current default gateway. You can check what your default gateway is set to by typing route and pressing Enter. The address next to "default" shows your default gateway, and the interface it is assigned to is displayed on the right side of the table.

    Advertisement

  3. What is gateway in route command?

    3

    Delete your current default gateway. If you have more than one default gateway set, you'll run into connection conflicts. Delete your existing default gateway if you intend to change it.[2]

    • Type sudo route delete default gw IP Address Adapter. For example, to delete the default gateway 10.0.2.2 on the eth0 adapter, type sudo route delete default gw 10.0.2.2 eth0.

  4. What is gateway in route command?

    4

    Type .sudo route add default gw IP Address Adapter. For example, to change the default gateway of the eth0 adapter to 192.168.1.254, you would type sudo route add default gw 192.168.1.254 eth0.[3] You'll be prompted for your user password in order to complete the command.

  5. Advertisement

  1. What is gateway in route command?

    1

    Open the configuration file in an editor. Type sudo nano /etc/network/interfaces to open the file in the nano editor. Editing your configuration file will keep your changes every time the system restarts.[4]

  2. What is gateway in route command?

    2

    Navigate to the correct section. Find the section for the adapter you want to change the default gateway for. For a wired connection, this is usually eth0.

  3. What is gateway in route command?

    3

    Add .gateway IP Address to the section. For example, type gateway 192.168.1.254 to make the default gateway 192.168.1.254.[5]

  4. What is gateway in route command?

    4

    Save your changes and exit. Press Ctrl+X and then Y to save your changes and exit.

  5. What is gateway in route command?

    5

    Restart your network. Restart your network by typing sudo /etc/init.d/networking restart.[6]

  6. Advertisement

Add New Question

  • Question

    Will the admins know if I change my IP?

    What is gateway in route command?

    Yes, if they chose to check.

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

Video

Thanks for submitting a tip for review!

About This Article

Article SummaryX

1. Open a terminal window.
2. Type "sudo route delete default gw (IP) (Adapter)" and press Enter.
3. Type "sudo route add default gw (IP) (Adapter)" and press Enter.
4. Open /etc/network/interfaces in a text editor.
5. Update the gateway IP address for the adapter.
6. Save your changes and exit the editor.
7. Type "sudo /etc/init.d/networking restart" and press Enter.

Did this summary help you?

Thanks to all authors for creating a page that has been read 936,497 times.

Is this article up to date?

What is gateway in route?

A gateway is the entrance point to another network. A default gateway is the address to which packets are sent if there is no specific gateway for a given destination listed in the routing table.

What is route and default gateway?

A router, by definition, is a device or computer that sends packets between two or more network segments as necessary, using logical network addresses, most often IP addresses. The default gateway is the path used to pass information when the device doesn't know where the destination is.

What is gateway in netstat?

Remember that the default gateway is the place we send network traffic in the event that we don't know where else to send it. The default gateway is currently up (indicated by the 'U' flag) but the flag also indicates a 'G' which shows that it is a gateway and the interface is eth0.

What is gateway in CCNA?

The default gateway is a device such as a router that serves as the edge devices providing an access point to other networks and is used to forward IP packets which does not match any routes in the routing table.