How to Enable Firewall Rules: Fast, Practical Steps to Lock Down Your Network
Lock down your server or network in minutes: learn how to enable firewall rules with fast, practical steps that reduce your attack surface, control access, and keep systems compliant.
Enabling effective firewall rules is one of the fastest, highest-impact steps you can take to secure a server, a virtual private server (VPS), or an entire network. Whether you’re a site owner, IT administrator, or developer deploying services, a well-configured firewall reduces attack surface, controls access, and helps maintain compliance. This article provides practical, hands-on guidance for enabling firewall rules across common platforms, explains core concepts, describes typical application scenarios, compares common firewall tools, and offers guidance for selecting the right approach for your environment.
Understanding the fundamentals
Before diving into commands and configuration files, it’s important to understand several core firewall concepts that apply across systems:
- Default policy: The base action (allow or deny) applied to traffic that doesn’t match any rule. Best practice: default deny for inbound traffic and default allow for outbound if you need to permit connections initiated from your host.
- Stateful vs stateless: Stateful firewalls track connection state (NEW, ESTABLISHED, RELATED) and can allow return traffic automatically. Stateless filters treat each packet independently. Use stateful filtering for TCP/UDP services for simplicity and security.
- Layers: Firewalls operate at various layers. Network/firewall rules usually work at Layers 3–4 (IP and TCP/UDP). Application firewalls inspect higher-layer payloads.
- Zones and interfaces: Organize rules by network interface or zone (public, private, DMZ). This helps apply different policies to different network segments.
- Ordering: Rule order matters. Many systems evaluate rules top-to-bottom and stop at the first match.
- Logging and monitoring: Enable logging for dropped/denied packets for troubleshooting and detecting attacks, but rate-limit logs to avoid disk saturation.
Platform-specific quick starts: Linux and Windows
Linux — nftables (modern recommended)
nftables is replacing iptables on modern Linux distributions and provides a cleaner rule syntax and more flexibility.
- To check if nftables is installed:
sudo nft --version. - Enable and start the service:
sudo systemctl enable --now nftables. - Minimal secure policy (default deny inbound, allow established):
Example ruleset (save as /etc/nftables.conf):
table inet filter {
chain input { type filter hook input priority 0; policy drop; }
chain forward { type filter hook forward priority 0; policy drop; }
chain output { type filter hook output priority 0; policy accept; }
chain input {
ct state established,related accept
iif lo accept
tcp dport {{22,80,443}} ct state new accept
icmp type echo-request accept
log prefix "nft-drop: " limit rate 10/second counter drop
}
}
Apply: sudo nft -f /etc/nftables.conf. This example allows SSH, HTTP, HTTPS and pings, while logging drops at a modest rate limit.
Linux — iptables (legacy)
Many systems still use iptables. Use the “filter” table for input/output/forward chains and remember to save rules with your distro’s utilities (iptables-save/iptables-restore or distro-specific scripts).
Minimal example:
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -p tcp -m multiport --dports 22,80,443 -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
Debian/Ubuntu convenience — UFW
UFW (Uncomplicated Firewall) provides a simple CLI for common setups. It’s suitable for many web servers and smaller deployments.
- Enable:
sudo apt install ufwthensudo ufw default deny incomingandsudo ufw default allow outgoing. - Allow SSH and web:
sudo ufw allow 22/tcp,sudo ufw allow http,sudo ufw allow https. - Enable:
sudo ufw enable. Check rules:sudo ufw status numbered.
Red Hat/CentOS — firewalld
firewalld uses zones and services; it’s the default on many RHEL-based systems.
- Enable and start:
sudo systemctl enable --now firewalld. - Set default zone policy and add services:
sudo firewall-cmd --permanent --add-service=ssh, and for web--add-service=http,--add-service=https. - Reload changes:
sudo firewall-cmd --reload. View active rules:sudo firewall-cmd --list-all.
Windows Server — Windows Firewall / Windows Defender Firewall
On Windows, use the built-in firewall with group policies for enterprise environments.
- Control via GUI: Windows Defender Firewall with Advanced Security.
- Or via PowerShell:
New-NetFirewallRule -DisplayName "Allow SSH" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 22. - Set default inbound rule behavior via group policy or local security policy to block unless explicitly allowed.
Practical application scenarios and rule patterns
Here are common scenarios and rule patterns you’ll encounter and how to implement them securely.
Secure remote administration
- Prefer SSH key authentication and disable password logins:
PermitRootLogin no,PasswordAuthentication noin /etc/ssh/sshd_config. - Restrict SSH to specific source IPs or ranges where possible:
ufw allow from 203.0.113.0/24 to any port 22or nftables/iptable rules matching source. - Use non-standard ports carefully — it’s obscurity, not security. Combine with rate limiting and fail2ban for protection.
Web servers and application segmentation
- Open only required ports (80/443). Avoid opening database ports publicly; use private networks, VPCs, or firewall rules restricting source to your application servers.
- If hosting multiple services, use separate zones or interfaces and explicit forwarding rules for controlled access.
NAT and port forwarding
If your firewall performs NAT (e.g., home router or cloud NAT), forward only necessary ports to internal IPs and keep public-to-private mappings explicit. In nftables/iptables, use the nat table and PREROUTING chain to translate destination ports/IPs.
DDoS mitigation and rate limiting
- Use connection tracking and rate-limiting rules to mitigate simple flooding: nftables’ limit/rate or iptables’ limit module.
- Combine with external services (CDNs, cloud DDoS protection) for high-volume attacks.
Advantages and trade-offs between common tools
nftables vs iptables
- nftables: modern, unified API for IPv4/IPv6/ARP, better syntax, lower overhead for complex rulesets.
- iptables: widely supported, many legacy scripts rely on it; less flexible for large dynamic rule sets.
UFW/firewalld vs manual rules
- UFW/firewalld: easier to manage for small/medium setups; good defaults and integration with system services.
- Manual nftables/iptables: offers the most control and performance for complex or high-throughput environments.
Host-based vs network-based firewalls
- Host-based: granular control per server, good for enforcing policies on individual instances (e.g., VPS).
- Network-based (edge firewall, cloud security groups): central control for an entire subnet, simpler to manage at scale. Use both for defense-in-depth.
Checklist and best practices for enabling firewall rules
- Plan first: Audit services and ports before applying a deny-all policy to avoid locking yourself out.
- Enable logging for denied traffic and monitor logs for suspicious patterns. Use rate limits for log entries.
- Test changes safely: Use a console (provider out-of-band access) or schedule maintenance windows. When changing SSH rules, keep an active session and test new connections before closing old ones.
- Automate and version-control firewall configurations using infrastructure-as-code (Ansible, Terraform, cloud provider templates) and store configs in git.
- Backup rules and ensure they persist across reboots and kernel updates.
- Use fail2ban or equivalent to block repeated login attempts based on logs, protecting services like SSH, FTP, and web admin panels.
- Minimize exposure by placing databases and admin interfaces on private networks with strict access controls.
Selecting the right firewall strategy for your VPS or cloud deployment
Choose based on scale, complexity, and operational model:
- Small websites or single-VM deployments: UFW or firewalld with a deny-inbound default and explicit service rules is usually sufficient.
- Medium deployments with multiple services: Use host-based nftables/iptables plus provider-level security groups for perimeter control.
- Large or regulated environments: Combine network firewalls, host-based controls, centralized logging/monitoring, and automation. Employ segmentation (VPCs/subnets, private routing) and hardware or cloud-native DDoS protections.
When using a VPS provider, check whether they supply network firewall or DDoS options at the control panel. These can complement your host-level rules and simplify management for public-facing services.
Summary
Enabling firewall rules is a fast, practical way to harden systems and reduce exposure. The core principles are consistent: adopt a default-deny posture for inbound traffic, allow established connections, restrict administrative access, log intelligently, and automate for repeatability. For modern Linux systems favor nftables for flexibility and performance, while UFW and firewalld provide excellent ergonomics for smaller setups. In production environments, combine host-based and network-level firewalls for defense-in-depth.
If you’re deploying services on a VPS, choose a provider that gives you reliable network performance and easy management options so you can focus on secure configuration. For example, consider VPS.DO’s services such as their USA VPS offerings when you need predictable infrastructure and strong network connectivity. For more information about the provider and their other offerings, visit VPS.DO.