{{indexmenu_n>13}} \\
Note | |
The plugin enables IP forwarding on the host by default. So it is not necessary to add any sysctl -w net.ipv4.ip_forward=1 type instruction in the interface.
|
Note | |
It is completely necessary and mandatory that our operator provide us with a public IP address, if we have CG-NAT in our connection we will not be able to access from outside. This is something completely normal, and it is the first thing you should make sure of for it. Of course, if we are opening a port on the router, we have to make 100% sure that our server's firewall is not interfering with the communication. |
Tip: Use templates to automatically generate keys. | |
If you are creating a custom tunnel from scratch and want to avoid creating the keys manually, you can create a tunnel and a client (or several) and use them as templates: Create a tunnel in the Tunnels tab and activate it and create a client in the Clients tab and activate it. In the Tunnels tab, select the tunnel you have created and click the Tunnel Config button. Copy the text to the clipboard and go to the Custom Config tab. Create a new tunnel and paste the text in the dialog box. Save the changes without activating the tunnel. Go to the Clients tab and select the client you have created. Click the Client Config button and copy the text to a text file. This will be the starting point with the keys for your peer. Delete the generated client and tunnel that you used as templates. You are now ready to edit your custom tunnel and activate it. Modifies the range of networks to move away from the networks generated by the plugin. Modify the rest of the parameters according to your needs. |
Note | |
In the procedures section of this document there is a procedure to create a point-to-point tunnel. |
Note | |
The plugin enables IP forwarding on the host by default. So it is not necessary to add any sysctl -w net.ipv4.ip_forward=1 type instruction in the interface.
|
Note | |
Depending on your router settings, the connection may not work if you are connected by Wi-Fi on the same network as the server. You can disable the Wi-Fi connection of the smartphone in this case and connect with data on the smartphone. This way you can test your connection. |
Note | |
Depending on your router settings, the connection may not work if the PC is connected to the same network as the server. If the PC has Wi-Fi, you can share a data connection via Wi-Fi from the smartphone and connect to it from the PC. This way you can test your connection. |
[Interface]
PrivateKey = Uses the previously generated TUNNEL PRIVATE KEY
ListenPort = 51500
Address = 10.15.15.1/32
[Peer]
PublicKey = Uses the previously generated CLIENT PUBLIC KEY
AllowedIPs = 10.15.15.2/32
* You can adapt the //ListenPort// field to your needs. Use a port that is free on your server.
* You can adapt the //Address// field to your needs. Make sure to use ''/32'' for Netmask. This will ensure that the peer will only access the IP of the server.
* Press the **Enable** button to activate the tunnel.
* Press the **Save** button and accept the changes.
\\
== Configuration of the second server (peer 2) ==
* On the second server, go to **Services** > **Custom Config** in the GUI and click **Create**
* Paste the content of the client file you generated on the first server into the window.
* Get rid of the parameters you don't need and keep the keys, so you end up with this configuration:
[Interface]
PrivateKey = Uses the previously generated CLIENT PRIVATE KEY
ListenPort = 51500
Address = 10.15.15.2/32
[Peer]
PublicKey = Use the previously generated TUNNEL PUBLIC KEY
AllowedIPs = 10.15.15.1/32
Endpoint = mydomain.com:51500
PersistentKeepalive = 25
* If you adjusted the values of the first peer, port and subnet, repeat it in this configuration.
* This peer will be the one that makes the connection and will keep it open.
* For this we need to indicate a domain to connect to. You can create one for free by following this procedure: [[omv6:omv6_plugins:wireguard#how_to_set_up_a_free_domain_with_duckdns_fix_dynamic_ip|How to set up a free domain with duckdns fix dynamic ip]]
* We also need to set the //PersistentKeepalive// value. This will send a minimum packet every 25 seconds (or whatever value you choose, 25 is enough) so that the peer 1 knows where to direct their communication if they want to make contact.
* Press the **Enable** button to activate the tunnel.
* Press the **Save** button and accept the changes.
You just need to make sure that the port set is open on both routers and that the domain point set on the peer 2 points to the public IP of the peer 1.
If you are sure of the above, the point-to-point tunnel is established. You can check this in the CLI from the first peer by running ''ping 10.15.15.2'' and from the second peer by running ''ping 10.15.15.1'' or whatever subnet you have set. The response should be something similar to this:
ping 10.15.15.1 (10.15.15.1) 56 (84) bytes of data.
64 bytes from 10.15.15.1: icmp_seq = 1 ttl = 64 time = 30.6 ms
64 bytes from 10.15.15.1: icmp_seq = 2 ttl = 64 time = 30.7 ms
64 bytes from 10.15.15.1: icmp_seq = 3 ttl = 64 time = 29.6 ms
64 bytes from 10.15.15.1: icmp_seq = 4 ttl = 64 time = 28.9 ms
^ C
--- 10.15.15.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 8ms
rtt min / avg / max / mdev = 28.877 / 29.934 / 30.677 / 0.775 ms
If it doesn't work check your domain and check that the ports are open on both routers.
\\
=== Point to point. Variant with two Endpoints, silence in the connection. ===
Wireguard is characterized by being a silent connection. In the above case, only one of the two peers can initiate the connection since the other peer does not have an endpoint. Therefore, to allow the initiation of the connection from both peers, one of them must keep the connection open by sending a packet every so often (PersistentKeepalive).
We can achieve that the tunnel behaves silently when there is no communication and that both peers can initiate the connection, for this we must establish an Endpoint in each of the two peers. Of course to achieve this we must have a domain pointing to each server. We will call them in this case peer1.mydomain.com and peer2.mydomain.com
The previous configuration would look like this:
Peer 1.
[Interface]
PrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ListenPort = 51500
Address = 10.15.15.1/32
[Peer]
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.15.15.2/32
Endpoint = peer2.mydomain.com:51500
Peer 2.
[Interface]
PrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ListenPort = 51500
Address = 10.15.15.2/32
[Peer]
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.15.15.1/32
Endpoint = peer1.mydomain.com:51500
\\
=== Point by point. Firewall configuration using iptables. ===
The above configuration allows the peers to talk to each other on any port. If you need it, you can restrict these communications to one or more ports using iptables as a firewall. This will cause each of the peers to reject any communication outside of what we need to establish.
Suppose we are setting up this tunnel to perform rsync synchronization from a module that supports connections on port 873 (you can customize it). In this case, it would be desirable for each server to only allow connections to that port, denying connections to any other service.
Suppose we have called the interface of each peer pp_peer1 in the plugin GUI. The plugin will end up calling that interface wgnet_pp_peer1. Similarly, in peer 2 the interface will be called wgnet_pp_peer2.
The configuration of the previous section would look like this after applying the iptables rules:
Peer 1.
[Interface]
PrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ListenPort = 51500
Address = 10.15.15.1/32
# Firewall
PreUp = iptables -A INPUT -i wgnet_pp_peer1 -m state --state ESTABLISHED,RELATED -j ACCEPT
PreUp = iptables -A INPUT -i wgnet_pp_peer1 -m state --state NEW -p tcp --dport 873 -j ACCEPT
PreUp = iptables -A INPUT -i wgnet_pp_peer1 -j REJECT
PostDown = iptables -D INPUT -i wgnet_pp_peer1 -m state --state ESTABLISHED,RELATED -j ACCEPT
PostDown = iptables -D INPUT -i wgnet_pp_peer1 -m state --state NEW -p tcp --dport 873 -j ACCEPT
PostDown = iptables -D INPUT -i wgnet_pp_peer1 -j REJECT
[Peer]
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.15.15.2/32
Endpoint = peer2.mydomain.com:51500
Peer 2.
[Interface]
PrivateKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ListenPort = 51500
Address = 10.15.15.2/32
# Firewall
PreUp = iptables -A INPUT -i wgnet_pp_peer2 -m state --state ESTABLISHED,RELATED -j ACCEPT
PreUp = iptables -A INPUT -i wgnet_pp_peer2 -m state --state NEW -p tcp --dport 873 -j ACCEPT
PreUp = iptables -A INPUT -i wgnet_pp_peer2 -j REJECT
PostDown = iptables -D INPUT -i wgnet_pp_peer2 -m state --state ESTABLISHED,RELATED -j ACCEPT
PostDown = iptables -D INPUT -i wgnet_pp_peer2 -m state --state NEW -p tcp --dport 873 -j ACCEPT
PostDown = iptables -D INPUT -i wgnet_pp_peer2 -j REJECT
[Peer]
PublicKey = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AllowedIPs = 10.15.15.1/32
Endpoint = peer1.mydomain.com:51500
Be sure to bring the interface down before making iptables changes and then bring it back up to avoid orphan rules being left active.
If you need to add more than one port to the tunnel, for example ports 80 and 443 on peer1, you can replace the second and fifth lines of iptables with these:
PreUp = iptables -A INPUT -i wgnet_pp_peer1 -m state --state NEW -p tcp -m multiport --dports 80,443 -j ACCEPT
PostDown = iptables -D INPUT -i wgnet_pp_peer1 -m state --state NEW -p tcp -m multiport --dports 80,443 -j ACCEPT
----
===== How to Set up a free domain with duckdns. Fix dynamic IP =====
[[https://www.duckdns.org/|{{ :omv6:omv6_plugins:wireguard10.jpg?direct&200|www.duckdns.org}}]]
If you need a domain there are many ways to get it. One of them is provided by [[https://www.duckdns.org/|duckdns.org]] for free.
If your IP is dynamic, the most usual, it can change at any time. If this happens you will lose the connection because the domain will be forwarded to an IP that is no longer your server's. To solve this duckdns also provides a simple dynamic public IP update system.
=== Get a domain in duckdns ===
* Access the [[https://www.duckdns.org/|duckdns.org]] website and log in.
* At the top you can see the token that has been assigned to your account, this is the identifier for the account you have created.
* You can get up to 5 different domains with one login account. Choose a domain that is available and add it to your account.
* These domains will have the format MY_DOMAIN.duckdns.org where MY_DOMAIN is chosen by you whenever it is available.
=== Dynamic IP update with duckdns on OMV ===
The original instructions can be seen here. [[https://www.duckdns.org/install.jsp|www.duckdns.org/install.jsp]]. The procedure installs a small file that must be executed from time to time. In each execution it sends the current IP and compares it with the one configured in the domain, if it is different it updates it.
Instead we will use the scheduled task execution in the OMV GUI to execute the instruction directly.
To configure it do the following:
* In the OMV GUI go to **System** > **Scheduled Tasks** and press the **Create** button
* You need to have ''curl'' installed on your system. If you do not have it installed you can do it from here. If you already have it installed, skip the following substeps.
* To install ''curl'':
* Type in the **Command** field the ''apt install curl'' command.
* Press the **Save** button
* Select the scheduled task you just created (yellow color)
* Press the **Run** button
* This will have installed the ''curl'' package on the system. Now select the task again and press the **Edit** button. Delete the ''apt install curl'' command you wrote earlier.
* Type the following command in the **Command** field of the dialog box.
echo url="https://www.duckdns.org/update?domains=MY_DOMAIN&token=MY_TOKEN&ip=" | curl -k -o /var/log/duck.log -K -
* Replace ''MY_DOMAIN'' with the subdomain you chose in "''MY_DOMAIN''.duckdns.org".
* Replace ''MY_TOKEN'' with the token that has been assigned to your duckdns account.
* In the **Time of execution** field, choose the Hourly option.
* This will run the command every hour. If your IP changes frequently you can change this to run for shorter periods of time. Every 5 minutes may be reasonable.
* Make sure the **Enabled** option is checked.
* In the **Tags** field you can optionally write a description, for example ''Duckdns_DDNS''.
* Press the **Save** button.
* Run the task once to verify operation. Select the task and press the **Run** button.
* You can check on the duckdns website that your domain has been updated and now points to the public IP of your server.
* Check your public IP in [[https://www.whatismyip.com/|What is my IP]] website. If you have configured everything correctly and it does not match, you are probably behind CGNAT. Check with your internet provider for a solution to this problem.
Note | |
This task will create a log file at /var/log/duck.log. |