Vou colocar aqui a configuração do
pf.conf que fiz, porém se quiserem aperfeiçoar sua configurações é somente editá-lo.
# vi /etc/pf.conf
Teremos o seguinte:
#Arquivo pf.conf by Marcio Freitas (Base Luciano)
#
#***& LINKS INTERNOS &***#
# Rede
lan_net1 = "192.168.0.0/24"
int_if1 = "em0"
int_gw1 = "192.168.0.1"
#***& LINKS INTERNET &***#
# Link 1
ext_if2 = "ste0" #(Interface de Rede de Internet)
ext_gw2 = "200.xxx.xxx.xxx" #(Gateway de Interface acima)
ext_ip2 = "200.xxx.xxx.xxx" #(Ip da Interface de Rede)
# Link 2
ext_if3 = "ste1" #(Interface de Rede de Internet)
ext_gw3 = "201.xxx.xxx.xxx" #(Gateway de Interface acima)
ext_ip3 = "201.xxx.xxx.xxx" #(Ip da Interface de Rede)
# Caso Queria Colocar mais Links (N=Numero que preferir)
#ext_ifN = "xl0" #(Interface de Rede de Internet) Exemplo "xl0"
#ext_gwN = "192.168.4.1" #(Gateway de Interface acima) Exemplo 192.168.4.1
#ext_ipN = "192.168.4.10" #(Ip da Interface de Rede) Exemplo 192.168.4.10
#***& Set's &***#
set block-policy return
set loginterface $ext_if2
set loginterface $ext_if3
#set loginterface $ext_ifN #(Adicionar a interface de Internet nova aqui)
set skip on lo0
set optimization high-latency
# Redes Internas pra INTERNET
nat on $ext_if2 from $lan_net1 to any -> ($ext_if2)
nat on $ext_if3 from $lan_net1 to any -> ($ext_if3)
#--------------------NOVA INTERFACE------------------------
#nat on $ext_ifN from $lan_net to any -> ($ext_ifN)
#-----------------------OU---------------------------------
#nat on { ext_if2 , ext_if3 , ext_ifN } from $lan_net1 to any -> { ($ext_if2) , (ext_if2) , (ext_ifN) }
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
anchor "ftp-proxy/*"
#Libera a Rede Interna para navegar
pass in quick on $int_if1 from $lan_net1 to any keep state
# aceita (quick) quaisquer pacotes destinados ao próprio gateway
pass in quick on $int_if1 from $lan_net1 to $int_if1
# HTTPS ( Caso tenha mais um link, adicione em { ($ext_if2 $ext_gw2 $ext_gwN) } )
pass in quick on $int_if1 route-to { ($ext_if2 $ext_gw2) } round-robin proto tcp from $lan_net1 to any port 443 flags S/SA modulate state
# Restante do Trafego ( Caso tenha mais um link, adicione em { ($ext_if2 $ext_gw2 $ext_gwN) } )
pass in on $int_if1 route-to { ($ext_if2 $ext_gw2), ($ext_if3 $ext_gw3) } round-robin proto tcp from any to any
# balanceamento de carga em pacotes udp e icmp vindos da rede interna ( Caso tenha mais um link, adicione em { ($ext_if2 $ext_if2), ($ext_if3 $ext_gw3), ($ext_ifN $ext_gwN) })
pass in on $int_if1 route-to { ($ext_if2 $ext_gw2), ($ext_if3 $ext_gw3) } round-robin proto { udp, icmp } from any to any keep state
# regras gerais "pass out" para as interfaces externas
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
pass out on $ext_if3 proto tcp from any to any flags S/SA modulate state
pass out on $ext_if3 proto { udp, icmp } from any to any keep state
#Caso Adicione mais um Link acrescente aqui.
#pass out on $ext_ifN proto tcp from any to any flags S/SA modulate state
#pass out on $ext_ifN proto { udp, icmp } from any to any keep state
# roteia pacotes de qualquer IP na $ext_if1 para $ext_gw1 e o mesmo para
# $ext_if2 e $ext_gw2
pass out on $ext_if2 route-to ($ext_if3 $ext_gw3) from $ext_if3 to any
pass out on $ext_if3 route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
#Caso Adicione mais um Link acrescente aqui.
#pass out on $ext_if2 route-to ($ext_ifN $ext_gwN) from $ext_if3 to any
#pass out on $ext_if3 route-to ($ext_ifN $ext_gwN) from $ext_if2 to any
#pass out on $ext_ifN route-to ($ext_if3 $ext_gw3) from $ext_if3 to any
#pass out on $ext_ifN route-to ($ext_if2 $ext_gw2) from $ext_if2 to any
block in
Salve e feche.
Reinicie o
OpenBSD e aproveite!
Como testar o Packet Filter
Execute o seguinte comando:
# route -n show | grep default
default 200.xxx.xxx.xxx UGS 0 0 - ste0
default 201.xxx.xxx.xxx UGS 0 0 - ste1
Use a internet como cliente do servidor e execute o comando novamente:
# route -n show | grep default
default 200.xxx.xxx.xxx UGS 0 10 - ste0
default 201.xxx.xxx.xxx UGS 0 5 - ste1
Caso não tenha aparecido assim dividido, tente usar coisas diferentes como MSN/Broswer/Velocímetro/Outros para gerar tráfego e execute o comando novamente.
Para facilitar a configuração dos clientes, configure o
servidor dhcp.
Edite o arquivo
/etc/dhcpd.conf, ele já vem pré-configurado, basta somente editar para sua rede interna. Em nosso exemplo acima ficaria assim:
# vi /etc/dhcpd.conf
# $OpenBSD: dhcpd.conf,v 1.1 1998/08/19 04:25:45 form Exp $
#
# DHCP server options.
# See dhcpd.conf(5) and dhcpd(8) for more information.
#
# Network: 192.168.1.0/255.255.255.0
# Domain name: my.domain
# Name servers: 192.168.1.3 and 192.168.1.5
# Default router: 192.168.1.1
# Addresses: 192.168.1.32 - 192.168.1.127
#
shared-network LOCAL-NET {
option domain-name "seudominio.com.br";
option domain-name-servers 208.67.222.222, 208.67.220.220;
subnet 192.168.0.0 netmask 255.255.255.0 {
option routers 192.168.0.1;
range 192.168.0.32 192.168.0.127;
}
}
Feche e salve.
Para dar o start no servidor dhcp execute o comando:
# dhcpd em0
Lembrando que em0 é nossa placa de rede interna (verifique qual o nome da sua interface interna).
Para iniciar no boot do OpenBSD você pode inserir esse comando no seguinte arquivo:
# vi /etc/rc.local
Teremos o seguinte:
# $OpenBSD: rc.local,v 1.39 2006/07/28 20:19:46 sturm Exp $
# Site-specific startup actions, daemons, and other things which
# can be done AFTER your system goes into securemode. For actions
# which should be done BEFORE your system has gone into securemode
# please see /etc/rc.securelevel.
echo -n 'starting local daemons:'
# Add your local startup actions here.
echo '.'
# Start do DHCPD on em0
dhcpd em0 # <<<<<<<<<< Aqui está o comando
Salve e feche.
Pronto, seu balanceamento de links está completo!
Espero que tenha ajudado.
Abraços.