0% found this document useful (0 votes)
921 views32 pages

Why Does The Default Gateway Route Entry Disappear After Restarting The Network Service in RHEL

The default gateway route entry disappears from the routing table after restarting the network service in RHEL because the NETWORK parameter in the interface configuration file is set incorrectly. Specifically, if NETWORK does not match the actual network based on the IP address and netmask, it will cause the default gateway to be removed. Removing the NETWORK or DEFROUTE parameters from the interface configuration resolves the issue.

Uploaded by

iftikhar ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
921 views32 pages

Why Does The Default Gateway Route Entry Disappear After Restarting The Network Service in RHEL

The default gateway route entry disappears from the routing table after restarting the network service in RHEL because the NETWORK parameter in the interface configuration file is set incorrectly. Specifically, if NETWORK does not match the actual network based on the IP address and netmask, it will cause the default gateway to be removed. Removing the NETWORK or DEFROUTE parameters from the interface configuration resolves the issue.

Uploaded by

iftikhar ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Why does the default gateway route entry disappear after restarting

the network service in RHEL?

Environment

 Red Hat Enterprise Linux 5


 Red Hat Enterprise Linux 6
 Red Hat Enterprise Linux 7

Issue

 After a network service restart or a server reboot, the default gateway entry disappears from
the IP routing table:

Raw
[root@test sysconfig]# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.10 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@test sysconfig]#
[root@test sysconfig]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@test sysconfig]# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.10 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
[root@test sysconfig]#

 The interface has a static IP with the parameter GATEWAY in /etc/sysconfig/networking-


scripts/ifcfg-eth0
 Why is the default route missing after reboot?
 Network default gateway address cannot be added

Resolution

 Remove the following directives if present in


either /etc/sysconfig/network-scripts/ifcfg-ethX  or /etc/sysconfig/network:
o NETWORK
o DEFROUTE=no
Root Cause

 Issue will be seen if the parameter NETWORK is assigned an incorrect value. For instance, below is
a sample configuration file:

Raw
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
NETWORK=192.168.10.0
GATEWAY=192.168.1.1
ONBOOT=yes

 When considering the values for the parameters IPADDR and NETMASK, the correct value
for NETWORK is 192.168.1.0, not 192.168.10.0; the latter is totally a different network
 The directive DEFROUTE=no is used if the interface should never act as a default gateway

Diagnostic Steps

 Check whether default gateway can be added using the commands route or ip


 Ensure the parameter GATEWAY is available either
in /etc/sysconfig/network or /etc/sysconfig/network-scripts/ifcfg-ethX

Note the following additional information about creating and displaying information about persistent routes:

 Use the route command with the –p option to add a persistent route:

# route -p add default ip-address

 Use the route command with the –name option to add a persistent route by specifying a name rather than
destination and gateway:

# route -p add destination-address gateway-address -name name

 For routes that are created by using the route command, use the route –p show command to display all of the
persistent static routes:

# route -p show

 To display the currently active routes on a system, use the netstat command with the following options:

# netstat -rn

For more information, see the netstat(1M) and route(1M) man pages.


How to Add a Persistent Static Route by Specifying Destination and
Gateway
1. View the current state of the routing table by using your regular user account.

% netstat -rn
The output would be similar to the following:

Routing Table: IPv4


Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ---------- ---------
192.0.2125 192.0.2.10 U 1 5879 net0
224.0.0.0 198.0.2.10 U 1 0 net0
default 192.0.2.10 UG 1 91908
127.0.0.1 127.0.0.1 UH 1 811302 lo0

Routing Table: IPv6


Destination/Mask Gateway Flags Ref Use If
--------------------------- --------------------------- ----- --- ------- -----
::1 ::1 UH 2 0 lo0

2. Become an administrator.
3. (Optional) Flush the existing entries in the routing table.

# route flush

4. Add a persistent route.

# route -p add -net network-address -gateway gateway-address


–p
Creates a route that persists across system reboots. If you want the route to persist only for the current
session, do not use the –p option.

–net network-address
Specifies that the route goes to the network with the address that is specified in network-address.

–gateway gateway-address
Indicates that the gateway system for the specified route has the IP address gateway-address.

Example 10  Adding a Persistent (Static) Route by Specifying a Destination

The following example shows how to add a static route to a router (Router 2). The static route is needed for the AS's
border router, 203.0.113.150. See Autonomous System With Multiple IPv4 Routers for an illustration of this particular
setup.

You would view the routing table on Router 2 as follows:


# netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
default 198.51.100.10 UG 1 249 ce0
224.0.0.0 198.51.100.10 U 1 0 ce0
203.0.113.0 203.0.113.20 U 1 78 bge0
127.0.0.1 127.0.0.1 UH 1 57 lo0

Routing Table: IPv6


Destination/Mask Gateway Flags Ref Use If
--------------------------- --------------------------- ----- --- ------- -----
::1 ::1 UH 2 0 lo0

The routing table indicates that there are two routes that Router 2 knows about. The default route uses Router
2's 198.51.100.10 interface as its gateway. The second route, 203.0.113.0, was discovered by the in.routed daemon
that is running on Router 2. The gateway for this route is Router 1 and it has the IP address 203.0.113.20.

You would add a second route to network 203.0.113.0, which has its gateway as the border router, as follows:

# route -p add -net 203.0.113.0/24 -gateway 203.0.113.150


add net 203.0.113.0: gateway 203.0.113.150

The routing table now has a route for the border router, which has the IP address 203.0.113.150.

# netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
default 198.51.100.10 UG 1 249 ce0
224.0.0.0 198.51.100.10 U 1 0 ce0
203.0.113.0 203.0.113.20 U 1 78 bge0
203.0.113.0 203.0.113.150 U 1 375 bge0
127.0.0.1 127.0.0.1 UH 1 57 lo0

Routing Table: IPv6


Destination/Mask Gateway Flags Ref Use If
--------------------------- --------------------------- ----- --- ------- -----
::1 ::1 UH 2 0 lo0

How to Specify a Name for a Persistent Static Route


When you add a persistent static route, you can provide a name for the route by using the –name option. You can
specify any name other than the name, default, as this name has a special meaning within the context of routing
configuration. See the route(1M) man page for more information.

If you create a persistent route by specifying the –name option, you can display information about the route by
specifying its name rather than the destination. You can also modify and delete the route by specifying its name. Note
that you cannot use the –name option to name an existing route. Nor can you change the name of a route that you
previously named by using this option. To assign a name to an existing route or to modify the name of an existing
route that you previously named, first delete that route and then add the route again by specifying the –name option.

1. Become an administrator.
2. Add a persistent route by specifying a name.
# route -p add destination-address gateway-address -name name

where –name is the name that you refer to the persistent route by instead of its destination and gateway. The –
name option is ignored for non-persistent routes.

3. Display information about the route.

# route get -name route-name


You can also display information about the route as follows:

# route -p show
Example 11  Adding a Persistent (Static) Route by Specifying a Name

The following example shows how you would add a persistent static route (route1) by specifying a name.

# route -p add 9.9.9.9 3.3.3.9 -name route1


persistent: route add 9.9.9.9 3.3.3.9 -name route1
# route get -name route1
route to : 9.9.9.9
name : route1
destination : 9.9.9.9
mask : 255.255.255.25
gateway : 3.3.3.9
interface : net0
flags : <UP,GATEWAY,HOST,DONE,STATIC>
recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire
0 0 0 0 0 0 1500 0
Example 12  Changing Information for a Persistent (Static) Route by Specifying the Route's Name

The following example shows how to modify information for a persistent route by specifying its name. In this example,
the gateway information is changed. Note that the persistent route must have been added by specifying a name
initially.

# route -p show
persistent: route add 9.9.9.9 3.3.3.9 -name route1
# route change -name route1 9.9.8.8
change host -name route1 9.9.9.9: gateway 9.9.8.8
Example 13  Deleting a Persistent (Static) Route by Specifying the Route's Name

The following example shows how you would delete a persistent route by specifying its name. Note that the persistent
route must have been added by specifying a name initially.

# route -p delete -name route1


delete host -name route1 9.9.9.9: gateway 3.3.3.9: not in table
delete persistent host -name route1 9.9.9.9: gateway 3.3.3.9

If you do not speicfy the –p option with the –name option, the route is removed from the routing tables only, as shown
in the following example:

# route delete -name route1


delete host -name route1 9.9.9.9: gateway 3.3.3.9
Add / setup a new route
The syntax is as follows:

route add default gw {IP-ADDRESS} {INTERFACE-NAME}


Where,

 IP-ADDRESS: Specify router IP address


 INTERFACE-NAME: Specify interface name such as eth0
For example if your router IP address is 192.168.1.254 type the following
command as the root user:
# route add default gw 192.168.1.254 eth0
OR use hostname such as dsl-router:
# route add default gw dsl-router eth0
Or use the ip command (newer syntax) to route all traffic via 192.168.1.254
gateway connected via eth0 network interface:
# ip route add 192.168.1.0/24 dev eth0
OR
# ip route add 192.168.1.0/24 via 192.168.1.254

Setting route using GUI tools/command under Linux


If you find above command hard to use, consider using GUI tools. If your are
using Red Hat/CentOS/Fedora core Linux type following command:# redhat-
config-networkOR If you are using other Linux distribution use command: #
network-admin

Prerequisites
In order to add routes on your Linux machine, you need to have administrator rights.

In order to verify it, you can run the “sudo” command followed by the “-v” option (in order to update
your cached credentials).
$ sudo -v

If you don’t have sudo rights, you can have a look at our dedicated articles on getting administrator
rights on Ubuntu or CentOS.

Add route on Linux using ip


The easiest way to add a route on Linux is to use the “ip route add” command followed by
the network address to be reached and the gateway to be used for this route.

$ ip route add <network_ip>/<cidr> via <gateway_ip> # Example

$ ip route add 10.0.3.0/24 via 10.0.3.1

By default, if you don’t specify any network device, your first network card, your local loopback
excluded, will be selected.

However, if you want to have a specific device, you can add it to the end of the command.

$ ip route add <network_ip>/<cidr> via <gateway_ip> dev <network_card_name>

As an example, let’s say that you want two LAN networks to be able to communicate with each
other.

The network topology has three different Linux machines :

 One Ubuntu computer that has the 10.0.2.2/24 IP address;


 Another Ubuntu computer that has the 10.0.3.2/24 IP address;
 One RHEL 8 computer that will act as a simple router for our two networks.
The first computer cannot ping the other computer, they are not in the same subnet : 10.0.2.0 for the
first computer network and 10.0.3.0 for the second one network.

As the two hosts are not part of the same subnet, the ping command goes to the default gateway.

In order to see the routes already defined on your machine, use the “ip route” command with no
arguments. You can also use the “ip r” command as an abbreviation.

$ ip r

This is the routing table of your Linux computer : every computer has one. A router happens to
manage many more routes than that but it is essentially using the same routing syntax.

So how does one read that?


In order to understand this output, you have to read from top to bottom :

 By default, network calls will be forwarded to the local default gateway which is 10.0.2.1
 UNLESS your call is for the 10.0.2.0/24 network. In this case, it will simply be sent on your
local network via your default physical link (physically a CAT network cable)
 UNLESS your call is for the 169.254.0.0/16 network. In this case, it will also be sent on your
local network using your default physical link.

Note : did you know? The 169.254.0.0/16 address is


called APIPA (for Automatic IP Address Addressing). It
is the default IP used by a system that failed to reach a
DHCP server on the network.
In our case, in order to call the 10.0.3.2/24 IP address, the call will be forwarded to
our 10.0.2.1 router.

However, is our router able to forward calls addressed to the 10.0.3.0/24 network?

A simple “ip r” command on the router can give us a hint.

As you can see, the router is only linked to the 10.0.2.0/24 network which is obviously an issue.

In order to add a route on our Linux router, we use the “ip route add” command.

$ sudo ip route add 10.0.3.0/24 via 10.0.3.1

Now, if you were to ping your second computer on the first computer, you would be able to reach it.
Awesome, you have successfully added a route from one Linux computer to another!

Adding permanent route configuration on Ubuntu


On Ubuntu, there are three ways of adding a permanent route to your Linux machine :

 You can add it to your Network Manager configuration file;


 You can edit your Netplan YAML configuration file;
 You can add your route to the “/etc/network/interfaces” file if you are using an old Ubuntu
distribution.
Using Network Manager

To add a permanent route to the Network Manager, you have to navigate to the connection
file located at “/etc/NetworkManager/system-connections”.

Edit your “Wired connection” file and add a “route1” property in the IPv4 part of the network
configuration.

The route has to be defined as : the network IP address followed by the CIDR, next the default
gateway and finally the next-hop.

In order for the changes to be applied, you can restart your network connection, and execute the
“route -n” command in order to see your route.
$ sudo nmcli connection reload

Awesome, you have added a permanent route to your Linux server!

Using Netplan

Netplan is an Ubuntu exclusive but it can be quite useful if you want to configure your network using
a simple YAML file.

To add a permanent route using Netplan, add the following section to your “/etc/netplan”
configuration file.

$ sudo vi /etc/netplan/<configuration_file>.yaml

For the changes to be applied, you will have to execute the “netplan” command with the “apply”
argument.

$ sudo netplan apply


Congratulations, you have configured your network using Netplan. If you want to read more
about Netplan and its objectives, you can have a look at the dedicated documentation.

Using /etc/network/interfaces

To add a permanent route to a distribution using ifup and ifdown, edit the
“/etc/network/interfaces” file and add the following section.

$ sudo vi /etc/network/interfaces auto eth0

iface eth0 inet static address 10.0.2.2 netmask 255.255.255.0 up route add -net
10.0.3.0 netmask 255.255.0.0 gw 10.0.2.1

Adding permanent route configuration on RHEL


By adding the route in the previous section, there is a chance that your distribution created a file for
the route to be persisted.

However, if it is not the case, you need to add it in order to keep your route when restarting your
server.

On RHEL and CentOS distributions, you need to create a file named “route-<device>” in the
“/etc/sysconfig/network-scripts” folder.

$ sudo vi /etc/sysconfig/network-scripts/route-enp0s3

Add route on Linux using nmcli


Another way of adding a route on Linux is to use the “nmcli” utility and add an IPV4 route
using the “modify” command.
$ sudo nmcli connection modify <interface_name> +ipv4.routes "<network_ip>
<gateway_ip>"

Note : need a complete article about the Network


Manager? We have a complete article about configuring
your network using Network Manager.
For example, using the infrastructure of the previous section, in order to add a route, we would
execute the following command.

$ sudo nmcli connection modify enp0s3 +ipv4.routes "10.0.3.0/24 10.0.3.1"

As changes are not made live, you will need to reload your network connections from disk using the
“nmcli reload” command.

$ sudo nmcli connection reload

Awesome! Now there is a route between your first and second network.

As a consequence, you will be able to ping your second computer from the first computer.
Adding a route using the network graphical interface
If you are not into executing commands in the terminal, luckily for you, there is a way to add a route
on Linux using a graphical interface.

Whether you are on Ubuntu, Debian or RHEL makes no difference as they all share the same
network panel on GNOME.

At the top right corner of your screen, look for a small network icon and click on it.

Click on “Wired Connected” and look for the “Wired Settings” panel under it.

When the panel opens, look for the “Wired” section and click on the small gear wheel right next to it.
In the “Wired” panel, you will be presented with many different parameters : your current IPv4
address, your current MAC address, an optional IPv6 address and your link speed.

In the “IPv4” tab, you will be presented with your current IP configured (most likely two for your
computer to act as a Linux router).

Right under it, you will see the “Routes” section. In there, you can specify the input of the previous
sections.
When you are done, click on the “Apply” blue button at the top right corner of the window.

In order for the changes to be applied, you will need to restart your network. You can achieve that by
clicking on the “on/off” toggle in the “Wired” window of the network parameters.

Done!

You have successfully added a route on Linux using the graphical interface, your computers
should now be able to talk to each other.
Troubleshooting Internet issues on Linux
In some cases, you may want to add a route on your Linux because you want to be able to reach
websites outside of your local network, say 8.8.8.8 for example.

As an example, let’s say that you have a local router linked to “Internet” that resides at
192.168.178.1/24.

Inspecting your current routes is an easy way for you to guess why you are not able to reach
Internet websites.

The thought process is quite simple :

 Is the IP that I am trying to reach a part of my subnet or not?


 If yes, I should be able to reach it without any routes, everything will be handled by the
ARP protocol and Ethernet.
 If not, I need to have a route from my computer to a router that is able to forward requests to
Internet.
However, remember that routes are two-lane highways : you need to be able to reach an
external IP, but the external IP needs to be able to reach back to you.

As a consequence, routes need to be correctly defined on your local network architecture. As a


diagram is more useful that a thousand words, here is a way to understand it.
Whenever you are troubleshooting Internet issues, you have to think with routes : do I have a route
from my computer to the computer that I am trying to reach?

Are the computers or routers between me and the target configured to handle my calls?

Reaching a part of the network is great, but is this part of the network able to answer me back?

In our diagram detailed above, our router may receive an answer from Google, but it has to know
what to do with the request. In your local home network, you don’t have to worry about it as most of
the requests are forwarded using the NAT protocol (short for Network Address Translation
Protocol).
Any network we are trying to reach is accessed via default gateway only if it is not
implicitly overwritten by another static route definition. Let’s have a look at a current
routing table on our Redhat 7 Linux box:

root@rhel7 ~]# ip route show

default via 10.1.1.1 dev enp0s3 proto static metric 1024

10.0.0.0/8 dev enp0s3 proto kernel scope link src 10.1.1.110

From the above we can see that any packets to reach a destination network
ID 10.0.0.0/8 should travel via enp0s3 interface with 10.1.1.110 and any other
destination network not implicitly defined should use a default gateway 10.1.1.1.

To add a new static route means to define yet another destination network as well as
specify via which IP address and interface the packet should travel through in order to
reach its destination. For example, let’s add a static route to destination
network 15.15.0.0/24 via 10.1.1.110 ip address and enp0s3 interface. To do this
create a new file route-enp0s3 in a /etc/sysconfig/network-
scripts/ directory. To define an above mentioned persistent static route add a
following line into your enp0s3 file:

15.15.0.0/24 via 10.1.1.110 dev enp0s3

Once done restart your network:

root@rhel7 ~]# systemctl restart network

Next, check whether your new static route was correctly defined:

[root@rhel7 ~]# ip route show

<="" img="" style="box-sizing: inherit; height: auto; max-width: 100%;">


The Default Route
Linux, like any other OS has a routing table that determines what is the next
hop for every packet.

Print the routing table contents

There are numerous commands that show the routing table but today we will
use the ip command as this command will be replacing the route command in
future releases.
# ip route show

10.1.6.0/26 dev eth0 proto kernel scope link src 10.1.6.21

10.1.7.0/24 dev eth1 proto kernel scope link src 10.1.7.41

default via 10.1.6.1 dev eth0

As you can see in the example routing table there are numerous routes
however 1 route shows as the default route. This routing table tells the system
that if the IP that is being communicated to does not fall into any of the other
routes than send the packets to the default route defined as 10.1.6.1. The
default route basically acts as a catchall for any packet that isn't being told
what to do in the above routes.

Our Example System


In today's article I will be referencing an example network configuration in
order to show how static routes are added, why to add them and some basic
troubleshooting.

Example Interface Configuration

eth0:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=static

IPADDR=10.1.6.21

NETMASK=255.255.255.192

ONBOOT=yes

eth1:
# cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

BOOTPROTO=static

IPADDR=10.1.7.41

NETMASK=255.255.255.0

ONBOOT=yes

Example Default Route Configuration

# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=testing.example.com

GATEWAY=10.1.6.1

The GATEWAY configuration in /etc/sysconfig/network tells the system


that 10.1.6.1 is the default route. This configuration could also be added
to /etc/sysconfig/network-scripts/ifcfg-eth0 file; However if multiple ifcfg-
<interface> files have a GATEWAY this may provide unexpected results as there
can only be one default route.
Example Why we need a static route

For our example network configuration we have two interfaces; eth0


(10.1.6.21) for the internet, and eth1 (10.1.7.41) for the internal network. If we
were to hook up to a backup server such as 10.1.5.202 we would want the
connectivity to go through eth1 the internal network, rather than eth0 which is
the internet network.

Since 10.1.5.202 is not in the same subnet at eth1 (10.1.7.0/24) the routing


table does not automatically route the packet through eth1 and would then
hit the “catchall” default route out eth0. To force all of our packets destined
for 10.1.5.202 out eth1 we will need to set up a static route.

Adding a Static Route


Adding the route to the current routing table

Adding the static route is a fairly simple task however before we start we must
first know the gateway for the internal network; for our example the gateway
is 10.1.7.1.

Adding a single IP

# ip route add 10.1.5.202/32 via 10.1.7.1 dev eth1

The above command adds a route that tells the system to send all packets
for 10.1.5.202 and only that IP to 10.1.7.1 from device eth1.

Adding a subnet of IP's

In order to add a whole subnet than you will need to change the CIDR on the
end of the IP. In this case I want to add anything in the 10.1.5.0 - 10.1.5.255 IP
range. To do that I can specify the netmask of 255.255.255.0 in CIDR
format(/24) at the end of the IP itself.

If a CIDR (or netmask) is not specified the route will default to a /32 (single ip)
route.
# ip route add 10.1.5.0/24 via 10.1.7.1 dev eth1

The difference between these two routes is that the second will route anything
between 10.1.5.0 and 10.1.5.255 out** eth1** with 1 route command. This is
useful if you need to communicate with multiple servers in a network and
don't want to manage lengthy routing tables.

Adding the route even after a network restart

While the commands above added the static route they are only in the routing
table until either the server or network service is restarted. In order to add the
route permanently, the route can be added to the route-<interface> file.
# vi /etc/sysconfig/network-scripts/route-eth1

Append:
10.1.5.0/24 via 10.1.7.1 dev eth1

If the above configuration file does not already exist than simply create it and
put only the route itself in the file (# comments are ok). When the interface is
restarted next the system will add any valid route in the route-eth1 file to the
routing table.
I highly suggest that when possible anytime you add a route to the route-
<interface> files that the interface itself is restarted to validate whether the
route is actually in place correctly or not. I have been on many late night calls
where a static route was not added correctly to the configuration files and was
removed on the next reboot, which is also long after everyone has forgotten
that a static route was required.

Troubleshooting a Static Route


Check if the route is in the routing table

Before performing any deep down troubleshooting steps the easiest and first
step should be to check if the routing table actually has the route you expect
it to have.
# ip route show

10.1.5.0/24 via 10.1.7.1 dev eth1

10.1.6.0/26 dev eth0 proto kernel scope link src 10.1.6.21

10.1.7.0/24 dev eth1 proto kernel scope link src 10.1.7.41

default via 10.1.6.1 dev eth0

Use tcpdump to see tcp/ip communication

The easiest way that I have found to find out whether a static route is working
correctly or not is to use tcpdump to look at the network communication. In our
example above we were attempting to communicate to 10.1.5.202 through
device eth1.
# tcpdump -qnnvvv -i eth1 host 10.1.5.202

tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96


bytes

16:50:35.880941 IP (tos 0x10, ttl 64, id 59563, offset 0, flags [DF],


proto: TCP (6), length: 60) 10.1.7.41.41403 > 10.1.5.202.22: tcp 0

16:50:35.881266 IP (tos 0x0, ttl 59, id 0, offset 0, flags [DF], proto:


TCP (6), length: 60) 10.1.5.202.22 > 10.1.7.41.41403: tcp 0

The above tcpdump command will only listen on eth1 and output only results


that to or from 10.1.5.202.
TCP connections require communication from both the source and the
destination, to validate a static route you can simply initiate a tcp connection
(telnet to port 22 in this case) from the server with the static route to the
destination server. In the output above you can see communication
from 10.1.7.41 to 10.1.5.202 from the eth1 interface, this line alone shows that
the static route is working correctly.

If the static route was incorrect or missing the tcpdump output would look
similar to the following.
# tcpdump -qnnvvv -i eth1 host 10.1.5.202

tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96


bytes
16:50:35.881266 IP (tos 0x0, ttl 59, id 0, offset 0, flags [DF], proto:
TCP (6), length: 60) 10.1.5.202.22500 > 10.1.7.41.22: tcp 0

In the above, only the target server is communicating over eth1.

Adding Route and Deleting Route in Windows:

1 Show the current routing table


1.1 Bring up the start menu by using “Win” key or click on Windows start menu icon

1.2 Type “cmd”

1.3 Right click on “Command Prompt”, Run as Administrator

1.4 Click on “Yes” if asked by UAC

1.5 Use the following command to show the current routing table

route print

Example output

C:\WINDOWS\system32>route print

===========================================================================

Interface List

11...aa 56 9f fe 22 07 ......Red Hat VirtIO Ethernet Adapter


1...........................Software Loopback Interface 1

===========================================================================

IPv4 Route Table

===========================================================================

Active Routes:

Network Destination Netmask Gateway Interface Metric

0.0.0.0 0.0.0.0 10.0.2.1 10.0.2.21 5

10.0.2.0 255.255.255.0 On-link 10.0.2.21 261

10.0.2.21 255.255.255.255 On-link 10.0.2.21 261

10.0.2.255 255.255.255.255 On-link 10.0.2.21 261

127.0.0.0 255.0.0.0 On-link 127.0.0.1 331

127.0.0.1 255.255.255.255 On-link 127.0.0.1 331


127.255.255.255 255.255.255.255 On-link 127.0.0.1 331

224.0.0.0 240.0.0.0 On-link 127.0.0.1 331

224.0.0.0 240.0.0.0 On-link 10.0.2.21 261

255.255.255.255 255.255.255.255 On-link 127.0.0.1 331

255.255.255.255 255.255.255.255 On-link 10.0.2.21 261

===========================================================================

Persistent Routes:

None

IPv6 Route Table

===========================================================================

Active Routes:

If Metric Network Destination Gateway


1 331 ::1/128 On-link

1 331 ff00::/8 On-link

===========================================================================

Persistent Routes:

None

C:\WINDOWS\system32>

2 Add a temporary static route


2.1 Bring up the start menu by using “Win” key or click on Windows start menu icon

2.2 Type “cmd”

2.3 Right click on “Command Prompt”, Run as Administrator

2.4 Click on “Yes” if asked by UAC

2.5 Add the temporary static route

route ADD 10.0.3.0 MASK 255.255.255.0 10.0.0.1

This command means, we are adding a static route, that specifying all traffic bound for
10.0.3.0 subnet will go through gateway 10.0.0.1 with automatic metric cost

Use route print to double it’s added

C:\WINDOWS\system32> route print


===========================================================================

Interface List

11...aa 56 9f fe 22 07 ......Red Hat VirtIO Ethernet Adapter

1...........................Software Loopback Interface 1

===========================================================================

IPv4 Route Table

===========================================================================

Active Routes:

Network Destination Netmask Gateway Interface Metric

0.0.0.0 0.0.0.0 10.0.2.1 10.0.2.21 5

10.0.2.0 255.255.255.0 On-link 10.0.2.21 261

10.0.2.21 255.255.255.255 On-link 10.0.2.21 261


10.0.2.255 255.255.255.255 On-link 10.0.2.21 261

10.0.3.0 255.255.255.0 10.0.0.1 10.0.2.21 6

127.0.0.0 255.0.0.0 On-link 127.0.0.1 331

127.0.0.1 255.255.255.255 On-link 127.0.0.1 331

127.255.255.255 255.255.255.255 On-link 127.0.0.1 331

224.0.0.0 240.0.0.0 On-link 127.0.0.1 331

224.0.0.0 240.0.0.0 On-link 10.0.2.21 261

255.255.255.255 255.255.255.255 On-link 127.0.0.1 331

255.255.255.255 255.255.255.255 On-link 10.0.2.21 261

===========================================================================

Persistent Routes:

None
IPv6 Route Table

===========================================================================

Active Routes:

If Metric Network Destination Gateway

1 331 ::1/128 On-link

1 331 ff00::/8 On-link

===========================================================================

Persistent Routes:

None

C:\WINDOWS\system32>

Note: Temporary static route will disappear after system reboot

3 Add a persistent static route


3.1 Bring up the start menu by using “Win” key or click on Windows start menu icon

3.2 Type “cmd”


3.3 Right click on “Command Prompt”, Run as Administrator

3.4 Click on “Yes” if asked by UAC

3.5 Add the persistent static route

route -p ADD 10.0.3.0 MASK 255.255.255.0 10.0.0.1

To double confirm, we can use the route print command again, this time, we should
see the new persistent static route under “Persistent Routes:” section

4 Remove / Delete static route


4.1 Bring up the start menu by using “Win” key or click on Windows start menu icon

4.2 Type “cmd”

4.3 Right click on “Command Prompt”, Run as Administrator

4.4 Click on “Yes” if asked by UAC

4.5 Use the following command to delete a static route

Syntax: route DELETE destination_network

route DELETE 10.0.3.0

You might also like