Requirements: WireGuard is used to build a remote network, and each peer node can access each other, but if you want to access each other's LAN through the node, how should you configure it?
Shanghai Mobile Computer wants to access other machines in the LAN where Shandong Unicom Computer is located, as shown in the figure below:
This article is not based on Docker, but directly builds WireGuard on the host machine. The environment is as follows:
- Server: Ubuntu 20.04
- Shanghai Mobile (Peer): Windows 11
- Shandong Unicom (Peer): Rocky 8
Server configuration
Based on Ubuntu 20.04 system, with a public IP address, first set up to enable IP forwarding, the command is as follows:
Install WireGuard with the following commands:
The generation of the PublicKey public key and the PrivateKey private key actually has no connection between the server and the client, in fact, it is to help you generate the required configuration through the tool, the command is as follows:
The PresharedKey is optional, and the generated command is as follows:
Create a new wg0.conf configuration file in the /etc/wireguard/ directory, which is complete/etc/wireguard/wg0.confThe documents are as follows:
thereintoeth0Please start the WireGuard command according to your actual situation:
In fact, you can also use systemd to start wg0 and set boot start, etc., with the following command:
Peer Shanghai Mobile Configuration
To access other machines on the LAN where Shandong Unicom Peer is located, the configuration is as follows:
Peer Shandong Unicom configuration
Based on Rocky 8 system, you need to upgrade the system kernel first, otherwise you will get the error "Error: Unknown device type, Unable to access interface: Protocol not supported", the command is as follows:
Install WireGuard with the following commands:
You also need to set up IP forwarding to enable the following command:
Turn off the firewall, otherwise it may cause devices within the LAN to be inaccessible with the following command:
Similarly, create a new wg0.conf file, and configure the full /etc/wireguard/wg0.conf configuration as follows:
thereintoens192You need to set up the WG0 interface according to your actual situation, as follows:
Test
The machine in the Shandong Unicom LAN is accessed from Shanghai Mobile test, as shown in the following figure:
Reference:
The hyperlink login is visible.
The hyperlink login is visible.
(End)
|