ipfw es el software firewall avalado por freebsd, viene por defetco asi que no debemos hacer mucho. pues este ya sta en una instalacion base. hay otras maneras de establecer reglas, YO particularmente escogí crear un script y ahi colocar las reglas, el script luego se puede ejecutrar via sh.
para activarlo necesitamos agregar a rc.conf
# vi /etc/rc.conf
firewall_enable="YES"
firewall_type="open"
firewall_script="/etc/firewall"
Luego creamos y dento de /etc/firewall agregamos lo siguiente:
#!/bin/sh
#borrando antiguas reglas
ipfw -q flush
#permito lan y loopback
ipfw -q add allow all from any to any via rl0
ipfw -q add allow all from any to any via lo0
#importante para el nat del equipo
ipfw -q add divert natd ip from any to any via wlan0
ipfw -q add check-state
#states importantes para conexiones establecidas
ipfw -q add allow tcp from any to any established
#aceptando ssh dns http openvpn
#ipfw -q add allow tcp from any to any 2022 in via wlan0 keep-state
ipfw -q add allow tcp from any to any 22 out keep-state
ipfw -q add allow tcp from any to any 22 in keep-state
ipfw -q add allow tcp from any to 172.16.1.1 53 setup keep-state
ipfw -q add allow udp from any to 172.16.1.1 53 keep-state
ipfw -q add allow tcp from any to any 80 keep-state
ipfw -q add allow tcp from any to any 1194 via wlan0 keep-state
#denegar todo trafico tcp con reset
ipfw -q add reset log tcp from any to any
#denegar todo trafico udp con reset
ipfw -q add reset log udp from any to any
#denegando pings
ipfw -q add allow icmp from any to any keep-state
reinciamos el servicio
#service ipfw restart
y listo.
Ahora explicare un poco algunas reglas y parametros :
--> ipfw -q add allow all from any to any via rl0: Estoy agregando una regla permisiva "allow" para todo "all" desde cualquier origen "from any" hacia cualquier destino "to any" por la interfaz rl0 "via rl0". Básicamente permito que todo el trafico entre y salga por mi rl0.... rl0 (realtek0 asi las nombra Freebsd) es mi interfaz hacia la lan. Por defecto la ultima regla del firewall es denegar todo, esto es por seguridad, debemos permitir trafico LAN ya que sino se hace no podran haber servicios basicos como enrutamiento interno, resolucion d nombres, DHCP, etc.
--> ipfw -q add allow tcp from any to any established: "established" Estoy permitiendo basicamente dialogo tcp establecido(3 hand shake ack y rst).
--> ipfw -q add allow tcp from any to 172.16.1.1 53 setup keep-state: Pemito paquetes por el puerto 53 hacia mi dns 172.16.1.1. "setup" basicamente permite paquetes para establecer dialogo( 3-handshake syn solamente) "keep-state" marca los paquetes para que pasen tanto de entrada como de salida.
--> ipfw -q add reset log tcp from any to any: Con esta regla envio un reset al inicio del 3handshake , dandole al usuario un port unreachable y no un filter.
--> ipfw -q add allow icmp from any to any keep-state: permito protocolo icmp.
---> ipfw -q add divert natd ip from any to any via wlan0: esta regla es para NAT. Todo trafico entrante es enviado al demonio NAT para antes ver sus reglas. mas informacion en la seccion NAT en FREEBSD.
Espero les sirva de ayuda!!!
Saludos!!
para activarlo necesitamos agregar a rc.conf
# vi /etc/rc.conf
firewall_enable="YES"
firewall_type="open"
firewall_script="/etc/firewall"
Luego creamos y dento de /etc/firewall agregamos lo siguiente:
#!/bin/sh
#borrando antiguas reglas
ipfw -q flush
#permito lan y loopback
ipfw -q add allow all from any to any via rl0
ipfw -q add allow all from any to any via lo0
#importante para el nat del equipo
ipfw -q add divert natd ip from any to any via wlan0
ipfw -q add check-state
#states importantes para conexiones establecidas
ipfw -q add allow tcp from any to any established
#aceptando ssh dns http openvpn
#ipfw -q add allow tcp from any to any 2022 in via wlan0 keep-state
ipfw -q add allow tcp from any to any 22 out keep-state
ipfw -q add allow tcp from any to any 22 in keep-state
ipfw -q add allow tcp from any to 172.16.1.1 53 setup keep-state
ipfw -q add allow udp from any to 172.16.1.1 53 keep-state
ipfw -q add allow tcp from any to any 80 keep-state
ipfw -q add allow tcp from any to any 1194 via wlan0 keep-state
#denegar todo trafico tcp con reset
ipfw -q add reset log tcp from any to any
#denegar todo trafico udp con reset
ipfw -q add reset log udp from any to any
#denegando pings
ipfw -q add allow icmp from any to any keep-state
reinciamos el servicio
#service ipfw restart
y listo.
Ahora explicare un poco algunas reglas y parametros :
--> ipfw -q add allow all from any to any via rl0: Estoy agregando una regla permisiva "allow" para todo "all" desde cualquier origen "from any" hacia cualquier destino "to any" por la interfaz rl0 "via rl0". Básicamente permito que todo el trafico entre y salga por mi rl0.... rl0 (realtek0 asi las nombra Freebsd) es mi interfaz hacia la lan. Por defecto la ultima regla del firewall es denegar todo, esto es por seguridad, debemos permitir trafico LAN ya que sino se hace no podran haber servicios basicos como enrutamiento interno, resolucion d nombres, DHCP, etc.
--> ipfw -q add allow tcp from any to any established: "established" Estoy permitiendo basicamente dialogo tcp establecido(3 hand shake ack y rst).
--> ipfw -q add allow tcp from any to 172.16.1.1 53 setup keep-state: Pemito paquetes por el puerto 53 hacia mi dns 172.16.1.1. "setup" basicamente permite paquetes para establecer dialogo( 3-handshake syn solamente) "keep-state" marca los paquetes para que pasen tanto de entrada como de salida.
--> ipfw -q add reset log tcp from any to any: Con esta regla envio un reset al inicio del 3handshake , dandole al usuario un port unreachable y no un filter.
--> ipfw -q add allow icmp from any to any keep-state: permito protocolo icmp.
---> ipfw -q add divert natd ip from any to any via wlan0: esta regla es para NAT. Todo trafico entrante es enviado al demonio NAT para antes ver sus reglas. mas informacion en la seccion NAT en FREEBSD.
Espero les sirva de ayuda!!!
Saludos!!