WireGuard connect

Submitted by lepton on Tue, 05/26/2020 - 15:39

wg genkey | tee server.key | wg pubkey > server.pub


PEER_A_PUB=key_string
PEER_Endpoint="endpoint ip:9902" #maybe empty
PEER_A_IP=10.1.0.2
MY_IP=10.1.0.1/24
MY_PORT=9901
ip link del wg0 ip link add dev wg0 type wireguard
ip addr add $MY_IP dev wg0
wg set wg0 listen-port $MY_PORT private-key /etc/wireguard/server.key
wg set wg0 peer $PEER_A_PUB $PEER_Endpoint allowed-ips $PEER_A_IP/32
ip link set wg0 up

in dir /etc/wireguard

wg genkey | tee peer.key | wg pubkey > peer.pub

wg genpsk > peer_A-peer_B.psk

//if ip is not fixed no need endpoint other-ip:9902
//mostly server side has no,client has endpoint

//preshared-key /path/to/peer_A-peer_B.psk
//if has both side need to add

a side config

ip link add dev wg0 type wireguard
ip addr add 10.1.0.1/24 dev wg0
wg set wg0 listen-port 9901 private-key /etc/wireguard/peer.key

wg set wg0 peer other-b-pub-string endpoint other-ip:9902 allowed-ips 10.1.0.2/32
//if has many peer like b c d, add one peer one line

ip link set wg0 up

 

b side config

ip link add dev wg0 type wireguard
ip addr add 10.1.0.2/24 dev wg0
wg set wg0 listen-port 9902 private-key /etc/wireguard/peer.key
wg set wg0 peer other-a-pub-string allowed-ips 10.1.0.1/32
ip link set wg0 up

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.