Configuring Firewall Rules for WireGuard: Allow Connections between PC1 (10.0.0.1) and PC2 (10.0.0.3)

Abstract: Resolve blocked peer-to-peer communication between PC1 and PC2 by allowing inbound UDP traffic on the WireGuard listen port.

Created: 2026-10-03 by

To allow direct communication between PC1 (10.0.0.1) and PC2 (10.0.0.3) over WireGuard, you must configure the host firewall to permit incoming traffic on the UDP port defined in your wg0.conf. By default, most Linux distributions block all unsolicited incoming connections. You need to explicitly open this specific UDP port using tools like ufw or iptables, ensuring that the WireGuard interface is allowed to receive packets from the remote peer without requiring IP forwarding for local subnet routing.

Understanding the Network Topology

Before modifying firewall rules, it is crucial to understand how WireGuard handles traffic. Unlike traditional VPNs that often route all traffic through a central gateway, WireGuard peers can communicate directly if they are configured as such. In this scenario, PC1 and PC2 are both clients connected to a server, but they also need to talk to each other directly. The key distinction here is between routing and forwarding. If PC1 wants to send data to PC2, and both machines have their own WireGuard interfaces, the traffic does not necessarily pass through the main network stack of the host acting as a router. Instead, the packets are encapsulated in WireGuard protocol headers and sent to the server, which decapsulates them and forwards them to the correct peer. However, the initial handshake and subsequent data flow require that the server's firewall allows the WireGuard daemon to listen on its designated port. Many users mistakenly believe they must enable ip_forward on the server to allow client-to-client communication. This is incorrect unless the server is acting as a gateway for non-WireGuard traffic. For pure WireGuard peer-to-peer communication within the virtual network, the firewall rule simply needs to allow inbound UDP traffic on the WireGuard port. The kernel handles the rest via the wg0 interface. For more details on managing DNS settings for these peers, see Configuring a Custom DNS Server for WireGuard VPN Clients.

Identifying the WireGuard Port

Firewall rules are specific to ports and protocols. You cannot simply "open WireGuard"; you must open the specific UDP port your configuration uses. Open your WireGuard configuration file, typically located at /etc/wireguard/wg0.conf, on the server. Look for the line starting with ListenPort. It will look something like this:
[Interface]
Address = 10.0.0.1/24
PrivateKey = [server_private_key]
ListenPort = 51820
In this example, the port is 51820. This is the standard default, but it can be changed. Note this number down, as you will need it for your firewall commands. If you do not specify a ListenPort, WireGuard defaults to 51820. Ensure that no other service is using this UDP port on the server before proceeding.

Configuring UFW (Uncomplicated Firewall)

Ubuntu and Debian-based systems often use UFW by default. It provides a simplified interface for managing iptables rules. To allow WireGuard traffic, you need to add an exception for the UDP port identified in the previous step. First, ensure UFW is enabled. If it is not, enable it with:
sudo ufw enable
Next, allow incoming traffic on the WireGuard port. Replace 51820 with your actual port number if different:
sudo ufw allow 51820/udp
This command tells the firewall to accept any incoming UDP packet destined for port 51820. It does not restrict the source IP address, which is appropriate for a VPN server that expects connections from multiple peers. After running this command, verify the status to ensure the rule was added correctly:
sudo ufw status
You should see a line similar to:
51820/udp                     ALLOW IN    Anywhere
If you are using a cloud provider like AWS, Azure, or Google Cloud, remember that you must also configure the security group or firewall associated with your virtual machine instance. These cloud firewalls operate independently of the OS-level firewall. You must add an inbound rule for UDP port 51820 (or your custom port) in the cloud console as well.

Configuring iptables Directly

For systems using raw iptables, such as CentOS, RHEL, or Arch Linux, the process is slightly more verbose but offers greater control. You need to insert a rule into the INPUT chain to accept UDP traffic on the WireGuard port. Assuming your port is 51820, run the following command:
sudo iptables -A INPUT -p udp --dport 51820 -j ACCEPT
This appends a rule to the end of the INPUT chain. If you have existing rules that might block traffic, you may need to place this rule earlier in the chain using -I instead of -A. For example:
sudo iptables -I INPUT 1 -p udp --dport 51820 -j ACCEPT
To make these changes persistent across reboots, you must save the iptables rules. On many systems, this is done using:
sudo iptables-save | sudo tee /etc/iptables/rules.v4
Or depending on your distribution, you might use netfilter-persistent save. Always check your distribution's documentation for the correct persistence method.

Verifying Connectivity Between PC1 and PC2

Once the firewall rules are in place, test the connection. From PC1 (10.0.0.1), attempt to ping PC2 (10.0.0.3):
ping 10.0.0.3
If the ping fails, do not immediately assume the firewall is the issue. Check the following: 1. WireGuard Service Status: Ensure the WireGuard service is active on both machines. Use systemctl status wg-quick@wg0. 2. Peer Configuration: Verify that PC1's config includes PC2 as a peer with the correct public key and endpoint, and vice versa. 3. AllowedIPs: Ensure that the AllowedIPs field in the peer configurations covers the respective IP addresses. For direct communication, PC1 should have AllowedIPs = 10.0.0.3/32 for PC2's peer entry, and PC2 should have AllowedIPs = 10.0.0.1/32 for PC1's peer entry. If connectivity still fails, consult Troubleshooting WireGuard Client-to-Client Communication Issues for deeper diagnostic steps.

Security Considerations

Opening the WireGuard port to the world is necessary for functionality, but it exposes your server to potential scanning or brute-force attempts against the WireGuard protocol. While WireGuard itself is lightweight and secure, it is good practice to monitor logs for unusual activity. You can limit access to specific IP ranges if you only expect connections from known sources. For UFW, this looks like:
sudo ufw allow from 203.0.113.0/24 to any port 51820 proto udp
However, for most home or small office setups, allowing all IPs is standard because the cryptographic handshake ensures that only authorized keys can establish a session. Unauthorized IPs cannot decrypt or inject traffic even if they reach the port.

Frequently Asked Questions

Do I need to enable ip_forward on the server?

No, enabling ip_forward is not required for basic client-to-client communication over WireGuard. This setting is only necessary if the server is acting as a router for traffic outside the WireGuard tunnel, such as connecting to the internet. For direct peer communication, the kernel handles packet forwarding via the wg0 interface automatically.

What happens if I change the ListenPort in wg0.conf?

If you change the ListenPort, you must update your firewall rules to match the new port. The firewall rule must allow inbound UDP traffic on the exact port specified in the configuration file. Failure to update the firewall will result in connection timeouts because the server will be listening on a port the firewall blocks.

Can I restrict WireGuard access to specific IP addresses?

Yes, you can restrict access by specifying source IPs in your firewall rules. For example, in UFW, you can use sudo ufw allow from [IP_ADDRESS] to any port 51820 proto udp. This adds an extra layer of security by ensuring that only trusted networks can initiate the handshake, although WireGuard's cryptography already prevents unauthorized decryption.

Why can PC1 ping the server but not PC2?

This usually indicates that the firewall rule is correct, but there is a misconfiguration in the WireGuard peers. Check that PC1's configuration lists PC2 as a peer with the correct public key and that the AllowedIPs for that peer includes PC2's IP address (10.0.0.3). Also, verify that PC2 has PC1 listed as a peer with corresponding AllowedIPs.

How do I check if my firewall is blocking WireGuard?

You can test connectivity by temporarily disabling the firewall to see if the connection works. If it does, the firewall is likely the culprit. Alternatively, use tcpdump on the server to monitor incoming UDP packets on the WireGuard port. If you see packets arriving but no response, the firewall is allowing them in, but something else is blocking the return traffic.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More