User Tools

Site Tools


docs:guide-user:services:vpn:wireguard:client

WireGuard client

Introduction

  • This how-to describes the method for setting up WireGuard client on OpenWrt.
  • You can use it to connect to your own WireGuard server or a commercial WireGuard provider.
  • Follow WireGuard basic for server setup and WireGuard extras for additional tuning.

Goals

  • Encrypt your internet connection to enforce security and privacy.
    • Prevent data leak and traffic spoofing on the client side.
  • Bypass regional restrictions using commercial providers.
    • Escape client side content filters and internet censorship.
  • Access your LAN services remotely without port forwarding.

Instructions

1. Preparation

Install the packages and specify the VPN client configuration parameters.

# Install packages
opkg update
opkg install wireguard
 
# Configuration parameters
WG_IF="wg0"
WG_SERV="SERVER_NAME_OR_IP_ADDRESS"
WG_PORT="51820"
WG_ADDR="192.168.9.2/24"
WG_ADDR6="fdf1:7610:d152:3a9c::2/64"

2. Key management

Generate client keys. Exchange the public keys and the pre-shared key between the server and the client using file transfer or copy-paste.

# Generate and exchange the keys
umask u=rw,g=,o=
wg genkey | tee wgclient.key | wg pubkey > wgclient.pub
 
WG_KEY="$(cat wgclient.key)"
WG_PSK="$(cat wg.psk)"
WG_PUB="$(cat wgserver.pub)"

3. Firewall

Consider VPN network as public and assign VPN interface to WAN zone to minimize firewall setup.

# Configure firewall
uci rename firewall.@zone[0]="lan"
uci rename firewall.@zone[1]="wan"
uci rename firewall.@forwarding[0]="lan_wan"
uci del_list firewall.wan.network="${WG_IF}"
uci add_list firewall.wan.network="${WG_IF}"
uci commit firewall
/etc/init.d/firewall restart

4. Network

Set up VPN interface and peers.

# Configure network
uci -q delete network.${WG_IF}
uci set network.${WG_IF}="interface"
uci set network.${WG_IF}.proto="wireguard"
uci set network.${WG_IF}.private_key="${WG_KEY}"
uci set network.${WG_IF}.preshared_key="${WG_PSK}"
uci add_list network.${WG_IF}.addresses="${WG_ADDR}"
uci add_list network.${WG_IF}.addresses="${WG_ADDR6}"
 
# Add VPN peers
uci -q delete network.wgserver
uci set network.wgserver="wireguard_${WG_IF}"
uci set network.wgserver.public_key="${WG_PUB}"
uci set network.wgserver.endpoint_host="${WG_SERV}"
uci set network.wgserver.endpoint_port="${WG_PORT}"
uci set network.wgserver.route_allowed_ips="1"
uci set network.wgserver.persistent_keepalive="25"
uci add_list network.wgserver.allowed_ips="0.0.0.0/1"
uci add_list network.wgserver.allowed_ips="128.0.0.0/1"
uci add_list network.wgserver.allowed_ips="::/0"
uci commit network
/etc/init.d/network restart

Testing

Establish the VPN connection. Verify your client traffic is routed via VPN gateway.

traceroute openwrt.org
traceroute6 openwrt.org

Check your client public IP addresses.

Make sure there is no DNS leak on the client side.

Delegate a public IPv6 prefix to VPN6 network to use IPv6 by default.

Troubleshooting

Collect and analyze the following information.

# Restart the services, then try to reconnect
/etc/init.d/log restart; /etc/init.d/network restart; sleep 10
 
# Log and status
logread -e ${WG_IF}; netstat -l -n -p | grep -e ${WG_PORT}
 
# Runtime configuration
pgrep -f -a wg; wg show; wg showconf ${WG_IF}
ip address show; ip route show; ip rule show; iptables-save
ip -6 address show; ip -6 route show; ip -6 rule show; ip6tables-save
 
# Persistent configuration
uci show network; uci show firewall
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
docs/guide-user/services/vpn/wireguard/client.txt · Last modified: 2019/10/03 23:28 by vgaetera