SHOW:
|
|
- or go back to the newest paste.
1 | # add routing tables | |
2 | # flush old tables | |
3 | ip route flush table $TABLE1 | |
4 | ip route flush table $TABLE2 | |
5 | # add new table | |
6 | ip route add $GW1 dev $DEV1 src $IP1 table $TABLE1 | |
7 | ip route add default via $GW1 table $TABLE1 | |
8 | ip route add $GW2 dev $DEV2 src $IP2 table $TABLE2 | |
9 | ip route add default via $GW2 table $TABLE2 | |
10 | ||
11 | # add rule for lookup | |
12 | # remove old rule | |
13 | ip rule del from $IP1 table $TABLE1 | |
14 | ip rule del from $IP2 table $TABLE2 | |
15 | ip rule del fwmark 1 table $TABLE1 | |
16 | ip rule del fwmark 2 table $TABLE2 | |
17 | # add new rule | |
18 | ip rule add from $IP1 table $TABLE1 | |
19 | ip rule add from $IP2 table $TABLE2 | |
20 | ip rule add fwmark 1 table $TABLE1 | |
21 | ip rule add fwmark 2 table $TABLE2 | |
22 | ||
23 | # iptables rules for SNAT: | |
24 | iptables -t nat -A POSTROUTING -o ppp0 -j SNAT --to-source $IP1 | |
25 | iptables -t nat -A POSTROUTING -o ppp1 -j SNAT --to-source $IP2 | |
26 | ||
27 | # iptables for marking packet from originate source | |
28 | iptables -t mangle -A PREROUTING -m state --state ESTABLISHED,RELATED -j CONNMARK --restore-mark | |
29 | iptables -t mangle -A OUTPUT -m state --state ESTABLISHED,RELATED -j CONNMARK --restore-mark | |
30 | iptables -t mangle -A PREROUTING -i ppp0 -m state --state NEW -j CONNMARK --set-mark 1 | |
31 | iptables -t mangle -A PREROUTING -i ppp1 -m state --state NEW -j CONNMARK --set-mark 2 | |
32 | iptables -t mangle -A PREROUTING -m connmark --mark 1 -j MARK --set-mark 1 | |
33 | iptables -t mangle -A PREROUTING -m connmark --mark 2 -j MARK --set-mark 2 | |
34 | iptables -t mangle -A PREROUTING -m connmark ! --mark 0 -m state --state NEW -j CONNMARK --save-mark |