Connecting OpenWRT to a WireGuard VPN involves several steps, including installing the WireGuard packages, obtaining the VPN configuration details, and configuring both the WireGuard interface and firewall rules on your OpenWRT router. Here’s a detailed guide to help you set up WireGuard on OpenWRT:
Prerequisites
- An OpenWRT router with internet access.
- A valid WireGuard VPN configuration from your VPN provider.
Step 1: Install WireGuard Packages
-
Log in to OpenWRT:
- Open your web browser and navigate to your router's web interface (typically
192.168.1.1
). - Log in with your username and password.
- Open your web browser and navigate to your router's web interface (typically
-
Update Package Lists:
- Go to
System
>Software
. - Click
Update lists
.
- Go to
-
Install WireGuard Packages:
- In the same
System
>Software
section, use the search bar to find the following packages:wireguard
luci-proto-wireguard
- Install both packages by clicking
Install
next to each package.
- In the same
Step 2: Obtain WireGuard Configuration from Your VPN Provider
-
Log in to Your VPN Provider:
- Access your account on your VPN provider’s website.
-
Generate WireGuard Configuration:
- Navigate to the VPN configuration section and select
WireGuard
as the VPN type. - Download the configuration file or note down the necessary details (Public Key, Private Key, Endpoint, Allowed IPs, and DNS).
- Navigate to the VPN configuration section and select
Step 3: Configure WireGuard Interface on OpenWRT
-
Navigate to Network Interfaces:
- Go to
Network
>Interfaces
.
- Go to
-
Add a New Interface:
- Click
Add new interface
. - Name: Enter a name for the interface (e.g.,
wg0
). - Protocol: Select
WireGuard VPN
.
- Click
-
Configure the Interface:
- Private Key: Enter the private key from your VPN configuration.
- Listen Port: Leave as default or set a specific port if required.
- Addresses: Enter the IP address assigned by your VPN provider (e.g.,
10.0.0.2/24
).
-
Add Peers:
- Click
Add peer
. - Description: Name the peer (e.g.,
VPN Server
). - Public Key: Enter the public key provided by your VPN provider.
- Allowed IPs: Enter
0.0.0.0/0
to route all traffic through the VPN. - Endpoint Host: Enter the VPN server address (e.g.,
vpn.example.com
). - Endpoint Port: Enter the server port (e.g.,
51820
).
- Click
-
Save and Apply:
- Click
Save & Apply
.
- Click
Step 4: Configure Firewall Rules
-
Create a New Firewall Zone:
- Go to
Network
>Firewall
. - Click
Add
to create a new firewall zone. - Name: Enter a name for the zone (e.g.,
wg_zone
). - Input: Accept
- Output: Accept
- Forward: Reject
- Masquerading: Enable
- MSS clamping: Enable
- Go to
-
Assign Interface to Zone:
- In the
Covered networks
section, select thewg0
interface.
- In the
-
Save and Apply:
- Click
Save & Apply
.
- Click
Step 5: Route Traffic Through the VPN
-
Configure Traffic Routing:
- Go to
Network
>Interfaces
. - Edit the
WAN
interface. - In the
Advanced Settings
tab, uncheckUse gateway metric
. - Edit the
wg0
interface. - In the
Advanced Settings
tab, set theUse gateway metric
to a lower value than the WAN interface (e.g.,10
).
- Go to
-
Update Routing Table:
- Go to
Network
>Routing
. - Ensure that the default route is through the WireGuard interface.
- Go to
Step 6: Test the VPN Connection
-
Check Interface Status:
- Go to
Network
>Interfaces
. - Ensure the
wg0
interface is up and running.
- Go to
-
Verify VPN Connection:
- Use an external service like
whatismyip.com
to confirm that your public IP address matches the VPN server.
- Use an external service like
Conclusion
By following these steps, you should have successfully connected your OpenWRT router to a WireGuard VPN. This setup enhances your network security and ensures your traffic is securely routed through the VPN.
If you encounter any issues, refer to your VPN provider’s support documentation or the OpenWRT forums for additional troubleshooting tips.