IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Linux simple source policy routing

    hev发表于 2018-06-27 15:01:20
    love 0

    Dual network connections
    eth0:
    Address: 192.168.0.2
    NetMask: 255.255.255.0
    Gateway: 192.168.0.1

    eth1:
    Address: 192.168.1.2
    NetMask: 255.255.255.0
    Gateway: 192.168.1.1

    Routing policy
    * Transmit via eth0 when source address is 192.168.0.2
    * Transmit via eth1 when source address is 192.168.1.2

    Commands

    # eth0
    ifconfig eth0 192.168.0.2/24 up
    ip rule add from 192.168.0.2 table 251
    ip route add default via 192.168.0.1 dev eth0 src 192.168.0.2 table 251
    
    # eth1
    ifconfig eth1 192.168.1.2/24 up
    ip rule add from 192.168.1.2 table 252
    ip route add default via 192.168.1.1 dev eth1 src 192.168.1.2 table 252
    

    Over!



沪ICP备19023445号-2号
友情链接