-
Star
(374)
You must be signed in to star a gist -
Fork
(81)
You must be signed in to fork a gist
-
-
Save chrisswanda/88ade75fc463dcf964c6411d1e9b20f4 to your computer and use it in GitHub Desktop.
Install WireGuard via whatever package manager you use. For me, I use apt. | |
$ sudo add-apt-repository ppa:wireguard/wireguard | |
$ sudo apt-get update | |
$ sudo apt-get install wireguard | |
MacOS | |
$ brew install wireguard-tools | |
Generate key your key pairs. The key pairs are just that, key pairs. They can be | |
generated on any device, as long as you keep the private key on the source and | |
place the public on the destination. | |
$ wg genkey | tee privatekey | wg pubkey > publickey | |
example privatekey - mNb7OIIXTdgW4khM7OFlzJ+UPs7lmcWHV7xjPgakMkQ= | |
example publickey - 0qRWfQ2ihXSgzUbmHXQ70xOxDd7sZlgjqGSPA9PFuHg= | |
One can also generate a preshared key to add an additional layer of symmetric-key cryptography to be mixed into the already existing public-key cryptography, for post-quantum resistance. | |
# wg genpsk > preshared | |
Take the above private key, and place it in the server. And conversely, put the | |
public key on the peer. Generate a second key pair, and do the opposite, put the | |
public on the server and the private on the peer. Put the preshared key in the client config if you choose to use it. | |
On the server, create a conf file - /etc/wireguard/wg0.conf (These are examples, | |
so use whatever IP ranges and CIDR blocks that will work for your network. | |
################################ | |
[Interface] | |
Address = 10.0.0.1/24 | |
DNS = 1.1.1.1 | |
PrivateKey = [ServerPrivateKey] | |
ListenPort = 51820 | |
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o enp9s0 -j MASQUERADE | |
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o enp9s0 -j MASQUERADE | |
[Peer] | |
#Peer #1 | |
PublicKey = [Peer#1PublicKey] | |
AllowedIPs = 10.0.0.3/32 | |
[Peer] | |
#Peer #2 | |
PublicKey = [Peer#2PublicKey] | |
AllowedIPs = 10.0.0.10/32 | |
[Peer] | |
#Peer #3 | |
PublicKey = [Peer#3PublicKey] | |
AllowedIPs = 10.0.0.2/32 | |
[Peer] | |
#Peer #4 | |
PublicKey = [Peer#4PublicKey] | |
AllowedIPs = 10.0.0.11/32 | |
################################## | |
On each client, define a /etc/wireguard/mobile_user.conf - | |
################################### | |
[Interface] | |
Address = 10.0.0.3/24 | |
PrivateKey = [PrivateKeyPeer#1] | |
[Peer] | |
PublicKey = [ServerPublicKey] | |
PresharedKey = [PresharedKey] | |
Endpoint = some.domain.com:51820 | |
AllowedIPs = 0.0.0.0/0, ::/0 | |
# if you want to do split tunnel, add your allowed IPs | |
# for example if your home network is 192.168.1.0/24 | |
# AllowedIPs = 192.168.1.0/24 | |
# This is for if you're behind a NAT and | |
# want the connection to be kept alive. | |
PersistentKeepalive = 25 | |
######################################## | |
sudo wg show | |
######################################### | |
peer: Peer #1 | |
endpoint: 192.168.2.1:50074 | |
allowed ips: 10.0.0.2/32 | |
latest handshake: 4 minutes, 16 seconds ago | |
transfer: 57.58 KiB received, 113.32 KiB sent | |
peer: Peer #2 | |
endpoint: 99.203.28.43:36770 | |
allowed ips: 10.0.0.10/32 | |
latest handshake: 5 minutes, 30 seconds ago | |
transfer: 92.98 KiB received, 495.89 KiB sent | |
################################################## | |
Start/stop interface | |
wg-quick up wg0 | |
wg-quick down wg0 | |
Start/stop service | |
$ sudo systemctl stop [email protected] | |
$ sudo systemctl start [email protected] | |
Instead of having to modify the file for every client you want to add to the | |
server you could also use the wg tool instead: | |
# add peer | |
wg set wg0 peer <client_pubkey> allowed-ips 10.0.0.x/32 | |
# verify connection | |
wg | |
# save to config | |
wg-quick save wg0 | |
######### EDIT ############## | |
I was setting up a relative with a Wireguard config, and figured I might as well use qrencode to do it since I have it installed on my local machine. | |
qrencode -t ansiutf8 < /etc/wireguard/mobile_user.conf | |
█████████████████████████████████████████████████████████████████████████████ | |
█████████████████████████████████████████████████████████████████████████████ | |
████ ▄▄▄▄▄ █▄▀████▀▀█ ▄▀▀▀▄▄ ▄▄▄▄▄▀ █ ██▀█ ▄▀▀██▄ ▄ ▀█▀▄█ ▄▄ ▀▄▄▄█ ▄▄▄▄▄ ████ | |
████ █ █ █ ▀▀█▀█▄▄▄ █▀██▄ ▄▀ ▀ ▄▀▄█▄▄ ▄█▀▀█▄▄ ▄█ ▄ █ ▄█▄█▀█ █ █ ████ | |
████ █▄▄▄█ █▄▄█▄ ▀█ ▀▄█████ ▀ ▄▄▀▄ █ ▄▄▄ █▄▄▀▀▀▀▀▀██▄ █▄ ▀ ▀ █▄█ █▄▄▄█ ████ | |
████▄▄▄▄▄▄▄█▄█ █▄▀▄▀ █▄█▄█ ▀ ▀▄▀ ▀ ▀ █▄█ █▄█ █▄█▄█▄▀ █▄▀ █▄▀ █▄▀▄█▄▄▄▄▄▄▄████ | |
████▄▄ ▀▀▄▀ ▄ ██▄ █▀▄▄▀█▄▀ ▄▀▄▀██ ▄ ▄ ▀ █ ██▀ █▀▄▀▄▄ ▀ ▄ █ █▀▄▄ ▀ ████ | |
████▀▄ ▀█▀▄▀█ █ ▀██▄█ █▀▄█▀ ▄▄█▄▀ ▀▄█ ▀▀ ▀▄▀▄▀██▄ ▀██▀▄▀█▀█ █ ▄█ ▄██▀████ | |
█████ ▄▄▀ ▄ ██▀█▀▄ ▄▄█ ▀ ▄ █ ▀██ ▀▄█ █ ▄▄█▄█ ▀▀ ███ █▀▄▀▄ █ ▄█ ▄█▀ █ ▀█ ████ | |
████▀█ ▄ ▄▀▄▀ ▄████▄▄█▄█ █▀█▀ ▀▀█▄█ ▄▀ ▄█▀█▄▀ █▀▄ █▀▄▀ ▄█▄█ ██ █▄▀▀ ▀ ████ | |
████ ▀█ ▄▀▄█▄▄▀ ▀█ ▄█▄█ █▄ █ ▄ ▄ ▀▀█▄▀ ▀▄█ █ ▀ ▀▀ █▀██▄█▄▀ ▄█▄█ ▀▄▄▀▄████ | |
████▄ ▄█ ▀▄▀▄▄▄ █▀ ▄▀█▀▀▄▀█ █▀▄▄▀ ▄█▀ ██ █▀ ▄ ▄▀███▀██▀▀ █▀▄▄ ▄█ █▄█ █████ | |
████▀ ▄ ▄▀▄▄▀▀ ▄ ███▀▀▀█ ▀▄▄█▄▀█▀█▀█ ▄█ ▄█▄█▄█▄█▀▀█▄▀▄█ █ ▀▀▄██ █ ▀▀▄▄ ▄████ | |
████▀▄ ▄█▀▄▀██ █▀ ▄ ▀█▄ ▀▄ █▀ ▄▀▀█ ▄ ▄ ▀▀▀▄▀▀ ▄▄▄▄▀▀▄▀▄████▄█▄ ▄▀▀█▄█ ████ | |
█████ ▀▄▄▀▄ ▄█▄▀█▀ ▀ ██ ▄█ ▄█ ▀▄█▀▄▄ ▀███▄█▀ ██ ▄█ ▄ ▀▀▄▄█▀▀ ██▄▀ █▀▀█████ | |
████ ▀▄█ ▄▀▄ ▀▄ ▀ █▀▄▀█ █ █▀ ██ █ ▄ █▄▄██▀▄▀▀ ▄▀█▄ █▄▄▀ ▀▀▄▀▀██▀ ██▀▀████ | |
█████▄▄█▄█▄▀█▀▀▄▄ ▀▄▀ ▄▀▄▄██▀▀▀▀██▄█▄▄▀ ▄█▄▄█▄▄ █ ▀█▄▀█▀▀▄███▄ ▄ ▀ ▀ ████ | |
█████ ▄ ▀▄▄ ▄▀█▄▄▄█▀█▄▄▄ ▀▀█▄▀█▄█▄█ ▄█▀▄█▀▄█ ██▀▄ ▄ ▄▄▄▀▀███▀█▄█ ▄▀██▀█████ | |
████▄███ ▄▄▄ ▀▄▄▄▄▀▀▄▀▀██▀ █▄ ▀█▀█ ▄▄▄ ▀▀▄▀ █ ▄▀▄ █▀▄▄▀ ▀▄▄▄ ▄▄▄ ▄▄ █████ | |
████▄ █▀ █▄█ █▀▄ ▀▄ ▄ ▄ ▀█▄█▀█ ▀▀█ █▄█ ▀█▀ ▄████▀▄█ ▄▀▄ ██▄▄▄ █▄█ ▀▄▄▄████ | |
████ ▄▄ ▄▄▄▄█ █ ▀▀█▄▄▄ █▄ ▄ █▀▀▀ ██▀▄▄▄▀██▀ ▄▄ ▄▀██▄▄▄ ▄▀ █████ | |
████▀█▀▀▄ ▄▀▀▄ ▄▀ ▀▀ ▀▄ █▀▄█ ▀ █▀▄▀▄▀▀█▄▀ ▄▄▀▀ ▀▀██ ▀▄▄▀▄▀▀▄ ▄▀███▄ ▄▄████ | |
█████▀ ▀ ▄ █▀▀ ██ ▄▀▀▀▀▄█▀█▀ █ ▀█▄ ▀█▄ █▀███ █▄ ▄▀▀▄██▄▄ ▄▄█▀▄ ▄ ████ | |
███████▄ ▄▄▄ ▀▄▄ ▀ ████▄ ▀█▀▀▀█▄▀ ▀ ▄█ ▀ ▄█▀▄ █▀▀▀▄▄▀▀ ▄█▄ ██▀ ▀ █████ | |
██████ ▄▄▄▀ █▀ ▀▀ ▄ ▀ █ ▀ ███ ▄▄ ▄▀ ███▄▀ ▄ ▄▀ ▄███▄█▄▀▀▄█ ▄▀ ▀████ | |
████ ▄█▀▀▀▄▀▀ ▀█ ▀▄ █ █▀▄▄▄█▀▄ ▀ █▄▄█▄ ▄▄▀█ ▀ █▀▄▀ ██▀▄█▀▀█ ▄▀▄█▄ █▄ ████ | |
████▀███▀▀▄▀ ▀ █ ▄▀▄█ █▀██▀▀▄▀██ ▀▀▄▀█ ▀ ▀ ▄ ▀ ▀▄█▀█▄█ ▄▀ █▀▄ ██▄█▀▀▀ ████ | |
████▄ ▄▄▄▀▄▀▄ █▄ █▀ ▄▀▄ █▄▄▀ ▄▀█▄▀█▀▀ █▀ █ █▄▄ ▀▀ █▄▄▀█ █▀ ▀ ▀▀▄ ▄ ▄█████ | |
████ ▄▀█ █▄▀▄▀▄ ▄▄▄▀▄▄▀ █▀ ▄█▀▄█▄▄█ ▄▀▄ █▀█▀▀█▀█▀█ ▀ ▀▀▄█▀▄▄ ▄▄█▀ █▄█ ████ | |
████▀ █ ▀█▄▄█▄▀▄ █▄▄ █▀█▄█ ▀█▄▄▀▀█ ▄▀▀▄▄▄▄▀█▄▄▀█ ▀█▄ ▄ ▀█▄▀█▄█▀▄▄ ▄█▀████ | |
████ ▄ ▄ ▄█▀▀▀▄ ███ █▄▄█ █▄▀██▀▄████▄█▄██▄█▀▀▄ █▄▀ █▀▄█▀█ ▄█▄█▀ ▀██▄▀████ | |
████ █▄█▄▄▄▄ ▄▄███▀▄▄█ ▄▀▄▄█ ▄█ ▀▄▄▀▄█▀▀█▀▄▄▄█▀█▀ ▀ █▀ ▄▀▀ ▀ █▀ ▄ ▄ ▄ ████ | |
████▄██▄▄█▄▄ ▄▄ █▀▄█▄█ ██ ▄▀█████▀▀ ▄▄▄ ▄▀▄█▀▀ ▀█▀▀▄█▄ ▄▄ █ █▄▀ ▄▄▄ ▄▄█▄████ | |
████ ▄▄▄▄▄ ██ █▄▄▀▄ █▀▀▄▄█▄ ▄▄▀ ▀▀██ █▄█ ▀██ ▄▀▄█▀ ████▀▄██▄█▀█▄ █▄█ ▀▄▀████ | |
████ █ █ █▀▀▄█ ▄▄█ █ ▄▄█▄ ██▄▄▀▀█▄▄▄ █▄▄▀█▄█▄▄▄ ▀ ▀ ▀▀▄█▀▄ ▀ ▄▄ █▄▀▄████ | |
████ █▄▄▄█ █ ▄█ ▄▀ █ █▀▄▀▄█ ▀▀▀▀██ █▄ █▀▀ █ ▀▄▀▄▀█▀ ▄█▀▀ █▀▄▄ ▀▄▄ █▀ ▀█▀████ | |
████▄▄▄▄▄▄▄█▄███▄▄██▄▄▄▄▄█▄█▄█▄▄█▄▄▄▄█▄█▄▄█▄▄▄█▄▄█▄███▄█▄████▄█▄██▄█▄█▄██████ | |
█████████████████████████████████████████████████████████████████████████████ | |
████████████████████████████████████████████████████████████████████████████ | |
Have you stopped the Wireguard service? Is it still running?
sudo systemctl status [email protected]
I did stop it:
Aug 11 11:36:27 raspberrypi systemd[1]: Stopping [email protected] - WireGuard >
Aug 11 11:36:27 raspberrypi wg-quick[500702]: [#] ufw route delete allow in on wg0>
Aug 11 11:36:28 raspberrypi wg-quick[500709]: Rule deleted
Aug 11 11:36:28 raspberrypi wg-quick[500709]: Rule deleted (v6)
Aug 11 11:36:28 raspberrypi wg-quick[500702]: [#] iptables -t nat -D POSTROUTING ->
Aug 11 11:36:28 raspberrypi wg-quick[500778]: [#] wg showconf wg0
Aug 11 11:36:28 raspberrypi wg-quick[500702]: [#] ip link delete dev wg0
Aug 11 11:36:28 raspberrypi systemd[1]: [email protected]: Deactivated successf>
Aug 11 11:36:28 raspberrypi systemd[1]: Stopped [email protected] - WireGuard v>
Aug 11 11:36:28 raspberrypi systemd[1]: [email protected]: Consumed 1.156s CPU
It's hard to say with what provided....
what do you get when you run a sudo wg showconf wg0
when wireguard is running, what interface is it showing? sudo wg |grep interface
What does journalctl
show?
Just trying to get a grasp on what might be going on. Wireguard is just a standard service, nothing too complex or strange.
Here are results:
root@raspberrypi:/etc/wireguard# sudo wg showconf wg0
[Interface]
ListenPort = 51820
PrivateKey = ***
[Peer]
PublicKey =***
AllowedIPs = 10.8.0.2/32
root@raspberrypi:/etc/wireguard# sudo wg |grep interface
interface: wg0
The journalctl output is 2.5MB, so haven't attached it: I don't see any problems in it to do with wireguard.
So now wg0,conf etc seem to be correct. Can't figure out why the problem occurred and then got corrected. Now I will generate the 2nd client's keys and conf and amend the wg0.conf file accordingly.
Right on.
Chris,
Thanks for the help. The wireguard service now starts OK. I just tried it on my phone usin the public wifi in a supermarket. There's a repetition of the following lines:
08-11 16:52:12.460 6749 6749 I InputTransport: Create ARC handle: 0xb400007c87454320 08-11 16:52:12.466 6749 6749 I wm_on_top_resumed_gained_called: [203408990,com.wireguard.android.activity.LogViewerActivity,topStateChangedWhenResumed] 08-11 16:52:12.838 6749 6749 I wm_on_stop_called: [68814221,com.wireguard.android.activity.SettingsActivity,STOP_ACTIVITY_ITEM] 08-11 16:52:12.839 6749 6749 V PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@255cf9d, this = DecorView@13afd86[SettingsActivity] 08-11 16:52:15.243 6749 6749 I menu_item_selected: [0,Export log file] 08-11 16:52:18.114 6749 6749 I wm_on_top_resumed_lost_called: [203408990,com.wireguard.android.activity.LogViewerActivity,topStateChangedWhenResumed] 08-11 16:52:18.115 6749 6749 I wm_on_paused_called: [203408990,com.wireguard.android.activity.LogViewerActivity,performPause] 08-11 16:52:18.136 6749 6749 I wm_on_restart_called: [68814221,com.wireguard.android.activity.SettingsActivity,performRestartActivity] 08-11 16:52:18.138 6749 6749 I wm_on_start_called: [68814221,com.wireguard.android.activity.SettingsActivity,handleStartActivity] 08-11 16:52:18.138 6749 6749 V PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@255cf9d, this = DecorView@13afd86[SettingsActivity] 08-11 16:52:18.138 6749 6749 I wm_on_resume_called: [68814221,com.wireguard.android.activity.SettingsActivity,RESUME_ACTIVITY] 08-11 16:52:18.138 6749 6749 I wm_on_top_resumed_gained_called: [68814221,com.wireguard.android.activity.SettingsActivity,topWhenResuming] 08-11 16:52:18.138 6749 6749 V PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@255cf9d, this = DecorView@13afd86[SettingsActivity] 08-11 16:52:18.517 6749 6749 I wm_on_stop_called: [203408990,com.wireguard.android.activity.LogViewerActivity,LIFECYCLER_STOP_ACTIVITY] 08-11 16:52:18.518 6749 6749 V PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = android.view.ViewRootImpl@f81e623, this = DecorView@a933b4[LogViewerActivity] 08-11 16:52:18.519 6749 6749 I wm_on_destroy_called: [203408990,com.wireguard.android.activity.LogViewerActivity,performDestroy] 08-11 16:52:18.528 6749 6749 I InputTransport: Destroy ARC handle: 0xb400007c87454320 08-11 16:52:20.795 6749 6749 I wm_on_top_resumed_lost_called: [68814221,com.wireguard.android.activity.SettingsActivity,topStateChangedWhenResumed] 08-11 16:52:20.796 6749 6749 I wm_on_paused_called: [68814221,com.wireguard.android.activity.SettingsActivity,performPause] 08-11 16:52:20.825 6749 6749 I wm_on_create_called: [42336915,com.wireguard.android.activity.LogViewerActivity,performCreate] 08-11 16:52:20.828 6749 6749 I wm_on_start_called: [42336915,com.wireguard.android.activity.LogViewerActivity,handleStartActivity] 08-11 16:52:20.828 6749 6749 I wm_on_resume_called: [42336915,com.wireguard.android.activity.LogViewerActivity,RESUME_ACTIVITY]
Does that mean that wireguard is running Ok?
Interestingly, there is no log file created in /var/log for wireguard.
Do you have any services running on your local network to test? Or why are you implementing Wireguard to begin with?
The best thing to do, is connect to the macro network with your device (since this appears to be an Android device) and check what your IP address while on the macro network. Or if you have services running on your local network, see if you can connect to them.
You can verify when connected to Wireguard by checking the output of sudo wg show
. It'll show the peers and their connection status/data transfer.
The reason that I'm implementing WireGuard is mainly to do financial stuff when using a public network. It would also be useful to use BBC iPlayer when out of UK. "sudo wg show", when using phone signal on my phone at home, gives:
manager@raspberrypi:~$ sudo wg show
interface: wg0
public key: ***
private key: (hidden)
listening port: 51820
peer: ***
allowed ips: 10.8.0.2/32
peer: ***
allowed ips: 10.8.0.3/32
So it appears that WireGuard 's service is running Ok on my Raspberry Pi.
However, WireGuard's application log shows repeatedly, with appropriate client conf file being used by WireGuard client on my Android phone:
08-12 07:30:27.732 6749 6822 D WireGuard/GoBackend/rose: peer(1p55…dRiQ) - Handshake did not complete after 5 seconds, retrying (try 2)
08-12 07:30:27.732 6749 6822 D WireGuard/GoBackend/rose: peer(1p55…dRiQ) - Sending handshake initiation
08-12 07:30:32.891 6749 6821 D WireGuard/GoBackend/rose: peer(1p55…dRiQ) - Sending handshake initiation
08-12 07:30:38.163 6749 6822 D WireGuard/GoBackend/rose: peer(1p55…dRiQ) - Sending handshake initiation
I don't test WireGuard with my phone connected to my home wifi as I think that that's not a true test and I also think that it wouldn't work (just like my access to my web server's website, also on my Raspberry Pi, doesn't work at home, perhaps due to my ISP preventing it).
Even after purging the wireguard package still getting the 2 interfaces on the show command!