Hello everyone, over this weekend I spent some time by replacing my PFSense firewall with a FreeBSD IPFW one. Mostly because I wanted the flexibility that comes with FreeBSD and that I can install all kind of third party software on the same machine as it has plenty of available resources.
Anyway, getting IPFW to work has been a pain. I've spenth hours searching this forum for advice and tutorials, the FreeBSD mailing list and several blogs. There is a lot of confusing setups out there like if you should use natd() or IPFW-NAT.
Anyway I ended up with this configuration:
This seems to work well, I also changed net.inet.ip.fw.dyn_syn_lifetime from 20 to 300 as some connections would timout way too fast (Especially websockets). Even though every line is documented, I don't fully understand them, especially rule 5020 is confusing.
When you read these rules, are there anything unnecessary there? Am I missing something?
Anyway, getting IPFW to work has been a pain. I've spenth hours searching this forum for advice and tutorials, the FreeBSD mailing list and several blogs. There is a lot of confusing setups out there like if you should use natd() or IPFW-NAT.
Anyway I ended up with this configuration:
Code:
#!/bin/sh
#Quietly flush out rules
/sbin/ipfw -q -f flush
#Set command prefix (add "-q" option after development to turn on quiet mode)
cmd="/sbin/ipfw add"
# set outside and inside network interfaces
wan_if="em1"
lan_if="em2"
ipmi_if="em3"
/sbin/ipfw nat 1 config if $wan_if unreg_only \
reset \
redirect_port tcp 192.168.0.2:22 22
# Allow anything within the LAN - interface with heaviest traffic shall come first.
$cmd 10 allow ip from any to any via $lan_if
$cmd 20 allow ip from any to any via lo0
$cmd 30 allow ip from any to any via $ipmi_if
# Catch spoofing from outside.
$cmd 70 deny ip from any to any not antispoof in recv $wan_if
# you need this to be able to renew your DHCP lease from your ISP
$cmd 80 allow udp from 92.221.96.1 67 to any 68 in recv $wan_if
# allow dns to host
$cmd 82 allow udp from any to any dst-port 53 in setup keep-state
$cmd 83 allow udp from any to any dst-port 53 out setup keep-state
$cmd 88 allow tcp from any to any dst-port 53 in setup keep-state
$cmd 89 allow tcp from any to any dst-port 53 out setup keep-state
# NAT rule for incomming packets.
$cmd 100 nat 1 ip4 from any to any in recv $wan_if
$cmd 101 check-state
# Rules for outgoing traffic - allow everything that is not explicitely denied.
$cmd 1000 deny ip from not me to any 25,53 out xmit $wan_if
$cmd 1010 deny ip from any to any 5353 out xmit $wan_if
$cmd 1020 deny ip from any to any 1900,2195,2196,4488,5223,5350,5351 out xmit $wan_if
# Allow all other outgoing connections.
$cmd 2000 skipto 10000 tcp from any to any out xmit $wan_if setup keep-state
$cmd 2010 skipto 10000 udp from any to any out xmit $wan_if keep-state
# Rules for incomming traffic - deny everything that is not explicitely allowed.
$cmd 5020 allow udp from any to me in recv $wan_if frag
# Rules for allowing dial-in calls to services which are listening on a LAN interface behind the NAT
$cmd 6000 skipto 10000 tcp from any to any 22 in recv $wan_if setup keep-state
# Catch tcp/udp packets, but don't touch gre, esp, icmp traffic.
$cmd 9998 deny tcp from any to any via $wan_if
$cmd 9999 deny udp from any to any via $wan_if
# NAT rule for outgoing packets.
$cmd 10000 nat 1 ip4 from any to any out xmit $wan_if
# Allow anything else, just in case IPFW is not configured as open firewall.
$cmd 65534 allow ip from any to any
This seems to work well, I also changed net.inet.ip.fw.dyn_syn_lifetime from 20 to 300 as some connections would timout way too fast (Especially websockets). Even though every line is documented, I don't fully understand them, especially rule 5020 is confusing.
When you read these rules, are there anything unnecessary there? Am I missing something?