FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular open-source BSD operating system, accounting for more than three-quarters of all installed simply, permissively licensed BSD systems.
FreeBSD has similarities with Linux, with two major differences in scope and licensing: FreeBSD maintains a complete system, i.e. the project delivers a kernel, device drivers, userland utilities, and documentation, as opposed to Linux only delivering a kernel and drivers, and relying on third-parties for system software; and FreeBSD source code is generally released under a permissive BSD license, as opposed to the copyleft GPL used by Linux.
The following firewall was build to act as a NAT Server and also as a WEB server hosted on it. Also this firewall is working if this server act as a reverse proxy for backend WEB servers.
#################################
#### Packet Firewall Ruleset ####
#################################
###################
#### Variables ####
###################
# External interface
ext_if="vtnet0"
# Internal interface
int_if="vtnet1"
# Follow RFC1918 and don't route to non-routable IPs
# http://www.iana.org/assignments/ipv4-address-space
# http://rfc.net/rfc1918.html
nonroute= "{ 0.0.0.0/8, 20.20.20.0/24, 127.0.0.0/8, 169.254.0.0/16,
172.16.0.0/12, 192.0.2.0/24, 192.168.0.0/16, 224.0.0.0/3,
255.255.255.255 }"
# Set allowed ICMP types
# Blocking ICMP entirely is bad practice and will break things,
# FreeBSD does include rate limiting by default to mitigate attacks.
icmp_types = "{ 0, 3, 4, 8, 11, 12 }"
####################################
#### Options and optimizations #####
####################################
# Set interface for logging (statistics)
set loginterface $ext_if
# Drop states as fast as possible without having excessively low timeouts
set optimization aggressive
# Block policy, either silently drop packets or tell sender that request is blocked
set block-policy return
# Don't bother to process (filter) following interfaces such as loopback:
set skip on lo0
# Scrub traffic
# Add special exception for game consoles such as PS3 and PS4 (NAT type 2 vs 3)
# scrub from CHANGEME to any no-df random-id fragment reassemble
scrub on $ext_if all
#######################
#### NAT & Proxies ####
#######################
# Enable NAT and tell pf not to change ports if needed
# Add special exception for game consoles such as PS3 and PS4 (NAT type 2 vs 3)
# ie static-port mapping. Do NOT enable both rules.
# nat on $ext_if from $int_if:network to any -> ($ext_if) static-port
nat on $ext_if inet from any to any -> ($ext_if)
################################
#### Rules inbound (int_if) ####
################################
# Pass on everything incl multicast
pass in quick on $int_if inet all keep state
#################################
#### Rules outbound (int_if) ####
#################################
# Pass on everything incl multicast
pass out quick on $int_if inet all keep state
################################
#### Rules inbound (ext_if) ####
################################
# Drop packets from non-routable addresses immediately
block drop in quick on $ext_if from $nonroute to any
# Allow DHCP requests for WAN
pass in quick on $ext_if inet proto udp to ($ext_if) port { 67, 68 }
# Allow ICMP
pass in quick on $ext_if inet proto icmp all icmp-type $icmp_types
# Allow FTPs to connect to the FTP-proxy
#pass in quick on $ext_if inet proto tcp to ($ext_if) port ftp-data user proxy
# Allow SSH from LAN
pass quick proto tcp from { 127.0.0.1, 172.16.0.0/24 } to $int_if port { 21, 22 } flags S/SA keep state
# Allow all web traffic from Internet (em0)
pass quick proto tcp from any to any port { 80, 443 } flags S/SA keep state
################################################
# Block everything else
block in on $ext_if all
#pass in all
#################################
#### Rules outbound (ext_if) ####
#################################
# Drop packets to non-routable addresses immediately, allow everything else
block drop out quick on $ext_if from any to $nonroute
pass out on $ext_if all
Need help designing secure infrastructure with FreeBSD or Linux?
→ Check out our Infrastructure Services
0 Comments