<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>WireGuard on KTDEVX</title><link>/en/tags/wireguard/</link><description>KTDEVX (WireGuard)</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>ktdevx@gmail.com
(Kaito Takemura)</managingEditor><lastBuildDate>Sat, 03 May 2025 19:26:18 +0900</lastBuildDate><atom:link href="/en/tags/wireguard/index.xml" rel="self" type="application/rss+xml"/><item><title>Build a VPN Server on OpenWrt with WireGuard for Remote Access to Your Home Network</title><link>/en/blog/set-up-a-vpn-server-on-openwrt-using-wireguard-to-access-the-home-network-from-outside/</link><pubDate>Sat, 03 May 2025 19:26:18 +0900</pubDate><author>ktdevx@gmail.com (Kaito Takemura)</author><guid>/en/blog/set-up-a-vpn-server-on-openwrt-using-wireguard-to-access-the-home-network-from-outside/</guid><description>&lt;p>This article explains how to build a VPN server using WireGuard on a router running OpenWrt and securely access your home network while away from home.&lt;/p>
&lt;p>WireGuard is a lightweight, fast, and secure VPN protocol that makes it easy to build a VPN environment at home.&lt;/p>
&lt;h2 id="install-the-package" >
&lt;div>
&lt;a href="#install-the-package">
#
&lt;/a>
Install the Package
&lt;/div>
&lt;/h2>
&lt;p>Log in to the OpenWrt web management interface (LuCI) and install &lt;code>luci-proto-wireguard&lt;/code>. This also installs required packages such as &lt;code>wireguard-tools&lt;/code>.&lt;/p>
&lt;p>Restart the router after the installation is complete.&lt;/p>
&lt;h2 id="add-a-network-interface" >
&lt;div>
&lt;a href="#add-a-network-interface">
#
&lt;/a>
Add a Network Interface
&lt;/div>
&lt;/h2>
&lt;p>In LuCI, go to Network &amp;gt; Interfaces and select Create a new interface&amp;hellip; Create an interface with the following settings.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Setting&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Name&lt;/td>
&lt;td>&lt;!-- raw HTML omitted -->&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Protocol&lt;/td>
&lt;td>WireGuard VPN&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Choose an easy-to-understand name such as &lt;code>vpn&lt;/code> or &lt;code>wg&lt;/code>. In this example, &lt;code>vpn&lt;/code> is used.&lt;/p>
&lt;p>Next, configure the following settings on the General Settings tab.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Setting&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Listen Port&lt;/td>
&lt;td>51820&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>IP Addresses&lt;/td>
&lt;td>&lt;!-- raw HTML omitted -->&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Unless you have a specific reason, choose an IP address that does not overlap with an existing network segment. In this example, &lt;code>10.0.0.1&lt;/code> is used.&lt;/p>
&lt;p>Finally, select Generate new key pair to generate the server&amp;rsquo;s private and public keys.&lt;/p>
&lt;p>After configuring the settings, select Save.&lt;/p>
&lt;h2 id="configure-the-firewall" >
&lt;div>
&lt;a href="#configure-the-firewall">
#
&lt;/a>
Configure the Firewall
&lt;/div>
&lt;/h2>
&lt;p>In LuCI, go to Network &amp;gt; Firewall and configure the zones on the General Settings tab.&lt;/p>
&lt;p>To apply the same settings as the &lt;code>lan&lt;/code> interface, edit the &lt;code>lan&lt;/code> zone and add the &lt;code>vpn&lt;/code> interface to Covered networks.&lt;/p>
&lt;p>Next, open the Traffic Rules tab and add a rule to allow WireGuard connections. Communication from the &lt;code>wan&lt;/code> side is disabled by default, so allow communication from &lt;code>wan&lt;/code> to the VPN server (OpenWrt).&lt;/p>
&lt;p>Select Add and create a rule with the following settings.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Setting&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Name&lt;/td>
&lt;td>Allow-WireGuard&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Protocol&lt;/td>
&lt;td>UDP&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Source zone&lt;/td>
&lt;td>wan&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Destination zone&lt;/td>
&lt;td>Device (input)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Destination port&lt;/td>
&lt;td>51820&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>After configuring the rule, select Save &amp;amp; Apply.&lt;/p>
&lt;h2 id="add-a-peer" >
&lt;div>
&lt;a href="#add-a-peer">
#
&lt;/a>
Add a Peer
&lt;/div>
&lt;/h2>
&lt;p>Add information for the client (peer) that is allowed to connect to the VPN server.&lt;/p>
&lt;p>In this example, the client&amp;rsquo;s key pair is generated on the server and the configuration file is shared with the client. Be aware that this temporarily stores the client&amp;rsquo;s private key on the server.&lt;/p>
&lt;p>In LuCI, go to Network &amp;gt; Interfaces and edit the &lt;code>vpn&lt;/code> interface created earlier. Open the Peers tab and select Add peer.&lt;/p>
&lt;p>When the peer settings screen opens, configure it as follows.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Setting&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Description&lt;/td>
&lt;td>&lt;!-- raw HTML omitted -->&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Allowed IPs&lt;/td>
&lt;td>&lt;!-- raw HTML omitted -->&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Route Allowed IPs&lt;/td>
&lt;td>Enabled&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Persistent Keep Alive&lt;/td>
&lt;td>25&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Give Description a name that identifies the peer. Under Allowed IPs, specify the IP addresses that the peer is allowed to use.&lt;/p>
&lt;p>Normally, one peer is created for each public key, so this does not require much consideration. However, the Allowed IPs setting applies subnet masks as follows.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Allowed IPs&lt;/th>
&lt;th>Addresses the peer may use&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>10.0.0.2&lt;/td>
&lt;td>10.0.0.2&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>10.0.0.2/32&lt;/td>
&lt;td>Same as above&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>10.0.0.0/24&lt;/td>
&lt;td>10.0.0.0 to 10.0.0.255&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>10.0.0.2/24&lt;/td>
&lt;td>Same as above&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>In this example, &lt;code>10.0.0.2&lt;/code> is used.&lt;/p>
&lt;p>After configuring the settings, select Generate new key pair and Generate preshared key to generate the keys.&lt;/p>
&lt;p>At this point, Generate configuration&amp;hellip; under Configuration Export becomes available. Select it.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>Setting&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Connection endpoint&lt;/td>
&lt;td>&amp;lt;VPN-server-IP-address/domain-name&amp;gt;&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Allowed IPs&lt;/td>
&lt;td>&lt;!-- raw HTML omitted -->&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>For Connection endpoint, specify the VPN server&amp;rsquo;s IP address or domain name. Since the VPN server is running on OpenWrt in this example, the IP address assigned by the ISP to &lt;code>wan&lt;/code> is used.&lt;/p>
&lt;p>For Allowed IPs, specify the IP addresses that should use the VPN. By default, &lt;code>0.0.0.0/0&lt;/code> and &lt;code>::/0&lt;/code> are specified, which routes all traffic through the VPN. Change Allowed IPs as needed.&lt;/p>
&lt;p>A QR code and the client configuration are displayed near the bottom of the settings screen. The client can easily apply the configuration by importing these.&lt;/p>
&lt;p>After applying the configuration on the client, the client&amp;rsquo;s private key is no longer needed on the server. Delete it and save the peer settings.&lt;/p>
&lt;p>Select Save &amp;amp; Apply to apply the settings, then restart the &lt;code>vpn&lt;/code> interface as well.&lt;/p>
&lt;h2 id="connect-from-the-client" >
&lt;div>
&lt;a href="#connect-from-the-client">
#
&lt;/a>
Connect from the Client
&lt;/div>
&lt;/h2>
&lt;p>Connect to the VPN server from Android. Write the configuration displayed earlier to a file such as &lt;code>wg.conf&lt;/code> and send it to the client.&lt;/p>
&lt;p>Search for WireGuard in the Play Store and install the app.&lt;/p>
&lt;figure>&lt;img src="https://www.ktdevx.com/ja/blog/set-up-a-vpn-server-on-openwrt-using-wireguard-to-access-the-home-network-from-outside/images/android-01.webp"
alt="WireGuard in the Play Store" width="375">
&lt;/figure>
&lt;p>Open the installed app.&lt;/p>
&lt;figure>&lt;img src="https://www.ktdevx.com/ja/blog/set-up-a-vpn-server-on-openwrt-using-wireguard-to-access-the-home-network-from-outside/images/android-02.webp"
alt="WireGuard Android app" width="375">
&lt;/figure>
&lt;p>Select the plus icon in the lower-right corner, then select Import from file or archive. Select and import the configuration file downloaded from the server.&lt;/p>
&lt;figure>&lt;img src="https://www.ktdevx.com/ja/blog/set-up-a-vpn-server-on-openwrt-using-wireguard-to-access-the-home-network-from-outside/images/android-03.webp"
alt="WireGuard Android app" width="375">
&lt;/figure>
&lt;p>The configuration has been added. The VPN is disabled immediately after adding it. Select the switch on the right to enable the VPN.&lt;/p>
&lt;p>After enabling it, use the SMB client app Network Browser to access the home file server and verify the connection.&lt;/p>
&lt;figure>&lt;img src="https://www.ktdevx.com/ja/blog/set-up-a-vpn-server-on-openwrt-using-wireguard-to-access-the-home-network-from-outside/images/android-04.webp"
alt="WireGuard Android app" width="375">
&lt;/figure>
&lt;p>The connection works successfully. The VPN server setup is complete.&lt;/p></description></item></channel></rss>