write me firewall rules for freebsd for a web server
- User
write me firewall rules for freebsd for a web server
Assistant
Here's a basic set of firewall rules for FreeBSD using
pf(Packet Filter), suitable for a web server that runs HTTP/HTTPS and allows SSH access. This configuration is secure, minimal, and assumes you're using OpenSSH, HTTP (port 80), and HTTPS (port 443).
✅ Requirements:
- You are using PF as the firewall.
- The public interface is named something like
em0,re0, orvtnet0— adjust accordingly. - IPv4 only (IPv6 can be added separately).
- Allow inbound SSH, HTTP, HTTPS.
- Block everything else by default.
🛡️ FreeBSD PF Firewall Rules (
/etc/pf.conf)# Macros ext_if = "em0" # Replace with your actual external interface name http_ports = "{ 80, 443 }" ssh_port = 22 # Basic normalization and scrubbing set block-policy return scrub in all # Default policies block in all pass out all keep state # Allow loopback traffic pass quick on lo0 all # Allow SSH pass in on $ext_if proto tcp from any to any port $ssh_port flags S/SA keep state # Allow HTTP and HTTPS pass in on $ext_if proto tcp from any to any port $http_ports flags S/SA keep state # Optional: Allow ping (comment out if not needed) pass in on $ext_if proto icmp all icmp-type 8 code 0 # Block all other incoming traffic silently block in log all
🔁 Reload or Enable PF
- Enable PF at boot:
sudo sysrc pf_enable="YES"- Start PF now:
sudo service pf start- Load the ruleset:
sudo pfctl -f /etc/pf.conf- Check status:
sudo pfctl -s info- View logs (if blocking is logged):
sudo tcpdump -n -e -tttt -i pflog0
🧪 Testing Tips
- Test SSH access before disconnecting your session!
- From another terminal, try logging in again after applying rules.
- Use tools like
nmapor online scanners to verify ports are open/closed.
📝 Notes
- If you use IPv6, you should add similar rules for IPv6.
- For additional services (like SMTP, FTP, etc.), add them carefully.
- Consider rate-limiting SSH connections to prevent brute-force attacks.
Would you like an advanced version with tables, antispoof, or protection against brute-force attacks?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.