Static route configuration for Network System Management

Source: Internet
Author: User

The company uses a wide range of servers, FreeBSD8.1-64bit, windows2003_R2-64bit and cetnos5.5-64bit, and many planned network segments, there are 192.168.4.0, 192.168.10.0, 192.168.20.0, 192.168.21.0, and 10.1.0.0, 192.168.4.0 belongs to the office network, 192.168.20.0 and 192.168.21.0 belong to the development environment, and 192.168.10.0 and 10.1.0.0 belong to the online environment (providing external services ), but in many cases, the routers and firewalls are strictly controlled (The rule rules cannot be changed randomly due to permission reasons). In this case, you need to manually add routes to the server or client, I will give a brief summary here, hoping to help you in your work. Note:

The server systems here are described in 64-bit windows2003, FreeBSD8.1, and Centos5.5.

1. Here we will talk about the simplest static route configuration in windows2003, windowsxp, and windows7, which is relatively simple:

route add 192.168.4.0 mask 255.255.255.0 192.168.4.2

Route add is a specific syntax (non-route add-net) for adding CIDR blocks in windows, 192.168.4.0 is the CIDR block you need to route, and mask is followed by the subnet mask of This CIDR block, 192.168.4.2 is the next hop address. Note in detail the difference between 192.168.4.2 and centos and FreeBSD. Otherwise, it will be confusing.

What if I want to add a route permanently?

The ROUTE command can be manually configured for Static Routing in XP, 2 K/2003, WIN7, and other operating systems. However, after restart, the routing will be lost and will be added again, so how can we keep the route waiting and it will still exist after restart? In fact, it is very easy to add the-P switch after adding the routing command. For example

route -p add 10.10.0.0 mask 255.255.0.0 192.168.4.222

-P parameter description

When used together with the Add command, specify that the route is added to the Registry and initialize the IP route table when starting the TCP/IP protocol. By default, the added route entries are not saved when the TCP/IP protocol is started. When used together with the Print command, the permanent route list is displayed. All other commands ignore this parameter. The location where permanent routes are stored in the registry is. Pay attention to the red line of the last figure. It can also verify that the new commands will add static routes permanently. (Note the red line of the bottom picture)

HKEY_LOCAL_MACHSYSTEMCurrentControlSetServicesTcpipParametersPersistentRoutes

 

But in many cases, we only need to add routes temporarily? If this process is repeated, you can write a batch. Double-click it when necessary,

For example, edit c: windowsoute. bat

@echo off
route add 192.168.4.0 mask 255.255.255.0 192.168.21.3
route add 192.168.10.0 mask 255.255.255.0 192.168.21.3
route add 192.168.21.0 mask 255.255.255.0 192.168.21.3
route add 10.1.0.0 mask 255.255.0.0 192.168.21.3

Adding a permanent route depends on your needs. Sometimes, if you only need openVPN, you do not need to use route add-p to add a route table. You only need to use bat to process it; by the way, the command for viewing the local route table in windows is route print. Be sure not to confuse it with Linux/FreeBSD.

Ii. In other words, the permanent addition of the Static Routing Method under centos 5 is more common. The method of manually adding a route is as follows:

route add -net 172.16.6.0 netmask 255.255.255.0 gw 172.16.2.25

Route add-net is the method for adding a static route network under centos, netmask is the subnet mask of the network segment, gw represents the next hop address, in fact, 172.16.6.0 routes are routed out through 172.16.2.25. This is only temporary effect. If the server fails to be restarted, how can it be permanently effective? In fact, it may be written into the file as follows:

vim /etc/sysconifg/network-scripts/route-eth0
127.16.6.0/24 via 172.16.2.25

You don't need to worry about restarting the server. It will always take effect.

There are a lot of ways to view route tables in Centos, either netstat-rn or route-n. There are also a lot of related information in linux, which I will not focus on here

3. FreeBSD has fewer servers than the above two types. Therefore, it is not common to add routes under FreeBSD, and it is sometimes confusing. Note that it is different from centos and other linux systems, if you want to add a route entry with the CIDR Block 172.16.6.0 and the next hop address 172.16.2.25, that is

route add -net 172.16.0.0/24 172.16.2.25

Note the difference between centos5 and windows2003. The parameter 172.16.0.0/24 is not followed by the subnet mask. If you need to connect the mask parameter, shell will generate an error message.

bad netmask

If you want to add a permanent route, it is actually very simple, that is, add it at the end of/etc/rc. conf. The following command line can add four permanent static routes for your FreeBSD machine.

static_routes="net1 net2 net3 net4"
route_net1="-net 192.168.4.0/24 192.168.21.3"
route_net2="-net 192.168.10.0/24 192.168.21.3"
route_net3="-net 192.168.20.0/24 192.168.21.3"
route_net4="-net 10.1.0.0/16 192.168.21.3"

By the way, the command for viewing routes under FreeBSD is netstat-rn, as follows:

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.