zoukankan      html  css  js  c++  java
  • Linux 策略路由配置

    策略路由配置 

    #编辑rt_tables
    echo "192 net_192 " >> /etc/iproute2/rt_tables
    echo "196 net_196 " >> /etc/iproute2/rt_tables
    
    #清空net_192路由表
    ip route flush table net_192
    # 添加一个路由规则到 net_192 表,这条规则是 net_192 这个路由表中数据包默认使用源 IP 172.31.192.201 通过 ens4f0 走网关 172.31.192.254
    ip route add default via 172.31.192.254 dev ens4f0 src 172.31.192.201 table net_192
    #来自 172.31.192.201 的数据包,使用 net_192 路由表的路由规则
    ip rule add from 172.31.192.201 table net_192
    
    #清空net_196路由表
    ip route flush table net_196
    #添加一个路由规则到 net_196 表,这条规则是 net_196 这个路由表中数据包默认使用源 IP 172.31.196.1 通过 ens9f0 走网关 172.31.196.254 
    ip route add default via 172.31.196.254 dev ens9f0 src 172.31.196.1 table net_196
    #来自 172.31.196.1 的数据包,使用 net_196 路由表的路由规则
    ip rule add from 172.31.196.1 table net_196
    
    #添加默认网关
    route add default gw 172.31.192.254
    
    #如果需要自启动生效可以写进配置文件也可以加入rc.local
    vi /etc/rc.local
    
    ip route flush table net_192
    ip route add default via 172.31.192.254 dev ens4f0 src 172.31.192.201 table net_192
    ip rule add from 172.31.192.201 table net_192
    ip route flush table net_196
    ip route add default via 172.31.196.254 dev ens9f0 src 172.31.196.1 table net_196
    ip rule add from 172.31.196.1 table net_196
    route add default gw 172.31.192.254
    
    #查看路由表
    route -n
    
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    169.254.0.0     0.0.0.0         255.255.0.0     U     1006   0        0 ens9f0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1008   0        0 ens4f0
    169.254.0.0     0.0.0.0         255.255.0.0     U     1014   0        0 br-ex
    169.254.0.0     0.0.0.0         255.255.0.0     U     1015   0        0 br-int
    172.31.192.0    0.0.0.0         255.255.255.0   U     0      0        0 ens4f0
    172.31.196.0    0.0.0.0         255.255.255.0   U     0      0        0 ens9f0
    
    #在接入测试服务器上验证连通性
    ping 172.31.192.201
    ping 172.31.196.1
    
    作者:王奥OX
    链接:https://www.jianshu.com/p/19444d8f9b61
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    微信小程序 添加卡券至微信卡券
    微信小程序 引入第三方字体
    小程序 生成条形码barcode.js
    Pycharm编辑器功能之自动导入模块
    Cannot open include file: 'libxml/xpath.h': No such file or directory
    怎么在32位windows系统上搭建爬虫框架scrapy?
    python2.7安装Twisted报Microsoft Visual C++9.0 required
    在windows下搭建爬虫框架,安装pywin32时出错?
    python如何通过pymongo连接到mongodb?
    python2.7.12自带pip吗?
  • 原文地址:https://www.cnblogs.com/fatt/p/8135371.html
Copyright © 2011-2022 走看看