
# 为配置了多网卡的边缘实例配置策略路由
#### 操作场景
当边缘实例配置了多张网卡时，需要在边缘实例内部配置策略路由来实现非主网卡的通信。
#### 操作步骤
**Linux系统**
1. 执行以下命令，在"/etc/iproute2/rt_tables"文件中为每张网卡增加路由表优先级和名称（数值越小优先级越高），如下net0，net1对应eth0，eth1，如果有多张网卡，依次添加。 
   **vi /etc/iproute2/rt_tables**
   ```
   # added for dual net 
   250     net0
   251     net1
   ```
   
   
2. 执行以下命令，在"rc.local"文件中为每张网卡增加路由信息。 
   **vi /etc/rc.local**
   对于每张网卡，查找以下信息：
   以eth0为例，IPv4地址：192.168.0.129、子网网段：192.168.0.0/24、网关地址：192.168.0.1，以及步骤1中添加的路由表：net0，如果有多张网卡，依次添加如下信息：
   ```
   # wait for nics up 
    sleep 5 
    # Add v4 routes for eth0 
    ip route flush table net0 
    ip route add default via 192.168.0.1 dev eth0 table net0 
    ip route add 192.168.0.0/24 dev eth0 table net0 
    ip rule add from 192.168.0.129 table net0  
    # Add v4 routes for eth1 
    ip route flush table net1 
    ip route add default via 192.168.1.1 dev eth1 table net1 
    ip route add 192.168.1.0/24 dev eth1 table net1 
    ip rule add from 192.168.1.138 table net1
   ```
   如果要配置IPv6的策略路由，先确认做过IPv6相关的配置，具体请参考[Linux操作系统（手动配置启用IPv6）](https://support.huaweicloud.com/usermanual-iec/iec_02_0629.html#iec_02_0629__section11875111003115)。
   对于每张网卡，查找以下信息：
   以eth0为例，IPv6地址：2407:c080:802:1be:2233:64bf:b095:54bf、子网网段：2407:c080:802:1be::/64、网关地址：fe80::f816:3eff:fef3:20dc，以及步骤1添加的路由表：net0，通过如下命令查看每张网卡对应的IPv6网关地址：
   **ip -6 route show\| grep default**
   ![](https://support.huaweicloud.com/usermanual-iec/zh-cn_image_0000001125673211.png "点击放大")
   如果有多张网卡，依次添加如下信息：
   ```
   # Add v6 routes for eth0 
    ip -6 route flush table net0 
    ip -6 route add default via fe80::f816:3eff:fef3:20dc dev eth0 table net0 
    ip -6 route add 2407:c080:802:1be::/64 dev eth0 table net0 
    ip -6 rule add from 2407:c080:802:1be:2233:64bf:b095:54bf table net0  
    # Add v6 routes for eth1 
    ip -6 route flush table net1 
    ip -6 route add default via fe80::f816:3eff:fe10:5447 dev eth1 table net1 
    ip -6 route add 2407:c080:802:1bf::/64 dev eth1 table net1 
    ip -6 rule add from 2407:c080:802:1bf:39ea:bffe:13a2:7a1f table net1
   ```
   
   
3. 执行以下命令，添加rc.local文件的执行权限。 
   **# chmod +x /etc/rc.local**
   
   
4. 执行**reboot**命令，重启边缘实例。
5. 重启后，执行以下命令，确认配置的路由规则和路由表生效，如果有多张路由表，依次执行。 
   对于IPv4：
   **ip rule**
   **ip route show table net0**
   **ip route show table net1**
   ![](https://support.huaweicloud.com/usermanual-iec/zh-cn_image_0000001125769195.png "点击放大")
   对于Ipv6：
   **ip -6 rule**
   **ip -6 route show table net0**
   **ip -6 route show table net1**
   ![](https://support.huaweicloud.com/usermanual-iec/zh-cn_image_0000001125673213.png "点击放大")
   
   
6. 指定源地址进行测试： 
   对于Ipv4：
   **ping -I 192.168.0.129 xxx**
   **ping -I 192.168.1.138 xxx**
   对于Ipv6：
   **ping -I 2407:c080:802:1be:2233:64bf:b095:54bf xxx**
   **ping -I 2407:c080:802:1bf:39ea:bffe:13a2:7a1f xxx**
   
   
 
#### 相关操作
如需通过扩展网卡访问公网，可参考[通过扩展网卡绑定的弹性公网IP访问公网](https://support.huaweicloud.com/usermanual-iec/iec_02_0905.html)。
