多网卡分流

多网卡分流:

#!/bin/bash
#eth0:10.10.2.105
#eth1:10.10.2.106
#eth2:10.10.2.107
#eth3:10.10.2.108
echo 105 eth0 >> /etc/iproute2/rt_tables
echo 106 eth1 >> /etc/iproute2/rt_tables
echo 107 eth2 >> /etc/iproute2/rt_tables
echo 108 eth3 >> /etc/iproute2/rt_tables
ip route add to 0.0.0.0/0 via 10.10.2.1 dev eth0 table eth0
ip route add to 0.0.0.0/0 via 10.10.2.1 dev eth1 table eth1
ip route add to 0.0.0.0/0 via 10.10.2.1 dev eth2 table eth2
ip route add to 0.0.0.0/0 via 10.10.2.1 dev eth3 table eth3
ip rule add from 10.10.2.105/32  table eth0
ip rule add from 10.10.2.106/32  table eth1
ip rule add from 10.10.2.107/32  table eth2
ip rule add from 10.10.2.108/32  table eth3
echo "route add to 0.0.0.0/0 via 10.10.2.1 dev eth0 table eth0" >> /etc/sysconfig/network
echo "route add to 0.0.0.0/0 via 10.10.2.1 dev eth1 table eth1" >> /etc/sysconfig/network
echo "route add to 0.0.0.0/0 via 10.10.2.1 dev eth2 table eth2" >> /etc/sysconfig/network
echo "route add to 0.0.0.0/0 via 10.10.2.1 dev eth3 table eth3" >> /etc/sysconfig/network
echo "rule add from 10.10.2.105/32  table eth0" >> /etc/sysconfig/network
echo "rule add from 10.10.2.106/32  table eth1" >> /etc/sysconfig/network
echo "rule add from 10.10.2.107/32  table eth2" >> /etc/sysconfig/network
echo "rule add from 10.10.2.108/32  table eth3" >> /etc/sysconfig/network

同段多IP分流:

#!/bin/bash
# 添加多路由分流
GATEWAY=10.10.2.1
ETH0=`/sbin/ifconfig eth0|grep "inet addr"|head -n 2|/bin/awk '/inet addr/ {split($2,x,":");print x[2]}'|head -1`
ETH1=`/sbin/ifconfig eth1|grep "inet addr"|head -n 2|/bin/awk '/inet addr/ {split($2,x,":");print x[2]}'|head -1`
route add -net 0.0.0.0 netmask 0.0.0.0 gw $GATEWAY dev eth0
route add -net 0.0.0.0 netmask 0.0.0.0 gw $GATEWAY dev eth1
ip route add to 0.0.0.0/0 via $GATEWAY dev eth0 table 10
ip route add to 0.0.0.0/0 via $GATEWAY dev eth1 table 20
ip rule add from $ETH0/32 table 10
ip rule add from $ETH1/32 table 20
route -n

 

你可能感兴趣的:(多网卡分流)