Что-то типа http://www.lissyara.su/articles/freebsd ... #example_5, но проще и с natd
# rc.conf
Код: Выделить всё
gateway_enable="YES"
defaultrouter="gw1"
ifconfig_fxp0="inet isp1 netmask 255.255.255.192 media 100baseTX link0 mediaopt full-duplex mtu 1500" # to isp1
ifconfig_fxp1="inet 192.168.1.1 netmask 255.255.255.0 media 100baseTX link0 mediaopt full-duplex mtu 1500" # to local network
ifconfig_em0="inet 192.168.5.1 netmask 255.255.255.0" # to isp2
setfib1_enable="YES"
setfib1_defaultroute="192.168.5.2" # gw2
Код: Выделить всё
net.inet.ip.fw.one_pass=0
Код: Выделить всё
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 192.168.5.2 UGS 0 40 em0
Код: Выделить всё
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default gw1 UGS 0 13682 fxp0
Код: Выделить всё
natd -a isp1 -p 8668 -s -m -u -P /var/run/natd1.pid
natd -a isp2 -p 8669 -s -m -P /var/run/natd2.pid
ipfw add 100 pass ip from any to any via lo0
ipfw add 410 setfib 1 ip from any to 192.168.1.203
ipfw add 415 setfib 1 ip from 192.168.1.203 to any
ipfw add 420 setfib 1 ip from any to any via em0
ipfw add 500 divert 8668 ip from any to any via fxp0
ipfw add 510 divert 8669 ip from any to any via em0
ipfw add 550 allow ip from any to any
Если убрать правило 510 (отключаем второй nat),
tcpdump: listening on em0, link-type EN10MB (Ethernet), capture size 96 bytes
Код: Выделить всё
IP (tos 0x0, ttl 127, id 7987, offset 0, flags [none], proto ICMP (1), length 60) 192.168.1.203 > 194.186.36.211: ICMP echo request, id 512, seq 45313, length 40
IP (tos 0x0, ttl 127, id 7990, offset 0, flags [none], proto ICMP (1), length 60) 192.168.1.203 > 194.186.36.211: ICMP echo request, id 512, seq 45569, length 40
IP (tos 0x0, ttl 127, id 7991, offset 0, flags [none], proto ICMP (1), length 60) 192.168.1.203 > 194.186.36.211: ICMP echo request, id 512, seq 45825, length 40
IP (tos 0x0, ttl 127, id 7992, offset 0, flags [none], proto ICMP (1), length 60) 192.168.1.203 > 194.186.36.211: ICMP echo request, id 512, seq 46081, length 40
Если правило 510 включено, на em0 - тишина.
Специально упростил задачу, чтобы научиться работать с двумя шлюзами, но пока не выходит...