Hi all
I had a working pf.conf configuration with a block log all, but I couldn't get port forwarding to work with that rule in place.
I need at least a block rule for incoming traffic on the WAN interface, but now my port forwarding works, though all internal networks can also communicate with each other.
What I’m aiming for is a secure FreeBSD router/firewall setup with a WAN interface, where I can configure port forwarding, and three internal networks that can only access the internet. For this, I’ve written the following rule:
I intended to later specify traffic between the subnets.
I’m also really keen on blocking traffic based on the source address, and that worked until I tried to get my subnet-to-subnet rules functioning. The pass quick on rule works fine, like this:
However, I would prefer to block by "source" rather than using the pass quick on approach.
I’d really appreciate any help in achieving a more secure configuration. I want to start with a block all rule at the top, but still allow the necessary traffic to work.
Currently, after changing my block all to block in log on $WAN_IF, I find that my three internal networks are completely open to each other, which I want to avoid.
Any advice or suggestions would be greatly appreciated!
I had a working pf.conf configuration with a block log all, but I couldn't get port forwarding to work with that rule in place.
I need at least a block rule for incoming traffic on the WAN interface, but now my port forwarding works, though all internal networks can also communicate with each other.
What I’m aiming for is a secure FreeBSD router/firewall setup with a WAN interface, where I can configure port forwarding, and three internal networks that can only access the internet. For this, I’ve written the following rule:
Code:
pass in log on $LAN_IF inet proto { udp, tcp } from $LAN_NET to ! <RFC1918> keep state
I’m also really keen on blocking traffic based on the source address, and that worked until I tried to get my subnet-to-subnet rules functioning. The pass quick on rule works fine, like this:
Code:
pass quick on $SERVER_IF proto tcp from $LAN_NET to 10.0.20.20 port 22
I’d really appreciate any help in achieving a more secure configuration. I want to start with a block all rule at the top, but still allow the necessary traffic to work.
Currently, after changing my block all to block in log on $WAN_IF, I find that my three internal networks are completely open to each other, which I want to avoid.
Any advice or suggestions would be greatly appreciated!
Code:
# Interfaces
WAN_IF = "vtnet0" # external interface (Internet-facing)
LAN_IF = "vtnet1" # Office network
SERVER_IF = "vtnet2" # Server network
VIDEO_IF = "vtnet3" # Guest network
INT_IFS = "{ LAN_IF, SERVER_IF, VIDEO_IF }"
# Subnets
LAN_NET = "10.0.10.0/24"
SERVER_NET = "10.0.20.0/24"
VIDEO_NET = "10.0.30.0/24"
# RFC1918 (Private networks)
#RFC1918 = "{ 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 }"
table <RFC1918> const { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 }
# Global Settings and Optimizations
set block-policy return # Return RST for blocked TCP, ICMP unreachable for other protocols
set skip on lo0 # Skip filtering on the loopback interface
set optimization normal # Optimize for normal network conditions
set require-order yes # Process rules in the order they appear
set state-policy if-bound # Tie states to the interface they originate from
set loginterface $WAN_IF # Log all traffic on the WAN interface for debugging
# Scrub packets (normalize traffic to prevent fragmentation-based attacks)
scrub in on $WAN_IF all
# NAT Configuration
nat on $WAN_IF from <RFC1918> to any -> ($WAN_IF)
rdr on $WAN_IF inet proto tcp from any to ($WAN_IF) port 80 -> 10.0.20.12 port 80
rdr on $WAN_IF inet proto tcp from any to ($WAN_IF) port 443 -> 10.0.20.12 port 443
# Default Block WAN
# block log all # This blocked rdr
block in log on $WAN_IF
# Block traffic to blocked IPs
block in log quick on $INT_IFS inet from <RFC1918> to <blocked_ips>
# Allow Ping
pass inet proto icmp icmp-type echoreq
# Allow outbound traffic from the firewall itself
pass out on $WAN_IF inet from ($WAN_IF) to any keep state
# Allow firewall to communicate with internal networks
pass out on $INT_IFS inet from self to <RFC1918> keep state
pass out on $LAN_IF inet from self to $LAN_NET keep state
pass out on $SERVER_IF inet from self to $SERVER_NET keep state
# Allow internal networks to access the Internet but block RFC1918 destinations
pass in log on $LAN_IF inet proto { udp, tcp } from $LAN_NET to ! <RFC1918> keep state
pass in log on $SERVER_IF inet proto { udp, tcp } from $SERVER_NET to ! <RFC1918> keep state
# Allow internal networks to access services on the firewall (DHCP, DNS, NTP)
pass in on $SERVER_IF inet proto { udp, tcp } from $SERVER_NET to self port { 22, 53, 67, 68, 123 } keep state
pass in on $LAN_IF inet proto { udp, tcp } from $LAN_NET to self port { 22, 53, 67, 68, 123 } keep state
pass in on $VIDEO_IF inet proto { udp, tcp } from $VIDEO_NET to self port { 53, 67, 68, 123 } keep state
# Internal rules
pass quick on $SERVER_IF proto tcp from $LAN_NET to 10.0.20.20 port { 22 }
# Port Forwarding Rules
pass in log on $WAN_IF inet proto tcp from any to 10.0.20.12 port 80 keep state
pass in log on $WAN_IF inet proto tcp from any to 10.0.20.12 port 443 keep state
# Firewall rules
pass in log on $WAN_IF inet proto tcp from any to ($WAN_IF) port 8123 keep state