服务器多个网卡添加虚拟路由器,如何为配置了多网卡的弹性云服务器配置策略路由?...

执行以下命令,在“/etc/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相关的配置,具体请参考动态获取IPv6地址的“Linux操作系统(手动配置启用IPv6)” 部分。

对于每张网卡,查找以下信息:

以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

04ee04af4df6326b19dbc663696518b8.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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值