wireguard-hosts file

Elliot Saba staticfloat at gmail.com
Fri Jan 24 21:22:45 CET 2020


Just as a point of reference, I manually implemented my own solution for
this.  I have all my wireguard key files named as `<hostname>.pub` in a
directory, then I source the following as one of my dot files:


#!/usr/bin/env bash


# Don't do anything if `wg` doesn't exist

*if *[[ *-z* $(which wg) ]]; *then*

    *return*

*fi*


# Otherwise, load in our mapping of public keys to hostnames:

# Otherwise, load in our mapping of public keys to hostnames:

*declare* -A WG_HOST_MAP

*for* f *in* ${HOMES_PATH}/etc/secure/wireguard/*.pub; *do*

    HOST=$(basename *"*${f%.*}*"*)

    KEY=$(cat *"*$f*"*)

    WG_HOST_MAP["${KEY}"]="${HOST}"

*done*


function wg()

{

    # Do some special parsing for `wg show`

    *if *[[ *-z* "$1" ]] || [[ "$1" *==* "show" ]]; *then*

        WG_OUTPUT=$(unbuffer sudo -n $(which wg))

        *for* K *in* "${!WG_HOST_MAP[@]}"; *do*

            V="${WG_HOST_MAP["${K}"]}"

            WG_OUTPUT="${WG_OUTPUT/"${K}"/"${V}"}"

        *done*

        *echo* "${WG_OUTPUT}"

    *else*

        # Pass through to actual `wg` otherwise

        sudo -n $(which wg) "$@"

    *fi*

}

*export* -f wg



You’ll notice that it automatically calls `sudo -n` on things, and that it
requires `unbuffer`, which is usually installed alongside `expect`, so that
it can capture the output of `wg` retaining the color codes.
-E


On January 24, 2020 at 8:04:12 AM, jens (jens at viisauksena.de) wrote:

i really would love to have a feature like wireguard-hosts file.
whereas wg command would print given "name" instead of key - so the
output would be more meaningfull
We have some wireguard running in server like infrastructure, where one
server serves dozens of "clients"

so instead of
peer: l9FxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaU=
we would have something alike
peer: superhero downtown

some of you may be familar with batman-adv layer2 routing protocol,
there they also have a batctl which is working pretty similar to wg tool.
there you can add a bat-hosts file which is doing the job, which totaly
works likes any hosts file
a normal hosts file maps ip to name,
a bat-hosts file maps mac addresses to name,
a wg-hosts file would map keys to name.

i found the sources for bat-hosts ( .c .h .sample ) here
https://downloads.open-mesh.org/batman/releases/batman-adv-2019.5/batctl-2019.5.tar.gz

is this something maybe usefull to other also?
is there a chance to have this implemented by default?

thx for answers.
fuzzle

-- 
make the world nicer, please use PGP encryption
_______________________________________________
WireGuard mailing list
WireGuard at lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/wireguard/attachments/20200124/32f59907/attachment.html>


More information about the WireGuard mailing list