
In this guide, we will walk you through setting up a VPN using WireSock, with Ubuntu as the server and Windows as the client. This setup will also configure SOCKS5 and WireGuard on Ubuntu. Each command and configuration step is clearly explained to ensure a smooth process. Special thanks to Vadim Smirnov, the creator of WireSock (https://www.wiresock.net/).
While the step-by-step guide for setting up WireGuard is very detailed, it might be easier for most users to use this script: WireGuard Install. If the script fails for any reason, you can revert to the detailed guide provided below.
First, update your package list and upgrade the existing packages.
sudo apt updatesudo apt upgrade
Next, install the necessary tools: nano for editing files, net-tools for networking tools, and wireguard for the VPN.
sudo apt install nano net-tools wireguard
Identify your network interface name, which is often ens3 on many systems. Use ifconfig to find it:
ifconfig
Look for the interface connected to the internet (often named ens3 or similar).
Create a directory to store your WireGuard keys.
sudo mkdir /etc/wireguard/keyscd /etc/wireguard/keys
Switch to the root user to generate the keys.
sudo su
Generate the public and private keys.
wg genkey | tee privatekey | wg pubkey > publickey
You should also generate a preshared key.
wg genpsk > presharedkey
Store these keys securely.
Create a helper script to add NAT routing. This will enable forwarding traffic from your VPN to the internet.
sudo mkdir -p /etc/wireguard/helpersudo nano /etc/wireguard/helper/add-nat-routing.sh
Add the following content to the script:
#!/bin/bashIPT="/sbin/iptables"IPT6="/sbin/ip6tables"IN_FACE="ens3" # NIC connected to the internetWG_FACE="wg0" # WG NICSUB_NET="10.66.66.0/24" # WG IPv4 sub/net aka CIDRWG_PORT="51820" # WG udp portSUB_NET_6="fd42:42:42::/64" # WG IPv6 sub/net## IPv4 ##$IPT -t nat -I POSTROUTING 1 -s $SUB_NET -o $IN_FACE -j MASQUERADE$IPT -I INPUT 1 -i $WG_FACE -j ACCEPT$IPT -I FORWARD 1 -i $IN_FACE -o $WG_FACE -j ACCEPT$IPT -I FORWARD 1 -i $WG_FACE -o $IN_FACE -j ACCEPT$IPT -I INPUT 1 -i $IN_FACE -p udp --dport $WG_PORT -j ACCEPT## IPv6 (Uncomment) ### $IPT6 -t nat -I POSTROUTING 1 -s $SUB_NET_6 -o $IN_FACE -j MASQUERADE# $IPT6 -I INPUT 1 -i $WG_FACE -j ACCEPT# $IPT6 -I FORWARD 1 -i $IN_FACE -o $WG_FACE -j ACCEPT# $IPT6 -I FORWARD 1 -i $WG_FACE -o $IN_FACE -j ACCEPT
Make the script executable:
sudo chmod +x /etc/wireguard/helper/add-nat-routing.sh
Create a script to remove NAT routing.
sudo nano /etc/wireguard/helper/remove-nat-routing.sh
Add the following content:
#!/bin/bashIPT="/sbin/iptables"IPT6="/sbin/ip6tables"IN_FACE="ens3" # NIC connected to the internetWG_FACE="wg0" # WG NICSUB_NET="10.66.66.0/24" # WG IPv4 sub/net aka CIDRWG_PORT="51820" # WG udp portSUB_NET_6="fd42:42:42::/64" # WG IPv6 sub/net# IPv4 rules #$IPT -t nat -D POSTROUTING -s $SUB_NET -o $IN_FACE -j MASQUERADE$IPT -D INPUT -i $WG_FACE -j ACCEPT$IPT -D FORWARD -i $IN_FACE -o $WG_FACE -j ACCEPT$IPT -D FORWARD -i $WG_FACE -o $IN_FACE -j ACCEPT$IPT -D INPUT -i $IN_FACE -p udp --dport $WG_PORT -j ACCEPT# IPv6 rules (uncomment) ## $IPT6 -t nat -D POSTROUTING -s $SUB_NET_6 -o $IN_FACE -j MASQUERADE# $IPT6 -D INPUT -i $WG_FACE -j ACCEPT# $IPT6 -D FORWARD -i $IN_FACE -o $WG_FACE -j ACCEPT# $IPT6 -D FORWARD -i $WG_FACE -o $IN_FACE -j ACCEPT
Make this script executable as well:
sudo chmod +x /etc/wireguard/helper/remove-nat-routing.sh
Enable IP forwarding to allow traffic to be forwarded from your VPN clients to the internet.
sudo sysctl -w net.ipv4.ip_forward=1echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.confsudo sysctl -w net.ipv6.conf.all.forwarding=1echo "net.ipv6.conf.all.forwarding = 1" | sudo tee -a /etc/sysctl.confsudo sysctl -p
Create the main WireGuard configuration file.
sudo nano /etc/wireguard/wg0.conf
Add the following content, replacing the placeholder keys with your generated keys:
[Interface]PrivateKey = YOUR_PRIVATE_KEY_HEREAddress = 10.66.66.1/24ListenPort = 51820PostUp = /etc/wireguard/helper/add-nat-routing.shPostDown = /etc/wireguard/helper/remove-nat-routing.sh[Peer]PublicKey = YOUR_PEER_PUBLIC_KEY_HEREAllowedIPs = 10.66.66.2/32PresharedKey = YOUR_PRESHARED_KEY_HERE
Start WireGuard:
sudo wg-quick up wg0sudo systemctl enable wg-quick@wg0
Verify the iptables rules:
sudo iptables -t nat -Lsudo iptables -L
Check the status of WireGuard:
sudo systemctl status wg-quick@wg0
The use of a SOCKS5 proxy can be beneficial for specific network requirements or constraints. Install the Dante SOCKS proxy server:
sudo apt install dante-server
Create a user for Dante:
sudo suuseradd -r -s /bin/false danteuserpasswd danteuser
Edit the configuration file:
sudo nano /etc/danted.conf
Add the following configuration:
logoutput: /var/log/socks.loginternal: ens3 port = 1080external: ens3clientmethod: nonesocksmethod: usernameuser.privileged: rootuser.notprivileged: nobodyclient pass {from: 0.0.0.0/0 to: 0.0.0.0/0log: error connect disconnect}client block {from: 0.0.0.0/0 to: 0.0.0.0/0log: connect error}socks pass {from: 0.0.0.0/0 to: 0.0.0.0/0udp.portrange: 40000-45000log: error connect disconnect}socks block {from: 0.0.0.0/0 to: 0.0.0.0/0log: connect error}
Allow the required ports through the firewall:
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 1080 -j ACCEPTiptables -I INPUT -p udp --dport 40000:45000 -j ACCEPTiptables-save > /etc/iptables/rules.v4
Enable and start the Dante service:
sudo systemctl enable dantedsudo systemctl start danted
To set up the WireSock client on your Windows machine, follow these steps:
Download and Install WireSock: Download the appropriate WireSock client from the downloads section and install it on your Windows machine.
Configure WireSock: Open/Create the configuration file, typically located at C:\Program Files\WireSock VPN Client\bin\wg0.conf, and add the following configuration, replacing the placeholder keys with your generated keys:
[Interface]PrivateKey = YOUR_PRIVATE_KEY_HEREAddress = 10.66.66.2/32,fd42:42:42::2/128DNS = 1.1.1.1,1.0.0.1MTU = 1240[Peer]PublicKey = YOUR_PEER_PUBLIC_KEY_HEREPresharedKey = YOUR_PRESHARED_KEY_HEREEndpoint = YOUR_SERVER_IP:51820AllowedIPs = 0.0.0.0/0,::/0PersistentKeepalive = 900DisallowedIPs = 192.168.1.0/24Socks5Proxy = YOUR_SERVER_IP:1080Socks5ProxyUsername = danteuserSocks5ProxyPassword = YOUR_PASSWORD_HERESocks5ProxyAllTraffic = true
wiresock-client.exe run -config "C:\Program Files\WireSock VPN Client\bin\wg0.conf" -log-level info
Alternatively, you can use the WireSock UI application, which is available on GitHub for easier management of the VPN connection.
By following these steps, you have set up a WireGuard VPN with a SOCKS5 proxy on an Ubuntu server, allowing a Windows client to connect securely. This configuration enables private and secure internet access through your VPN.
We’d love to hear your feedback on this tutorial! If you have any questions or suggestions for improvement, please don’t hesitate to reach out. You can leave a comment below, or you can contact us through the following channels:
If you found this guide beneficial, don’t hesitate to share it with your network. Until the next guide, happy coding!
Quick Links
Legal Stuff





