Portál AbcLinuxu, 11. května 2025 04:40
#!/bin/bash for int in /proc/sys/net/ipv4/conf/*/rp_filter; do echo "0" > $int; done for i in /proc/sys/net/ipv4/conf/*; do echo "1" > $i/accept_redirects 2> /dev/null echo "1" > $i/accept_source_route 2> /dev/null done table_1="route1" table_2="route2" ext_net_1="100.100.100.10/29" ext_if_1="eth1" ext_ip_1="100.100.100.12" ext_gw_1="100.100.100.11" ext_net_2="200.200.200.20/30" ext_if_2="eth2" ext_ip_2="200.200.200.22" ext_gw_2="200.200.200.21" cmd_ip="/sbin/ip" cmd_IPT="/usr/sbin/iptables" jm_chain="rozdel_routy" $cmd_IPT -D PREROUTING -t mangle -j $jm_chain 2>/dev/null; $cmd_IPT -A PREROUTING -t mangle -j $jm_chain; $cmd_IPT -N $jm_chain -t mangle 2>/dev/null; $cmd_IPT -F $jm_chain -t mangle; $cmd_IPT -A $jm_chain -t mangle -s 10.10.1.0/24 -j MARK --set-mark 10; $cmd_IPT -A $jm_chain -t mangle -s 10.10.2.0/24 -j MARK --set-mark 10; $cmd_IPT -A $jm_chain -t mangle -s 10.10.3.0/24 -j MARK --set-mark 20; $cmd_IPT -A $jm_chain -t mangle -s 10.10.4.0/24 -j MARK --set-mark 20; $cmd_ip route flush table $table_1 2>/dev/null; $cmd_ip route flush table $table_2 2>/dev/null; $cmd_ip route flush cache; $cmd_ip rule del table $table_1 2>/dev/null; $cmd_ip rule del table $table_2 2>/dev/null; $cmd_ip route add $ext_net_1 dev $ext_if_1 src $ext_ip_1 table $table_1; $cmd_ip route add default via $ext_gw_1 table $table_1; $cmd_ip route add $ext_net_2 dev $ext_if_2 src $ext_ip_2 table $table_2; $cmd_ip route add default via $ext_gw_2 table $table_2; $cmd_ip rule add fwmark 20 table $table_1 prio 100; $cmd_ip rule add fwmark 10 table $table_2 prio 101;Takze kdyz chci pingnout ze sveho PC s IP 10.10.1.4 na jine s IP 10.10.3.x tak to nedojde. Podle mne je to v tom ze prichozi muj paket se omarkuje na hodnotu 10 vleze do routovaci tabulky pro nej urcene a tam se hned posle ven. Jak teda zarucit aby se koukl prvni na local jestli tam nic neni?
ip route add 10.10.3.0/24 via 10.10.1.1samozrejme to chce dotvorit podle skutecne topologie site ... jinak viz. tento blog
route1
a pote do route2
a nic nepomohlo. Pri traceroutu
zustane stat na serveru a dal nevi co s tim. Nemate jeste prosim vas nejaky jiny napad?
ip r d default table mainPak vytvorene dve tabulky (gw1, gw2) ve kterych jsou pouze default routy, kazda k jinemu ISP.
ip r a default via gw.isp1.cz table gw1 ip r a default via gw.isp2.cz table gw2No a vysledne pravidla by byly zhruba tak:
0: from all lookup local 50: from all lookup main 100: fwmark 20 lookup gw1 101: fwmark 10 lookup gw2
ip r a default via gw.isp1.cz table default ip r a default via gw.isp2.cz table gw2 ip r d default table main ip ru a pref 50 table main ip ru a pref 101 fwmark 10 table gw2 ip ru d pref 32766 ----------------------- 0: from all lookup local 50: from all lookup main 101: fwmark 10 lookup gw2 32767: from all lookup default
#!/bin/bash for int in /proc/sys/net/ipv4/conf/*/rp_filter; do echo "0" > $int; done for i in /proc/sys/net/ipv4/conf/*; do echo "1" > $i/accept_redirects 2> /dev/null echo "1" > $i/accept_source_route 2> /dev/null done table_1="route1" ext_net_1="200.200.200.20/30" ext_if_1="eth2" ext_ip_1="200.200.200.22" ext_gw_1="200.200.200.21" ext_gw_2="100.100.100.11" cmd_ip="/sbin/ip" cmd_IPT="/usr/sbin/iptables" jm_chain="rozdel_routy" $cmd_IPT -D PREROUTING -t mangle -j $jm_chain 2>/dev/null; $cmd_IPT -A PREROUTING -t mangle -j $jm_chain; $cmd_IPT -N $jm_chain -t mangle 2>/dev/null; $cmd_IPT -F $jm_chain -t mangle; $cmd_IPT -A $jm_chain -t mangle -s 10.10.1.0/24 -j MARK --set-mark 10; $cmd_IPT -A $jm_chain -t mangle -s 10.10.2.0/24 -j MARK --set-mark 10; echo "Smaz tabulky + cache"; $cmd_ip route flush table $table_1 2>/dev/null; $cmd_ip route flush cache; echo "Smaz zapisi v rule"; $cmd_ip rule del table $table_1 2>/dev/null; $cmd_ip rule del table main 2>/dev/null; $cmd_ip route del default table main; echo "Menim priorytu mainu" $cmd_ip rule add table main prio 50; echo "Nahod routovani do tabulek"; $cmd_ip route add default via $ext_gw_2 table default; $cmd_ip route add default via $ext_gw_1 table $table_1; echo "nahod rule pro mark pakety"; $cmd_ip rule add fwmark 10 table $table_1 prio 100;Tady je cely script. Kdyby snad nekdo narazil na tuto diskusi se stajnym problemem jako ja tak at to ma jednodussi.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.