Accessing LAN Devices with WireGuard VPN Setup: Peers Behind Different VPN Clients
In this article, we will discuss how to access Local Area Network (LAN) devices through a WireGuard VPN setup, where two WireGuard peers are connected to a WireGuard server with a public IP on an AWS EC2 instance running Ubuntu. We will also cover how to set up a new WireGuard alias to make the process easier.
Prerequisites
- A WireGuard server with a public IP address
- Two WireGuard peers connected to the WireGuard server
- An AWS EC2 instance running Ubuntu
Setting up WireGuard
To set up WireGuard, you need to install it on both the server and the peers. You can do this by running the following commands:
sudo apt-get update
sudo apt-get install wireguardOnce WireGuard is installed, you need to generate the necessary keys and configuration files. You can generate the keys using the following commands:
wg genkey | tee privatekey > publickey
cat privatekeyYou will need to copy the private key and public key for each peer and the server. You will also need to create a configuration file for each peer and the server. The configuration file should look something like this:
[Interface]
Address = 10.0.0.1/24
PrivateKey =
ListenPort = 51820
[Peer]
PublicKey =
Endpoint = :51820
AllowedIPs = 10.0.0.2/32 You will need to replace the placeholders with the actual private key, public key, and public IP address for each peer and the server. Once you have created the configuration files, you can start the WireGuard service on each peer and the server using the following command:
sudo systemctl start wg-quick@Setting up a WireGuard Alias
To make it easier to access LAN devices through the WireGuard VPN, you can set up a WireGuard alias. This will allow you to access LAN devices using a familiar name instead of an IP address. To set up a WireGuard alias, you need to edit the /etc/hosts file on each peer and the server. The /etc/hosts file should look something like this:
127.0.0.1 localhost
10.0.0.1 server
10.0.0.2 peer1
10.0.0.3 peer2You will need to replace the placeholders with the actual IP addresses for each peer and the server. Once you have edited the /etc/hosts file, you can access LAN devices using the alias name instead of the IP address.
Accessing LAN Devices
To access LAN devices through the WireGuard VPN, you need to use the alias name instead of the IP address. For example, if you want to access a LAN device with an IP address of 192.168.1.100, you can use the following command:
ssh @peer1 -p 2222 This will connect to the LAN device through the WireGuard VPN using the peer1 alias and the SSH port 2222. Once you are connected, you can access the LAN device as if you were on the same network.
- In this article, we discussed how to access LAN devices through a WireGuard VPN setup where two WireGuard peers are connected to a WireGuard server with a public IP on an AWS EC2 instance running Ubuntu.
- We covered how to set up WireGuard, generate the necessary keys and configuration files, and start the WireGuard service on each peer and the server.
- We also discussed how to set up a WireGuard alias to make it easier to access LAN devices through the WireGuard VPN.