目前天翼云4.0已支持在控制台绑定解绑弹性网卡;一台虚机可具备多张弹性网卡,但在默认情况下,主辅网卡网络不通,因此,本文介绍以下几种场景下的多网卡天翼云主机如何实现网络的连通验证
一、两台云主机的主辅网卡在同一个VPC下的同一子网
1、组网拓扑
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/c512c24c04a04301bb350245c4920553.png)
2、两台主机均有2张网卡,实现VM1和VM2的主辅网络互通
3、用户可在天翼云4.0上为两台主机各自添加与主网卡同子网下的弹性网卡,VM1、VM2的配置如下
主机
主网卡
辅网卡
VM1
eth0:192.168.0.65
eth1:192.168.0.62
VM2
eth0:192.168.0.66
eth1:192.168.0.63
天翼云控制台VM1的配置
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/de247b170de548b696432a973e6338b3.png)
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/2cbc5b39ad22438091b11cbf5bfbc9b3.png)
天翼云控制台VM2的配置
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/b070fcb454ce4f47ad746c8831f480aa.png)
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/50313453a5314e2b9e45b96380991df8.png)
4、默认情况下,只有主网卡可以互通,辅助弹性网卡网络不互通
5、解方法:分别在两台主机上配置策略路由
以VM1为例,如下配置
#编辑rt_tables
echo "66 net_66 " >> /etc/iproute2/rt_tables
echo "63 net_63 " >> /etc/iproute2/rt_tables
#清空net_66路由表
ip route flush table net_66
# 添加一个路由规则到 net_66 表,这条规则是 net_66 这个路由表中数据包默认使用源 IP 通过 eth0 192.168.0.66 走网关 192.168.0.1
ip route add default via 192.168.0.1 dev eth0 src 192.168.0.66 table net_66
#来自 192.168.0.66 的数据包,使用 net_66 路由表的路由规则
ip rule add from 192.168.0.66 table net_66
#清空net_63路由表
ip route flush table net_63
#添加一个路由规则到 net_63 表,这条规则是 net_63 这个路由表中数据包默认使用源 IP 192.168.0.63 通过 eth1 走网关 192.168.0.1
ip route add default via 192.168.0.1 dev eth1 src 192.168.0.63 table net_63
#来自 192.168.0.160 的数据包,使用 net_63 路由表的路由规则
ip rule add from 192.168.0.63 table net_63
#ip rule查看策略路由表
#配置完成后,从VM2测试ping虚机VM1,主从网卡都可连通
类似的方式在主机VM2上添加策略路由
从VM1测试ping虚机VM2,主从网卡都可以连通
二、两台云主机属于同一VPC,但主网卡属于同一子网,辅网卡属于另一子网
1、主网卡和辅网卡可互相进行对等访问,不需要加策略路由
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/d49c9c306bf840bcbf2816de5b8a7be3.png)
2、如果需要主辅网卡交叉访问,则要加策略路由
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/c3b3d719d06b4cde888decdbca6adac8.png)
天翼云控制台VM1、VM2主辅网卡不同子网网卡配置如下
主机
主网卡
辅网卡
VM1
eth0:192.168.0.65
eth1:192.168.35.12
VM2
eth0:192.168.0.66
eth1:192.168.35.9
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/ac042f0e4228449bbf59c3330a37d44d.png)
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/139a42ba2a924b59b45707d18fa93692.png)
天翼云控制台VM2主辅网卡不同子网结果如下
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/958102418fb9434e889b298669f7e4d7.png)
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/cda185cef24d4c87b6616b017dbf6318.png)
默认情况下,主主可通,辅辅可通,但主辅不通
若实现上述的不同子网的主辅网卡交叉访问,需配置策略路由,见上策略路由的配置方式
VM1上配置策略路由
![](https://ctyun-developers-0510.gdoss.xstore.ctyun.cn/prod/bc3ca206b8084f83aef6f308d6b37853.png)
在VM2上进行连通性访问
1、ping -I eth0 192.168.0.65 VM2主 -> VM1 主
2、ping -I eth0 192.168.35.12 VM2主 -> VM1 辅
3、ping -I eth1 192.168.0.65 VM2辅 -> VM1 主
4、ping -I eth1 192.168.35.12 VM2辅 -> VM1 辅
预期结果:网络均通,即可实现如下场景中的多网卡网络互通
VM2的配置类似,这里就不在赘述
三、目前天翼云暂不支持主辅网卡在不同的VPC下,这里暂且略过此场景
|