WireGuard client

    • Encrypt your internet connection to enforce security and privacy.
      • Prevent traffic leaks and 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.

    Install the required packages. Specify configuration parameters for VPN client.

    # Install packages
    wireguard-tools
     
    # Configuration parameters
    VPN_IF="vpn"
    VPN_SERV="SERVER_ADDRESS"
    VPN_PORT="51820"
    VPN_ADDR="192.168.9.2/24"
    VPN_ADDR6="fd00:9::2/64"

    Generate and exchange keys between server and client.

    # Generate keys
    umask go=
    wg genkey | tee wgserver.key | wg pubkey > wgserver.pub
    wg genkey | tee wgclient.key | wg pubkey > wgclient.pub
    wg genpsk > wgclient.psk
     
    # Client private key
    VPN_KEY="$(cat wgclient.key)"
     
    # Pre-shared key
    VPN_PSK="$(cat wgclient.psk)"
     
    # Server public key
    VPN_PUB="$(cat wgserver.pub)"

    Consider VPN network as public. 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 del_list firewall.wan.network="${VPN_IF}"
    uci add_list firewall.wan.network="${VPN_IF}"
    uci commit firewall
    service firewall restart

    Configure VPN interface and peers. Note that network addresses require a netmask or they will default to defining a subnet of /32, and fail to route to the other end of the tunnel! The Allowed IP field can be a /32 as it is describing IPs rather than a subnet.

    # Configure network
    uci -q delete network.${VPN_IF}
    uci set network.${VPN_IF}="interface"
    uci set network.${VPN_IF}.proto="wireguard"
    uci set network.${VPN_IF}.private_key="${VPN_KEY}"
    uci add_list network.${VPN_IF}.addresses="${VPN_ADDR}"
    uci add_list network.${VPN_IF}.addresses="${VPN_ADDR6}"
     
    # Add VPN peers
    uci -q delete network.wgserver
    uci set network.wgserver="wireguard_${VPN_IF}"
    uci set network.wgserver.public_key="${VPN_PUB}"
    uci set network.wgserver.preshared_key="${VPN_PSK}"
    uci set network.wgserver.endpoint_host="${VPN_SERV}"
    uci set network.wgserver.endpoint_port="${VPN_PORT}"
    uci set network.wgserver.persistent_keepalive="25"
    uci set network.wgserver.route_allowed_ips="1"
    uci add_list network.wgserver.allowed_ips="0.0.0.0/0"
    uci add_list network.wgserver.allowed_ips="::/0"
    uci commit network
    service network restart

    Resolve race conditions and configure dynamic connection if necessary.

    Establish the VPN connection. Verify your routing with traceroute and traceroute6.

    traceroute openwrt.org
    traceroute6 openwrt.org

    Check your IP and DNS provider.

    On router:

    • Go to LuCI > Status > Wireguard and look for peer device connected with an IPv4 or IPv6 address and with a recent handshake time
    • Go to LuCI > Network > Diagnostics and ipv4 ping client device IP eg. 10.0.0.10

    On client device depending on wireguard software:

    • Check transfer traffic for tx & rx
    • Ping router internal lan IP
    • Check public IP address in a browser – https://whatsmyip.com – should see public IP address of ISP for the router

    Collect and analyze the following information.

    # Restart services
    service log restart; service network restart; sleep 10
     
    # Log and status
    logread -e vpn; netstat -l -n -p | grep -e "^udp\s.*\s-$"
     
    # Runtime configuration
    pgrep -f -a wg; wg show; wg showconf wg0
    ip address show; ip route show table all
    ip rule show; ip -6 rule show; nft list ruleset
     
    # Persistent configuration
    uci show network; uci show firewall; crontab -l
    1. Check keys match
    2. Check the tunnel route
    3. Check your addresses (LuCI will not remind you to set a netmask!)
    4. Check your firewall

    You can use the `netcat` package to make an arbitrary UDP connection to your endpoint, and `tcpdump udp port ENDPOINT_PORT` at your other end if it is a Linux machine to see the result.

    echo hello | netcat -u ENDPOINT_HOST ENDPOINT_PORT
    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
    • Last modified: 2026/06/07 19:08
    • by widget