Script to add a permanent route to a Windows server

Source: Internet
Author: User

The function is not strong, but because occasionally also will use, here I still paste out to see, to everybody's appraisal appraisal. Work, and seldom do some fun things anymore. This stuff is written only because of the need for work.

The thing is this, if the purchase of dual-line or three-wire bandwidth, such products are non-BGP products, can automatically choose from the three major ISP operators the best route to return data, Single-line here will not talk about Kazakhstan. So how to choose the best line to return the data to the user with two or three lines? Here we can control the server we placed in the engine room, on the Windows Server, you can add a permanent route to achieve, but the implementation is relatively cumbersome, not like the Linux server so simple and quick. All right, so here's the thing about adding a permanent route to a Windows server.

One question is: why is there only one physical network card (imagine a physical link)? The reason is that through the IP header encapsulated network address, from the physical line out, and then handed over to the operator's router processing. Routers use the IP header to select the best route to return data to the user.

Okay, look at the script:

The code is as follows Copy Code
@echo off
echo Please enter your mobile gateway:
set/p g=:
Echo.
echo determines that the input gateway is correct and returns to the
Echo.
Pause
Route-p Add 192.168.0.0 mask 255.255.0.0%g%
...
...
...
Route-p Add 192.168.1.0 mask 255.255.255.0%g%
Ping-n 3%g%
Echo.
Echo.
If%errorlevel% equ 0 Echo Server permanent route is in effect
If%errorlevel% equ 1 Echo Gateway not reachable
Echo.
Pause

If the above gateway for 192.168.2.1 is your operator to the Unicom gateway. The assumption is that users from Unicom access. Then the user packet IP header has an IP ID, which is recognized as the IP and is accessed by a user from the Unicom ISP. The server header that returns the packet also encapsulates a similar IP header from the physical NIC to the router. The router is identified and returned in accordance with the Unicom line.

Parameters for Windows Add route:

The code is as follows Copy Code

C:\windows\system32>route

Operates the network routing table.

The code is as follows Copy Code

ROUTE [F] [P] [ -4|-6] command [destination]
[MASK netmask] [Gateway] [METRIC METRIC] [IF Interface]

-F Clears the routing table for all gateway entries. If you are with a
command, before you run the command,
The routing table should be cleared.

-p when used in conjunction with the ADD command, sets the route to
remain unchanged during system boot. By default, when you restart the system,
Routes are not saved. Ignore all other commands,
This will always affect the corresponding permanent route.

-4 mandatory use of IPV4.

-6 mandatory use of IPV6.

Command one of these:
Print printing route
Add route
Delete Remove route
Change modify an existing route
destination Specifies the host.
MASK specifies that the next parameter is a "netmask" value.
NETMASK Specifies the subnet mask value for this route item.
If not specified, its default setting is 255.255.255.255.
GATEWAY specifies gateways.
interface specifies the interface number for the route.
METRIC Specifies the metric, such as the cost of the target.

All symbol names for the target can be in the network database
File NETWORKS to find it in. Symbol names for gateways can be in the host name
The database file is located in HOSTS.

If the command is PRINT or DELETE. A target or gateway can be a wildcard character,
(wildcard characters are specified as asterisk "*"), otherwise the gateway parameter may be ignored.

If Dest contains a * or?, it is treated as Shell mode and only
Print a matching destination route. "*" matches any string,
and "?" matches any one character. Examples: 157.*.1, 157.*, 127.*, *224*.

Pattern matching is allowed only in the PRINT command.
Diagnostic Information Note:
An invalid MASK generates an error, that is, when (DEST & MASK)!= DEST.
Example: > Route ADD 157.0.0.0 MASK 155.0.0.0 157.55.80.1 IF 1
Route addition failed: The mask parameter specified is invalid.
(Destination & Mask)!= destination.

Example:

The code is as follows Copy Code

> Route PRINT
> Route PRINT-4
> Route PRINT-6
> Route PRINT 157* .... Print only those items that match the 157*

> Route ADD 157.0.0.0 MASK 255.0.0.0 157.55.80.1 METRIC 3 IF 2
destination^ ^mask ^gateway metric^ ^
interface^

If not given, it will try to find the best of the given gateway
Interface.

The code is as follows Copy Code

> Route ADD 3ffe::/32 3ffe::1

> Route change 157.0.0.0 MASK 255.0.0.0 157.55.80.5 METRIC 2 IF 2

Change is used only to modify gateways and/or hops.

The code is as follows Copy Code

> Route DELETE 157.0.0.0
> Route DELETE 3FFE::/32

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.