To resolve the issue where your Internet is not working over the WireGuard VPN, let's systematically check and configure both the server and client settings. Here's a step-by-step guide to help you troubleshoot and fix the problem.
1. Verify WireGuard Configuration
On the Server (wg0 interface):
Your current server configuration shows two peers:
-
Peer 1:
- Public Key:
Mr3u8mqBmQ1vRxGZ871RoO/IpiohZheB7SOyHbGWmT4=
- Allowed IPs:
10.0.0.2/32
- Endpoint:
92.62.58.199:42818
- Status: Connected (latest handshake 5 minutes ago)
-
Peer 2:
- Public Key:
QG57FCPa2dQwhQvJdrD+HP1dTQL4Jn/e0d91PV1U+AE=
- Allowed IPs:
(none)
On the Client:
- Interface:
PrivateKey = sP7i5iqsgjDV0VEci0iDGVQg6bKavsMKgoTOEvw1ylc=
Address = 10.0.0.2/32
DNS = 1.1.1.1
- Peer:
PublicKey = QG57FCPa2dQwhQvJdrD+HPldTQL4Jn/e0d91PVIU+AE=
Endpoint = 156.67.63.52:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
Issues Identified:
- Peer 2 on the server has
Allowed IPs: (none), which might be unintended.
- The client is set to route all traffic (
0.0.0.0/0) through the VPN, but the server may not be correctly forwarding or masquerading this traffic.
2. Enable IP Forwarding on the Server
IP forwarding allows your server to route packets between interfaces (e.g., from wg0 to eth0). To enable it:
-
Temporary Enablement (until next reboot):
sudo sysctl -w net.ipv4.ip_forward=1
-
Permanent Enablement:
Add the following line to /etc/sysctl.conf:
net.ipv4.ip_forward = 1
Then apply the changes:
sudo sysctl -p
3. Configure Firewall and NAT (Masquerading)
Assuming your server's external network interface is eth0 (replace with the correct interface if different), set up iptables rules to allow forwarding and perform NAT:
-
Allow Forwarding for WireGuard Interface:
sudo iptables -A FORWARD -i wg0 -j ACCEPT
sudo iptables -A FORWARD -o wg0 -j ACCEPT
-
Set Up NAT (Masquerading):
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
-
Persist iptables Rules:
To ensure these rules persist after reboot, consider installing iptables-persistent:
sudo apt-get install iptables-persistent
sudo netfilter-persistent save
Alternatively, you can add the rules to a firewall script that runs on startup.
4. Review WireGuard Peer Configuration
Ensure that the server’s WireGuard configuration (/etc/wireguard/wg0.conf or similar) correctly defines the peers:
-
For the Client Peer:
[Peer]
PublicKey = Mr3u8mqBmQ1vRxGZ871RoO/IpiohZheB7SOyHbGWmT4=
AllowedIPs = 10.0.0.2/32
If you intend for the client to access only the VPN IP (10.0.0.2), this is correct. However, since the client is routing all traffic (0.0.0.0/0) through the VPN, you might need to adjust settings.
-
For Client to Route All Traffic:
The server should know to route traffic back to the client. However, typically, AllowedIPs on the server side for the client remain 10.0.0.2/32 unless you have multiple subnets or advanced routing.
5. Check Client Configuration
Ensure that the client configuration is correct:
[Interface]
PrivateKey = sP7i5iqsgjDV0VEci0iDGVQg6bKavsMKgoTOEvw1ylc=
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = QG57FCPa2dQwhQvJdrD+HPldTQL4Jn/e0d91PVIU+AE=
Endpoint = 156.67.63.52:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
- DNS: Using
1.1.1.1 is fine, but ensure that the client can reach this DNS server through the VPN.
- AllowedIPs:
0.0.0.0/0 routes all traffic through the VPN. This requires the server to handle and forward all this traffic, which we've addressed above.
6. Restart WireGuard Services
After making changes, restart WireGuard on both server and client.
On the Server:
sudo wg-quick down wg0
sudo wg-quick up wg0
On the Client:
Depending on your OS:
7. Verify the Connection
-
Check Handshake Status:
On the server:
sudo wg show
Ensure that the latest handshake is recent.
-
Test Internet Connectivity:
On the client, try pinging an external IP:
ping 8.8.8.8
Then, test DNS resolution:
ping google.com
-
Check Routing Table (Client):
Ensure that the default route (0.0.0.0/0) is via the WireGuard interface.
ip route
8. Additional Troubleshooting Steps
-
Check Server’s External Connectivity:
Ensure the server can access the Internet and that there's no firewall blocking outbound traffic.
-
Firewall on the Server’s External Interface:
If you have additional firewall rules (e.g., ufw, firewalld), ensure they allow forwarding and accept WireGuard traffic.
-
Duplicate Peers:
The second peer on the server with Allowed IPs: (none) might be unnecessary or misconfigured. Verify if this peer should exist. If not, remove or correct it.
Example WireGuard Server Configuration (wg0.conf)
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <Your-Server-Private-Key>
# Add any other configurations as needed
# Peer (Client)
[Peer]
PublicKey = Mr3u8mqBmQ1vRxGZ871RoO/IpiohZheB7SOyHbGWmT4=
AllowedIPs = 10.0.0.2/32
Example WireGuard Client Configuration (wg0.conf)
[Interface]
PrivateKey = sP7i5iqsgjDV0VEci0iDGVQg6bKavsMKgoTOEvw1ylc=
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = QG57FCPa2dQwhQvJdrD+HPldTQL4Jn/e0d91PVIU+AE=
Endpoint = 156.67.63.52:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
Note: Replace <Your-Server-Private-Key> with your actual server private key.
Conclusion
By ensuring that IP forwarding is enabled, properly configuring iptables for NAT, and verifying WireGuard configurations on both the server and client, you should be able to restore Internet connectivity through your VPN. If you continue to experience issues, consider checking system logs (dmesg, /var/log/syslog) for any related error messages or consult WireGuard's official documentation for more detailed guidance.
Disclaimer: Always be cautious when modifying firewall rules and network configurations to avoid inadvertently exposing your server or disrupting connectivity.