Two-line server routing setting method under centos

  
        

In order to enable both Unicom and telecommunications users to quickly access the website, the company's servers are hosted in a two-line dual IP room. The server uses two-line dual ip to do some special configuration on the routing table. The solution provided by IDC is to fill in the static routing table. The method is to use the telecommunication gateway as the default route, and then manually fill in the routing rules of all Netcom IP address segments.

This method has a lot of drawbacks:

1. Adding too many rules is too much trouble. If you miss some network segments, users of these network segments will not be able to access the website.

2, dns intelligent resolution of the way and fill in the static routing network segment is different, users will not be able to access our website.

3, the distribution of network segment addresses is always changing, the routing table must be updated regularly.

Solution:

Use dynamic routing to set up dynamic routing based on the user's incoming path. If the user accesses through the telecom IP address, then use the telecom gateway to do routing and return. The content goes to the telecommunication gateway; if the user accesses through the Unicom IP address, then the Unicom gateway is used for routing, and the content is returned to the gateway of China Unicom.

After testing on the website backup server, the dynamic routing table method can solve the shortcomings of the static routing table.

The specific method is as follows:

If the server assigns the ip address as follows

Telecom Gateway: 59.83.100.1; Telecom ip: 59.83.100.10.

Unicom Gateway: 221.214.100.1; Unicom ip: 221.214.100.10.

1. Edit the rt_tables file and add the telecom connection path from the table

  1. # vi /etc/iproute2/rt_tables # (Increase the two routing tables of Telecom and China Unicom

    Adding a Telecommunication Linkage by

    1. 252 tel
    2. 251 cnc

      2, Edit rc The .local file sets the telecommunications and network access by the table contents.


      1. # vi /etc/rc.d/rc.local #(Setting the telecommunications and network access by table contents)

        Add

        1. ip route replace default via 59.83.100.1 dev eth0 #default route line
        2. ip route flush table tel #refresh tel routing table
        3. Ip route add default via 59.83.100.1 dev eth0 src 59.83.100.10 table tel #add loopback address
        4. ip rule add from 59.83.100.10 table tel #from 59.83.100.10, go tel route
          < Li> ip route flush table cnc # refresh cnc routing table
        5. ip route add default via 221.214.100.1 dev eth1 src 221.214.100.10 table cnc
        6. ip rule add from 221.214.100.10 table cnc # Take the cnc route from 221.214.100.10

          reboot the server test effect!

Copyright © Windows knowledge All Rights Reserved