Linux多运营商线路网卡配置

Linux多运营商线路网卡配置

配置方法:

  • 配置网络
  • 增加路由表
  • 增加默认网关
  • 增加回源路由

配置网络

这个根据运营商提供的IP来进行配置

举个例子:在bond模式下新增一个ip:

vim /etc/network/interfaces
post-up ifconfig bond0:0 电信IP netmask 子网掩码 up

配置路由表部分

Linux路由规则组成部分包括路由规则和路由表。

路由规则制定当数据包满足规则时,转交给某个路由表。

路由表根据数据包的信息,选择下一跳地址

  • 增加路由表

举个例子:添加一个电信路由表

vim /etc/network/interfaces
post-up (grep "101 dx" /etc/iproute2/rt_tables)|| (echo "101 dx" >> /etc/iproute2/rt_tables)
  • 增加默认路由

为dx这张表添加默认路由

vim /etc/network/interfaces
post-up ip route add default via ‘网关IP’ dev bond0:0 table dx
  • 增加路由返回功能,实现源进源出

根据源ip决定路由表

vim /etc/network/interfaces
post-up ip rule add from 电信IP table dx

汇总:

已添加一个电信线路为例,全部配置如下

vim /etc/network/interfaces
post-up (grep "101 dx" /etc/iproute2/rt_tables)|| (echo "101 dx" >> /etc/iproute2/rt_tables)
post-up ip route add default via ‘网关IP’ dev bond0:0 table dx
post-up ip rule add from 电信IP table dx

参考文档:

https://www.hi-linux.com/posts/64963.html#vip-container

https://www.cnblogs.com/jmilkfan-fanguiju/p/10589729.html

posted @ 2021-08-25 23:22  better_feng  阅读(283)  评论(0编辑  收藏  举报