Skip to content

Commit dfe1264

Browse files
authored
feat: wireguard ui configuration added (#212)
* feat: wireguard ui configuration added * suggestions
1 parent 43cc5eb commit dfe1264

2 files changed

Lines changed: 52 additions & 202 deletions

File tree

index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ NethSecurity administrator manual
8888
openvpn_roadwarrior
8989
openvpn_tunnels
9090
ipsec_tunnels
91+
wireguard
9192

9293
.. toctree::
9394
:maxdepth: 2
@@ -113,7 +114,6 @@ NethSecurity administrator manual
113114
snmp
114115
custom_openvpn_tunnel
115116
logs
116-
wireguard
117117
speedtest
118118
ups
119119
wol

wireguard.rst

Lines changed: 51 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It is designed to be faster, simpler, and more functional than IPsec and OpenVPN
77
and easy-to-configure VPN solution that uses cutting-edge cryptography.
88
It is designed to be simpler to configure than OpenVPN and to offer a lower attack surface.
99

10-
NethSecurity provides a WireGuard server and client that can be configured from the command line interface.
10+
NethSecurity provides a WireGuard server and client that can be configured from the web interface.
1111

1212
Features:
1313

@@ -19,230 +19,80 @@ Features:
1919
- Enhanced security with optional pre-shared keys
2020
- Standard WireGuard configuration file import capability
2121

22-
Current limitations:
22+
Server Configuration
23+
====================
2324

24-
- Supported networks are restricted to /24 subnet masks
25-
- Peer IP addresses are fixed and cannot be modified after creation
26-
- WireGuard interfaces appear as "unknown interface" in the Network page
25+
It's possible to create multiple WireGuard server instances, each with its own isolated network zone. NethSecurity will automatically open the necessary firewall ports
26+
to allow incoming connections to the WireGuard server and create a VPN zone to allow management of how the traffic is routed between zones.
2727

28-
Quickstart
29-
==========
28+
On the contrary of the OpenVPN server, there's no ties to the users database, accounts (peers) are created and managed directly inside the WireGuard interface.
3029

31-
The configuration is composed by the following steps:
30+
To create a WireGuard server, click on :guilabel:`Add server`, then fill the form with the desired configuration. The fields are the following:
3231

33-
1. Get good defaults to avoid conflicts with existing configurations
34-
2. Create the server instance
35-
3. Add a new account (peer)
32+
- `Status`: enable or disable the WireGuard server instance
33+
- `Name`: the name of the WireGuard server instance, this is not the name of the network interface, it will be automatically created as `wgX`, where `X` is a number
34+
- `VPN network`: the network CIDR that will be used by the WireGuard server, the server will automatically get the first IP of the network. Make sure this network does not overlap with any existing one
35+
- `UDP port`: the port on which the WireGuard server listens for incoming connections
36+
- `Public endpoint`: the public IP address or FQDN of the server
3637

37-
The following examples use the ``ns.wireguard`` API to configure the WireGuard server and peers.
38+
Under advanced settings, it's possible to configure additional options:
3839

39-
Get good defaults
40-
-----------------
40+
- `MTU`: to manually set the MTU of the WireGuard interface
41+
- `DNS servers`: to set custom DNS servers that will be pushed to the clients, useful to avoid DNS leaks
4142

42-
Before creating an instance, retrieve some valid defaults. Use the calculated defaults to create the instance:
43+
After creating the server, it's possible to add new clients (peers) directly from the WireGuard interface, click :guilabel:`Add peer` and fill the form as the following:
4344

44-
.. code-block:: bash
45-
46-
/usr/libexec/rpcd/ns.wireguard call get-instance-defaults
47-
48-
Response example:
49-
50-
.. code-block:: json
51-
52-
{
53-
"listen_port": 51820,
54-
"instance": "wg1",
55-
"network": "10.98.95.0/24",
56-
"routes": ["192.168.100.0/24"],
57-
"public_endpoint": "1.2.3.4"
58-
}
59-
60-
The response contains the following fields:
61-
62-
- ``listen_port``: the port on which the WireGuard server listens for incoming connections, a firewall rule will be automatically created
63-
to accept the traffic on this port
64-
- ``instance``: the name of the WireGuard server instance, this is also the name of the network interface
65-
- ``network``: the network CIDR that will be used by the WireGuard server, the server will automatically get the first IP of the network
66-
- ``routes``: a list of network CIDR that will be pushed to the clients
67-
- ``public_endpoint``: the public IP address of the server, this is used to create the firewall rule to accept the traffic on the WireGuard port;
68-
the command will try to automatically detect the public IP address
69-
70-
Before creating the instance, verify that the calculated defaults are correct:
71-
72-
- verify the public IP address, use a custom value if the automatic detection fails; a FQDN is supported too
73-
- verify the network field does not overlap with existing networks
74-
75-
Create an instance
76-
------------------
77-
78-
Create the WireGuard server instance using the calculated defaults:
79-
80-
.. code-block:: bash
81-
82-
echo '{"listen_port": 51820, "name": "wg1", "instance": "wg1", "enabled": true, "network": "10.98.95.0/24", "routes": ["192.168.100.0/24"], "public_endpoint": "1.2.3.4", "dns": [], "user_db": ""}' | /usr/libexec/rpcd/ns.wireguard call set-instance
83-
84-
The server will automatically get the first IP of the `network`, in this case `10.98.95.1`.
85-
86-
Response example:
87-
88-
.. code-block:: json
89-
90-
{"public_key": "dTQ5v0lJU1mwR3uRMXL+b6lEx7tZxmoIUcDdoTYzClE="}
91-
92-
This is the public key of the server, it is used to create the client configuration.
93-
94-
Save and apply:
95-
96-
.. code-block:: bash
97-
98-
uci commit network && uci commit firewall
99-
reload_config
100-
ifdown wg1; ifup wg1
101-
102-
You can use the same API to change the configuration of the server instance.
103-
104-
Add a new account (peer)
105-
------------------------
106-
107-
Create a new account, ensuring the ``account`` field is unique within the same instance:
108-
109-
.. code-block:: bash
110-
111-
echo '{"enabled": true, "instance": "wg1", "account": "user1", "route_all_traffic": false, "client_to_client": false, "ns_routes": [], "preshared_key": true}' | /usr/libexec/rpcd/ns.wireguard call set-peer
112-
113-
Options:
114-
115-
- ``route_all_traffic``: if set to ``true``, when the client connects, it will send all the traffic to the server.
116-
This is useful for ensuring all client traffic is encrypted and routed through the VPN. This flag should be set only if the client
117-
must access the internet through the VPN.
118-
- ``client_to_client``: if set to ``true``, the client will be able to communicate with all other peers and not only with the server.
119-
This is useful for enabling communication between clients in a mesh network configuration.
120-
- ``preshared_key``: if set to ``true``, automatically create a pre-shared key that will be used in the peer downloaded configuration.
121-
This adds an additional layer of security by requiring a shared secret for communication.
122-
- ``ns_routes``: a list of network CIDR, automatically routes the networks to this peer;
123-
this is used for site-to-site (net2net) connections, allowing the server to access multiple remote networks through the VPN.
124-
125-
Save and apply:
126-
127-
.. code-block:: bash
128-
129-
uci commit network
130-
reload_config
131-
ifdown wg1; ifup wg1
132-
133-
134-
Download the account configuration
135-
----------------------------------
136-
137-
The account configuration can be downloaded both in text format or a QR code and is suitable to be imported in a WireGuard client.
138-
139-
Download the text format if you want to configure a Linux machine or another NethSecurity:
140-
141-
.. code-block:: bash
142-
143-
echo '{"instance": "wg1", "account": "user1"}' | /usr/libexec/rpcd/ns.wireguard call download-peer-config | jq -r .config
45+
- `Status`: enable or disable the peer
46+
- `Name`: the name of the peer
47+
- `Reserved IP`: the static IP address that will be assigned to the peer, must be inside the VPN network, it will be pre-filled with the next available IP
48+
- `Pre-shared key`: if enabled, a pre-shared key will be automatically created to enhance security
49+
- `Route all traffic`: if enabled, when the client connects, it will send all the traffic to the server
50+
- `Server networks`: which networks the peer can access, all LAN networks will be automatically added
51+
- `Peer networks`: networks reachable on the peer side. Always fill this field when you want to create a net2net tunnel
14452

145-
Output example: ::
53+
.. note::
14654

147-
# Account: user1 for wg1
148-
[Interface]
149-
PrivateKey = iGn1xg3pENbVCJpJWf4EqOYtNu7HZj1dg5iIX9AU0FY=
150-
Address = 10.98.95.2
151-
# Custom DNS disabled
55+
It's possible to create a client-to-site (Road Warrior) connection by leaving empty the `Peer networks` entries. This will allow the client to access the server networks.
15256

153-
[Peer]
154-
PublicKey = dTQ5v0lJU1mwR3uRMXL+b6lEx7tZxmoIUcDdoTYzClE=
155-
PreSharedKey = N37bSeSO1Erzow9wVHqtkyY03TJ5D8uOrewg9iFB9MU=
156-
AllowedIPs = 192.168.100.0/24,10.98.95.1
157-
Endpoint = 1.2.3.4:51820
158-
PersistentKeepalive = 25
57+
Once the peer is saved, it's possible to download the configuration file in text format or as a QR code using the menu on the right side of the peer entry.
15958

59+
The server and peers configuration can be edited by the context menu on the right side of each entry.
16060

161-
Configure a mobile device
162-
~~~~~~~~~~~~~~~~~~~~~~~~~
61+
.. warning::
16362

164-
Many mobile WireGuard clients allows to import the configuration using a QR code:
63+
After modifying the WireGuard server or peers, remember that such changes needs to be applied to the peer by re-downloading the configuration file.
16564

166-
- `iOS <https://apps.apple.com/it/app/wireguard/id1441195209>`_
167-
- `Android <https://play.google.com/store/apps/details?id=com.wireguard.android&hl=it&pli=1>`_
65+
Tunnel Configuration
66+
====================
16867

169-
Once the app is installed, open it and import the configuration using the QR code:
68+
Nethsecurity can be configured as a WireGuard client (peer) to connect to another WireGuard server. On the :guilabel:`Peer tunnels` tab, it's possible to add manually a new tunnel by clicking on :guilabel:`Add peer tunnel` or import a generic wireguard configuration file using :guilabel:`Import peer tunnel`.
17069

171-
.. code-block:: bash
172-
173-
echo '{"instance": "wg1", "account": "user1"}' | /usr/libexec/rpcd/ns.wireguard call download-peer-config | jq -r .qrcode | base64 -d
174-
175-
Import the configuration to another NethSecurity
176-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177-
178-
When importing the configuration to another NethSecurity, the file must be base64 encoded.
179-
Print the configuration file in base64 to the console:
180-
181-
.. code-block:: bash
182-
183-
echo '{"instance": "wg1", "account": "user1"}' | /usr/libexec/rpcd/ns.wireguard call download-peer-config | jq -r .config | base64 -w0; echo
184-
185-
Copy the base64 string, than go the the other NethSecurity and execute:
186-
187-
.. code-block:: bash
188-
189-
echo '{"config": "IyBBY2NvdW50Oi..."}' | /usr/libexec/rpcd/ns.wireguard call import-configuration
190-
191-
Save and apply:
192-
193-
.. code-block:: bash
194-
195-
uci commit network && uci commit firewall
196-
reload_config
197-
ifdown wg1; ifup wg1
198-
199-
Remove an instance
200-
==================
201-
202-
To remove an instance, use the following command:
203-
204-
.. code-block:: bash
205-
206-
echo '{"instance": "wg1"}' | /usr/libexec/rpcd/ns.wireguard call remove-instance
70+
When manually adding a new tunnel, the following fields are available:
20771

208-
This command will remove:
209-
210-
- The WireGuard server instance
211-
- The firewall rules that allow traffic from the WAN
212-
- The VPN zone
213-
- All associated accounts
214-
215-
Save and apply the changes:
216-
217-
.. code-block:: bash
218-
219-
uci commit network && uci commit firewall
220-
reload_config
221-
222-
Remove a peer
223-
=============
224-
225-
To remove a peer use:
226-
227-
.. code-block:: bash
228-
229-
echo '{"instance": "wg1", "account": "user1"}' | /usr/libexec/rpcd/ns.wireguard call remove-peer
230-
231-
The command will remove the peer and its configuration inside the users database, if present.
232-
233-
Save and apply:
234-
235-
.. code-block:: bash
236-
237-
uci commit network && uci commit users
238-
reload_config
72+
- `Status`: enable or disable the tunnel
73+
- `Name`: the name of the tunnel, this is not the name of the network interface, it will be automatically created as `wgX`, where `X` is a number
74+
- `Reserved IP`: the static IP address that the tunnel will use
75+
- `Server public key`: the public key of the WireGuard server
76+
- `Peer private key`: the private key of the tunnel
77+
- `Pre-shared key`: the pre-shared key, if used, field is optional
78+
- `Route all traffic`: if enabled, all the traffic will be routed through the tunnel
79+
- `Network routes`: networks made available through the tunnel
80+
- `Endpoint`: the public IP address or FQDN of the WireGuard server
81+
- `UDP port`: the port on which the WireGuard tunnel will connect to
82+
- `DNS servers`: custom DNS servers to be used when the tunnel is active
23983

24084
Debug
24185
=====
24286

24387
By default, WireGuard does not log anything.
244-
To enable logging on `/var/log/messages`, use the following:
88+
To enable logging on `/var/log/messages`, use the following commands:
24589

24690
.. code-block:: bash
24791
24892
echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
93+
94+
To disable logging, use:
95+
96+
.. code-block:: bash
97+
98+
echo module wireguard -p > /sys/kernel/debug/dynamic_debug/control

0 commit comments

Comments
 (0)