How to Set Up Windows Firewall on Your VPS
What is Windows Firewall?
Windows Firewall is a security system that controls what can connect to your Windows VPS. It blocks bad connections and allows safe ones.
Windows Firewall helps protect your VPS from hackers and unwanted traffic. It's like a security guard that checks everyone trying to connect to your server.
Why Do You Need a Firewall?
- Stop hackers from getting into your server
- Block unwanted programs from connecting to the internet
- Protect your data from being stolen
- Control network access - only allow what you need
- Meet security requirements - many applications need firewall protection
Important
Always be careful when setting up firewall rules. If you block the wrong ports, you might lose access to your server!
Checking Your Firewall Status
Step 1: Open Windows Defender Firewall
- Press Windows key + R
- Type:
wf.mscand press Enter - Windows Defender Firewall will open
Step 2: Check Firewall Status
You should see:
- Domain Profile: Connected (if on domain) or Not connected
- Private Profile: Connected (if on private network)
- Public Profile: Connected (if on public network)
All should show "On" for protection.
Basic Firewall Rules
Allow RDP (Remote Desktop)
RDP is how you connect to your Windows VPS. You need to allow it:
- Open Windows Defender Firewall
- Click "Inbound Rules" on the left
- Click "New Rule" on the right
- Select "Port" and click Next
- Select "TCP" and enter 3389 for port
- Select "Allow the connection" and click Next
- Check all profiles (Domain, Private, Public) and click Next
- Name it "RDP" and click Finish
Allow Web Traffic (if you have a website)
# Allow HTTP (port 80)
New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
# Allow HTTPS (port 443)
New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action AllowAllow Game Server Ports
# Allow FiveM server (port 30120)
New-NetFirewallRule -DisplayName "FiveM" -Direction Inbound -Protocol TCP -LocalPort 30120 -Action Allow
# Allow Minecraft server (port 25565)
New-NetFirewallRule -DisplayName "Minecraft" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action AllowUsing PowerShell for Firewall Rules
Create Rules with PowerShell
Open PowerShell as Administrator and use these commands:
# Allow a specific port
New-NetFirewallRule -DisplayName "My App" -Direction Inbound -Protocol TCP -LocalPort 8080 -Action Allow
# Allow a program
New-NetFirewallRule -DisplayName "My Program" -Direction Inbound -Program "C:\Program Files\MyApp\app.exe" -Action Allow
# Block a port
New-NetFirewallRule -DisplayName "Block Port" -Direction Inbound -Protocol TCP -LocalPort 1234 -Action BlockView All Rules
# List all inbound rules
Get-NetFirewallRule -Direction Inbound | Format-Table DisplayName, Enabled, Direction
# List rules for a specific port
Get-NetFirewallPortFilter | Where-Object LocalPort -eq 80 | Get-NetFirewallRuleRemove Rules
# Remove a rule by name
Remove-NetFirewallRule -DisplayName "My App"
# Remove all rules for a port
Get-NetFirewallPortFilter | Where-Object LocalPort -eq 8080 | Get-NetFirewallRule | Remove-NetFirewallRuleCommon Ports You Might Need
| Port | What it's for | PowerShell Command |
|---|---|---|
| 3389 | RDP (Remote Desktop) | New-NetFirewallRule -DisplayName "RDP" -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Allow |
| 80 | HTTP websites | New-NetFirewallRule -DisplayName "HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow |
| 443 | HTTPS websites | New-NetFirewallRule -DisplayName "HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow |
| 21 | FTP | New-NetFirewallRule -DisplayName "FTP" -Direction Inbound -Protocol TCP -LocalPort 21 -Action Allow |
| 1433 | SQL Server | New-NetFirewallRule -DisplayName "SQL Server" -Direction Inbound -Protocol TCP -LocalPort 1433 -Action Allow |
| 25565 | Minecraft server | New-NetFirewallRule -DisplayName "Minecraft" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow |
| 30120 | FiveM server | New-NetFirewallRule -DisplayName "FiveM" -Direction Inbound -Protocol TCP -LocalPort 30120 -Action Allow |
Advanced Firewall Settings
Enable Logging
- Open Windows Defender Firewall
- Click "Windows Defender Firewall Properties"
- Go to each profile tab (Domain, Private, Public)
- Click "Customize" under Logging
- Check "Log dropped packets" and "Log successful connections"
- Set log file size (default is 4MB)
Block Specific IP Addresses
# Block a specific IP
New-NetFirewallRule -DisplayName "Block IP" -Direction Inbound -RemoteAddress 192.168.1.100 -Action Block
# Block a range of IPs
New-NetFirewallRule -DisplayName "Block IP Range" -Direction Inbound -RemoteAddress 192.168.1.0/24 -Action BlockAllow Only Specific IPs
# Allow only specific IP to connect
New-NetFirewallRule -DisplayName "Allow Specific IP" -Direction Inbound -RemoteAddress 192.168.1.50 -Protocol TCP -LocalPort 3389 -Action AllowTesting Your Firewall
Test from Another Computer
# Test if a port is reachable
telnet YOUR_VPS_IP 80
# Test RDP connection
mstsc /v:YOUR_VPS_IPCheck Firewall Logs
- Open Event Viewer
- Go to Windows Logs > Security
- Look for events with source "Microsoft-Windows-Windows Firewall With Advanced Security"
Use Online Port Scanner
- Go to https://www.yougetsignal.com/tools/open-ports/
- Enter your VPS IP address
- Check which ports are open
Troubleshooting
Problem: "Cannot connect to server"
Solutions:
- Check if the port is allowed in firewall
- Verify the application is running
- Test with telnet or port scanner
Problem: "Firewall rule not working"
Solutions:
- Make sure you're using the right protocol (TCP/UDP)
- Check if the rule is enabled
- Verify the port number is correct
Problem: "Too many rules"
Solutions:
- Group similar rules together
- Use port ranges when possible
- Remove unused rules regularly
Security Best Practices
1. Default Deny
- Block everything by default
- Only allow what you need
- Use specific rules, not broad ones
2. Regular Updates
- Keep Windows updated
- Review firewall rules monthly
- Remove unused rules
3. Monitor Logs
- Check firewall logs regularly
- Look for unusual activity
- Set up alerts for blocked connections
4. Use Strong Rules
- Specify exact ports and protocols
- Limit source IP addresses when possible
- Use descriptive names for rules
Quick Commands Reference
# Check firewall status
Get-NetFirewallProfile
# List all rules
Get-NetFirewallRule
# Enable firewall for all profiles
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
# Disable firewall (not recommended)
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
# Export firewall rules
Export-NetFirewallRule -Path C:\firewall-rules.xml
# Import firewall rules
Import-NetFirewallRule -Path C:\firewall-rules.xmlYour VPS is Protected!
Your Windows VPS is now much safer with proper firewall rules. Remember to only open the ports you actually need!