To set up a permanent static route on a Windows virtual machine, you need to use the command line tool. The specific steps are as follows:
-
Open command prompt :
- In a Windows virtual machine, press the Win + R key combination, type "cmd" and press Enter to open the command prompt.
-
View the current routing table :
- In the command prompt, enter the following command to view the current routing table:
route print
This will display the current system's routing table information, including destination networks, gateways, interfaces, etc.
-
Add a permanent static route :
- Use the following command to add a permanent static route. Please replace the following parameters according to your network configuration:
- The -p flag means to add the route as a permanent route to ensure persistence across system reboots.
route -p add target network mask subnet mask gateway
- Target Network: The IP address or hostname of the target network to be accessed.
- Subnet Mask: The subnet mask of the target network.
- Gateway: The gateway IP address that sends packets to the destination network.
For example, if you want to send all traffic to the destination network 10.0.0.0/24 and the gateway is 192.168.1.1, the command is as follows:
route -p add 10.0.0.0 mask 255.255.255.0 192.168.1.1
- Use the following command to add a permanent static route. Please replace the following parameters according to your network configuration:
-
Verify routing :
- Run the route print command again to ensure that the new permanent static route has been added to the routing table correctly.
-
Deletion of permanent static routes (optional):
- If you need to delete a previously set permanent static route, you can use the following command:
route delete target network
For example, delete the route with the destination network 10.0.0.0/24:
route delete 10.0.0.0
Note: After deleting a route, it will no longer exist after restarting the system.