natd_program="/sbin/natd" natd_enable="YES" natd_flags="-f /etc/natd.conf"
log instance default interface xl0 port 8668 use_sockets yes same_ports yes instance xl1 interface xl1 port 8669 use_sockets yes same_ports yes globalport 8670
ipfw="/sbin/ipfw -q " local="re0" ISP1="xl0" ISP2="xl1" localnet="192.168.1.0/24" ISP1_ip="111.111.111.1" ISP2_ip="222.222.222.1" ISP1_gw="111.111.111.2" ISP2_gw="222.222.222.2" nat_ISP1="8668" nat_ISP2="8669" nat_glob="8670" ${ipfw} -f flush # . # sshd ${ipfw} add 20 allow tcp from any to me 22 # Web Server ${ipfw} add 25 allow tcp from any to me 80 # MailServer ${ipfw} add 26 allow tcp from any to me 25 ${ipfw} add 27 allow tcp from any to me 110 # . # , , . ${ipfw} add 100 fwd ${ISP1_gw} ip from ${ISP1_ip} to not ${localnet} ${ipfw} add 200 fwd ${ISP2_gw} ip from ${ISP2_ip} to not ${localnet} # , # ${ipfw} add 400 skipto 1000 all from any to any in recv ${local} ${ipfw} add 410 skipto 2000 all from any to any out xmit ${local} # ${ipfw} add 500 skipto 3000 all from any to any in recv ${ISP1} ${ipfw} add 550 skipto 4000 all from any to any out xmit ${ISP1} ${ipfw} add 600 skipto 5000 all from any to any in recv ${ISP2} ${ipfw} add 650 skipto 6000 all from any to any out xmit ${ISP2} # . , ${ipfw} add 900 deny all from any to any # ${ipfw} add 1000 allow all from any to any # ${ipfw} add 2000 allow all from any to any # ISP1 ( natd) ${ipfw} add 3000 divert ${nat_ISP1} ip from any to ${ISP1_ip} ${ipfw} add 3010 allow all from any to any # ISP1 ( ) # natd globalport ${ipfw} add 4000 divert ${nat_global} ip from ${localnet} to any # , natd , # , ${ipfw} add 4010 allow all from ${ISP1_ip} to any # , . ${ipfw} add 4020 fwd ${ISP2_gw} ip from ${ISP2_ip} to any # natd , , natd ${ipfw} add 4030 divert ${nat_ISP1} ip from ${localnet} to any # . ${ipfw} add 4040 allow all from any to any # # ISP2 ${ipfw} add 5000 divert ${nat_ISP2} ip from any to ${ISP2_ip} ${ipfw} add 5010 allow all from any to any # ISP2 ${ipfw} add 6000 divert ${nat_global} ip from ${localnet} to any ${ipfw} add 6010 allow all from ${ISP2_ip} to any ${ipfw} add 6020 fwd ${ISP1_gw} ip from ${ISP1_ip} to any ${ipfw} add 6030 divert ${nat_ISP2} ip from ${localnet} to any ${ipfw} add 6040 allow all from any to any
#!/bin/sh IP1=111.111.111.1 IP2=222.222.222.1 GW1=111.111.111.2 GW2=222.222.222.2 /sbin/ping -q -c 1 -S $IP1 yandex.ru > /dev/null 2>&1 if [ $? != 0 ]; then /sbin/ping -q -c 1 -S $IP2 yandex.ru > /dev/null 2>&1 if [ $? = 0 ]; then if [ ! -f /tmp/gw.changed ]; then /sbin/route change default $GW2 && touch /tmp/gw.changed fi fi else if [ -f /tmp/gw.changed ]; then /sbin/route change default $GW1 && rm /tmp/gw.changed fi fi
Source: https://habr.com/ru/post/124447/
All Articles