A routing table is a part of a computer’s operating system. It contains the details of the best way to reach different networks, such as your home or office network. The table helps your computer send data to different networks and devices. Windows uses a routing table to determine the best way to send data to a specific destination. A routing table is used in every operating system. It contains the details of the best way to reach different networks, such as your home or office network. The table helps your computer send data to different networks and devices. Windows uses a routing table to determine the best way to send data to a specific destination. You can add a static route to the routing table to save time if your home or business is frequently visited. You can also add alternate routes to your home or business if you have trouble reaching the original location via the routing table.
Маршрутизация в Windows
Маршрутизация – это процесс передачи IP-трафика адресатам в сети, то есть процесс передачи пакетов от хоста-источника к хосту-адресату через промежуточные маршрутизаторы. Изучая эту статью предполагается что вы изучили материал основы компьютерных сетей.
Изучим как работает маршрутизация в Windows, что бы понять как она работает, а не просто прочитать и забыть, вам необходимо несколько виртуальных машин, а именно:
Учтите, что при настройке виртуальных машин, в настройках сети нужно указать «Внутренняя сеть» и задать одинаковое имя сети для всех машин.
Если вы не поленитесь и установите три виртуальные машины, а так же изучите этот материал до конца, то у вас будет практическое понимание работы сети в операционных системах семейства Windows.
Для простоты передачи данных хост-источник и маршрутизатор принимают решения о передаче пакетов на основе своих таблиц IP-маршрутизации. Записи таблицы создаются при помощи:
Пример маршрутизации в Windows
Допустим, у нас есть три узла:
Each IP packet contains information about its origin and destination.
A routing table contains the information necessary to forward an IP packet along the best path toward its destination.
In this note i will show how to display the routing table in Windows using the route print command.
To display the routing table in Windows, use the route command with the print option.
Display all routing tables:
Print IPv4 routing table:
Print IPv6 routing table:
Show only the network destinations that match 192*:
Example of the routing table in Windows:
IPv4 Route Table
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.31 50
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
192.168.1.0 255.255.255.0 On-link 192.168.1.31 306
192.168.1.31 255.255.255.255 On-link 192.168.1.31 306
On-link in the “Gateway” column means that the destination network is directly attached to the interface i.e. the NIC is in direct contact with the destination
network – on the same subnet.
The traffic that matches such route entry will trigger an ARP request on the interface to resolve the destination IP address directly i.e. find out a MAC-address of the target device (without contacting the gateway).
Sometimes you need to create static route entries to make communication with different networks that are connected via a different gateway. A gateway is simply a network router that routes the network traffic between different networks. When you have more than one gateway (router) on your network, then you may need to implement static route technique on Windows 10/Windows 11 or Windows servers/any Operating system.
A static route will tell the Operating System to send network packets to the appropriate router instead of sending them to the default router. This simple guide shows how to add, delete and modify a static route to the routing table on Windows 11/10 and Microsoft Server Operating Systems.
Why Add Static Route?
It mostly depends on the network setup. Usually, you can add these static routes on your default router (if it can support) or core switch. When you have this kind of proper network setup, you do not need to add a static route to each computer separately on the network. But in a few exceptional cases, you may need to implement static routes on individual computers. Here are a few examples.
Описание команды ROUTE.
1.1. Command line format:
Help on command line parameters can be obtained using the built-in help ( route /?).
All symbolic node names are searched in the NETWORKS network database file. The symbolic gateway names are looked up in the HOSTS hostname database file.
For PRINT and DELETE commands, you can specify the host and gateway using wildcards, or omit the “gateway” parameter.
If the destination node contains the wildcards * or ?, it is used as a wildcard and only the routes that match it are printed. The character ‘*’ matches any string, and ‘?’ matches one character.
Examples: 157.*.1, 157.*, 127.*, *224*.
Only the PRINT command supports pattern matching.
Invalid MASK causes an error if (NODE & MASK) != NODE.
For example, adding a route will fail because an invalid mask parameter was specified. ( Node & Mask) != Node.
C: route ADD 18.104.22.168 MASK 22.214.171.124 126.96.36.199 IF 1 –
2.1. display route table:
C: route PRINT
2.2. Display route table for IPv4 only:
C: route PRINT -4
2.3. Display route table for IPv6 only:
C: route PRINT -6
2.4. Display route table only for hosts starting with 157:
C: route PRINT 157*
If the network interface (IF) is not specified, then an attempt is made to find the best interface for the specified gateway.
2.5. Add new route for host with IPv6:
C: route ADD 3ffe::/32 3ffe::1
2.6. Change an existing route for an IPv4 host:
C: route CHANGE 188.8.131.52 MASK 255.0.0.0 184.108.40.206 METRIC 2 IF 2
The CHANGE parameter is only used to change the gateway or metric.
2.7. Delete route for IPv4:
C: route DELETE 220.127.116.11
2.8. Delete route for IPV6:
C: route DELETE 3ffe::/32
Examples of using the ROUTE command.
3.1. Display current route table:
The following information will be displayed:
3.2. Display route table only for addresses starting with 192:
C: route print 192.*
3.3. Set default gateway (primary gateway) to 192.168.1.1:
C: route add 0.0.0.0 mask 0.0.0.0 192.168.1.1
3.4. Add route for subnet 10.0.0.0/255.0.0.0 and store it in registry:
C: route -p add 10.0.0.0 mask 255.0.0.0 10.0.0.1
This is a permanent static route. If the route is added without using the -p option, then it is saved only until the system is rebooted (until the network system software is restarted). If, however, this parameter was slipped when adding a route, then information about the route is written to the Windows registry (key HKLMSYSTEMCurrentControlSetServicesTcpipParametersPersistentRoutes ) and will be used constantly when network interfaces are activated.
3.5 Delete route for subnet 10.0.0.0/255.0.0.0:
C: route delete 10.0.0.0 mask 255.0.0.0
C: route add 10.10.10.10 192.168.1.158
3.7. Delete the route created by the previous command:
C: route delete 10.10.10.10
3.8. Change gateway address for existing route to network 10.0.0.0/255.0.0.0 to 10.10.10.1:
C: route change 10.0.0.0 mask 255.0.0.0 10.10.10.1
This command can only be used to change the gateway address and metric.
3.9. Clear route table:
C: route -f
After rebooting the system, or when restarting network connections, the route table will be restored based on the current network configuration of the computer. When executing the route -f command, all routes that satisfy the conditions are removed from the table:
When processing the route table, static routes take precedence over a route that uses a default gateway to reach the endpoint.
Adjustment via snap-in
Then highlight the line “RIP version 2 for IP”.
In the context menu of the “RIP” tab that appears, select “New Interface”. Highlight the line “Local Area Connection” and click OK.
A window will appear in front of you.
In the window that appears, you need to set the following settings:
Leave the rest of the default settings and click OK.
Next, you need to perform these steps for the second network interface.
Then follow the same steps for Sever2.
Check the network with ping command.
Congratulations! Routing in Windows is learned.
The second way to set up routing in Windows is the default routing.
For default routing, you need to set default routes on all network nodes.
To add such a route on an XP host, run the following command:
route add 0.0.0.0 mask 0.0.0.0 192.168.0.1 metric 2 if 0x10003
This command tells the XP host to use gateway 192.168.0.1 and interface index 0x10003 to reach any network that does not have a route in the routing table.
This is the so-called default route.
Check the operation using the ping command.
Route Add on Windows 11/10 and Windows Servers
Though there are major changes and interface upgrades in the latest Windows 11, the below steps remain the same.
Here is the command to add a static route to the routing table.
route ADD destination_network MASK subnet_mask gateway_ip metric_cost
route add 10.10.10.0 mask 255.255.255.0 10.10.29.1
It indicates that any packets to 10.10.10.0 (in class C – 255.255.255.0) network should be forwarded to the 10.10.29.1 router (gateway).
Obviously, the PC/server in which we run this command is in the 10.10.29.0/24 network because it should communicate to the gateway from the same network.
The issue with the above command is when you shut down or restart the computer, these route entries will be removed. To make it permanent and add to the Windows OS routing table, we should use the –p key with the add command. So, adding a persistent (or permanent) static route on Windows 10 command will be like this;
route add –p 10.10.10.0 mask 255.255.255.0 10.10.29.1
Route print command is another useful command to view the entries on the routing table and which routes are active at the moment. If you need to modify an entry that is already in the routing table, better to confirm the entries before changing. To do it, use the route print command.
Route Delete on Windows 11/10 & Windows 2022/2019/2016 Servers
The below command is to delete an existing persistent route from a computer. Even though we added a route entry with the network, network mask and gateway, but to delete, we need to mention the network only. So, it goes like this;
route delete 10.10.10.0
That will delete the 10.10.10.0 route entry from the computer. You do not need to restart the computer to take effect. Adding and deleting route entries take effect instantly.
Let’s say that after the recent network change, now the network 10.10.10.0 should be routed through the 10.10.29.200 gateway. Obviously, you have to modify the existing route for this network and change the gateway to 10.10.29.200.
So, how to modify the existing route entry? You can’t modify an existing entry.
The simple method is to delete it and add the new entry. So, in this case, you would perform the below commands.
Route delete 10.10.10.0
Route add -p 10.10.10.0 mask 255.255.255.0 10.10.29.200
Dynamic Routing, RIP Protocol
RIP (Routing Information Protocol) is one of the most widely used dynamic routing protocols.
Its essence lies in the fact that a router using RIP transmits the contents of its routing table to all networks connected to it and receives their tables from neighboring routers.
There are two versions of the RIP protocol. Version 1 does not support masks, so only network and distance information is propagated between networks. At the same time, for RIP to work correctly, the same mask must be set on all interfaces of all routers in the composite network.
The RIP protocol is fully supported only by the server operating system, while the client operating system (for example, Windows XP) only supports receiving routing information from other routers on the network, and cannot transmit routing information itself.
There are two ways to configure RIP:
Consider command-line configuration using the netsh utility.
Netsh is a command-line utility and scripting tool for the networking components of the Windows operating systems (Windows 2000 and later).
Enter commands in sequence:
You will see that among the available commands of this context is the add interface command, which allows you to configure RIP on a given interface. The simplest version of this command is add interface “Interface name”.
Set up RIP on Server1. But first you need to turn off the firewall.
Now in the “Routing and Remote Access” snap-in, in the context menu of the SERVER1 (local) item, select the item “Configure and enable LAN Routing
In the wizard window that appears, click Next.
In the next step, select Custom Configuration and click Next.
Then you need to select “LAN Routing” and complete the wizard.
Do the same on Server2.
The default routing table is automatically created in the host by the TCP/IP stack software.
The routing table contains the following fields for each entry: Network Destination, Netmask, Gateway Address, Interface, and Metric. Let’s analyze each field in more detail.
Interface. This field contains the address of the logical or physical interface used to forward packets that match this routing table entry.
Metric. Used to select a route if there are multiple entries that match the same destination address with the same mask, that is, if the same destination can be reached in different ways, through different routes. At the same time, the smaller the value of the metric, the shorter the route.
Initially (ie with default routing tables) the router (host) only knows how to reach the networks it is directly connected to. Paths to other networks can be “figured out” in the following ways:
Consider each of the ways in order.
Static routes are set manually. The advantage of static routes is that they do not require broadcast packets with routing information that take up network bandwidth.
The disadvantage of static routes is that when changing the network topology, the administrator must manually change all static routes, which is quite laborious if the network has a complex structure with a large number of nodes.
The second disadvantage is that if a link fails, the static route will stop working, even if other data links are available, since there is no static route set for them.
But back to our example. Our task, the name of the initial data, is to establish connections between the XP host and Server2, which is located on the Net3 network, that is, we need to ping to 192.168.2.1.
Let’s start executing ping commands on the XP host, gradually moving away from the host itself. Run ping commands on the Command Prompt for addresses 192.168.0.2, 192.168.0.1, 192.168.1.1.
We can see that pings to the native interface address of the XP host and to the nearest interface address of the neighbor router Server1 succeed.
However, when attempting to receive a response from the second interface of Server1, the message “The specified host is unreachable” or “Query timed out” is displayed.
This is because the default routing table of the XP host has entries for the route to host 192.168.0.2 and the route to network 192.168.0.0, which is the Server1 router interface at 192.168.0.1. But it doesn’t have any entries for the route to host 192.168.1.1, nor for the route to network 192.168.1.0.
Let’s add an entry about the route to the network 192.168.1.0 to the XP routing table. To do this, enter the route add command with the necessary parameters:
Command parameters have the following meanings:
The interface index can be determined from the Interface List section of the output of the route print command.
Execute the route print command.
We now see that the XP host has two interfaces: a logical loopback interface and a physical interface to the Intel(R) PRO/1000 network adapter. The physical interface index is 0x2.
Now, knowing the index of the physical interface, add the desired route on the host by executing the following command:
route add 192.168.1.0 mask 255.255.255.0 192.168.0.1 metric 2 if 0x2
This command tells the XP host to use gateway 192.168. site from the XP host.
Let’s ping 192.168.1.1 and make sure there is a connection.
We get the message “Request timed out”. In this case, this means that our XP host knows how to send data to the destination, but it does not receive a response.
This is because Server2 has no route information to host 192.168.0.1 and network 192.168.0.0 respectively, so it cannot send a response.
To do this, you need to execute the route add command with the appropriate parameters, but first you need to know the index of the interface with the address 192.168.1.2.
On Server2, run the route print command and see the index of the first physical interface. Next, use the route add command to add a route to the Net1 network on Server2, in the same way as we added the route to the XP host.
In my case, this is the command:
route add 192.168.0.0 mask 255.255.255.0 192.168.1.1 metric 2 if 0x10003
0x10003 is the physical interface index of server 2.
Physical interface index can be different, be sure to pay attention to it.
Instead of a response, you will receive the message “The specified node is not available.” We encountered this problem at the very beginning of the lab, the XP machine does not know the path to the 192.168.2.0 network.
Add a route entry to the 192.168.2.0 network in the routing table of the XP host. This can be done by typing the route add command at the command line of the XP host with the appropriate options:
route add 192.168.2.0 mask 255.255.255.0 192.168.0.1 metric 3 if 0x2
I will not describe in detail how to fully configure static routing between nodes, I think that the essence is clear. If you have any questions – ask them in the comments.
Adding Static Route to the Routing Table
The command to add an entry from cmd is as below
route add Destination_Address
MASK Subnet_Mask Gateway_IP Metric
Example: route add 192.168.39.0
MASK 255.255.255.0 18.104.22.168
Below is the output of the route print after adding the static route.
Interfaces and Route Table on Windows