按照腾讯云的弹性网卡文档设置好网卡后,如果重启网络或者机器,原先的路由需要重新配置,十分麻烦,本文将补充如何开机自动设置路由。本文环境以CentOS7+为例
- 按照腾讯云文档设置好网卡,输入
ip addr
,确认辅助网卡及网卡上的ip在内容中生效。 根据业务情况设置路由
创建两张路由表(多少张网卡建立多少张路由表)
echo "10 t1" >> /etc/iproute2/rt_tables echo "20 t2" >> /etc/iproute2/rt_tables
设定路由指向
echo "default via xxx.xxx.xxx.xxx dev eth0 table t1" >> /etc/sysconfig/network-scripts/route-eth0 echo "default via xxx.xxx.xxx.xxx dev eth1 table t2" >> /etc/sysconfig/network-scripts/route-eth1
xxx.xxx.xxx.xxx 填写对应网卡的网关添加路由规则
echo "from xxx.xxx.xxx.xxx table t1" >> /etc/sysconfig/network-scripts/rule-eth0 echo "from xxx.xxx.xxx.xxx table t2" >> /etc/sysconfig/network-scripts/rule-eth1
xxx.xxx.xxx.xxx 填写对应网卡的IP地址
- 重启网络后生效
systemctl restart network
设置完成后每次开机将会每次自动设置好路由