FreeBSD双线负载均衡NAT服务器配置方法

网络安全 2021-07-04 10:23www.168986.cn网络安全知识
# vi /etc/rc.conf
================+==============+=================
defaultrouter="221.33.88.254"
ifconfig_fxp0="i 192.168.0.1 mask 255.255.255.0"
ifconfig_rl0="i 221.33.88.2 mask 255.255.255.0"
ifconfig_rl1="i 202.0.57.1 mask 255.255.255.0"
pf_enable="YES"
================+==============+================= # vi /etc/pf.conf
================+==============+=================
##anchors
lan_ = "192.168.0.0/24"
int_if  = "fxp0"
ext_if1 = "rl0"
ext_if2 = "rl1"
ext_gw1 = "221.33.88.254"
ext_gw2 = "61.0.57.254" ##nat outgoing connections on each inter interface
nat on $ext_if1 from $lan_ to any -> ($ext_if1)
nat on $ext_if2 from $lan_ to any -> ($ext_if2) ##default deny
block in  from any to any
block out from any to any ##pass all outgoing packets on internal interface
pass out on $int_if from any to $lan_
##pass in quick any packets destined for the gateway itself
pass in quick on $int_if from $lan_ to $int_if
##load balance outgoing tcp traffic from internal work.
pass in on $int_if route-to \
{ ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
proto tcp from $lan_ to any flags S/SA modulate state
##load balance outgoing udp and icmp traffic from internal work
pass in on $int_if route-to \
{ ($ext_if1 $ext_gw1), ($ext_if2 $ext_gw2) } round-robin \
proto { udp, icmp } from $lan_ to any keep state ##general "pass out" rules for external interfaces
pass out on $ext_if1 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if1 proto { udp, icmp } from any to any keep state
pass out on $ext_if2 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if2 proto { udp, icmp } from any to any keep state ##route packets from any IPs on $ext_if1 to $ext_gw1 and the same for
##$ext_if2 and $ext_gw2
pass out on $ext_if1 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
pass out on $ext_if2 route-to ($ext_if1 $ext_gw1) from $ext_if1 to any
================+==============+================= # vi /etc/sysctl.conf
.i.ip.forwarding=1

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by