Help Center> Virtual Private Cloud> FAQ> Routing> How Do I Configure Policy-Based Routing for ECSs with Multiple NICs?

How Do I Configure Policy-Based Routing for ECSs with Multiple NICs?

If an ECS has multiple NICs, perform the following operations to configure policy-based routing for the ECS to enable the network communication of secondary NICs.

For a Linux ECS:

  1. Run the following command and add two route tables (net1 and net2) and their priorities to the /etc/iproute2/rt_tables file. The priorities of net1 and net2 are 252 and 251, respectively. A smaller value indicates a higher priority.
    vi /etc/iproute2/rt_tables
    # added for dual net
    252     net1
    251     net2
  2. Run the following command and add the NIC routing information to the /etc/rc.local file:

    vi /etc/rc.local

    The IP addresses of NICs eth0 and eth1 are 192.168.1.23 and 192.168.2.4, respectively. The subnet mask is 24 bits. The gateway addresses of NICs eth0 and eth1 are 192.168.1.1 and 192.168.2.1, respectively. The information to be added is as follows:

    # Request IP address for eth1
    dhclient eth1
    # Add routes
    ip route flush table net1
    ip route add default via 192.168.1.1 dev eth0 src 192.168.1.23 table net1
    ip route add 192.168.1.0/24 dev eth0 src 192.168.1.23 table net1
    ip rule add from 192.168.1.23 table net1 
     
    ip route flush table net2
    ip route add default via 192.168.2.1 dev eth1 src 192.168.2.4 table net2
    ip route add 192.168.2.0/24 dev eth1 src 192.168.2.4 table net2
    ip rule add from 192.168.2.4 table net2
  3. Run the following command to add the execute permission for the rc.local file:

    chmod +x /etc/rc.local

  4. Run the reboot command to restart the ECS.

For a Windows ECS:

  1. Choose Control Panel > Network and Internet > Network Connections. Right-click Local Area Connection 2 and then click Properties.

    Right-click to add NICs based on the site requirements.

  2. On the Network tab page, select Internet Protocol Version 4 (TCP/IPv4).
  3. Click Properties.
  4. On the General tab page, click Advanced.
  5. On the IP Settings tab, click Add in the Default gateways area.
    Figure 1 Advanced TCP/IP settings
  6. Enter the gateway address of the secondary NIC and click Add.
    Figure 2 TCP/IP Gateway Address
  7. Click OK.

Related Operations

If you want to access the Internet using an extension NIC, see How Do I Access the Internet Using an EIP Bound to an Extension NIC?