Skip to content

Commit

Permalink
Allow WireGuard port & MTU to be set + fix IP warn
Browse files Browse the repository at this point in the history
  • Loading branch information
DigitallyRefined committed May 29, 2023
1 parent 16dac77 commit 96f1009
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ RUN cp /etc/rinetd.conf /etc/rinetd.conf.ori

COPY wg-start.sh /usr/local/bin/wireguard

EXPOSE 51820/udp

CMD ["wireguard"]

EXPOSE 51820/udp
23 changes: 13 additions & 10 deletions wg-start.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,44 @@
#!/usr/bin/env bash

wireguard_port="${WIREGUARD_PORT:-51820}"
wireguard_mtu="${WIREGUARD_MTU:-1280}"

if [ ! -f /etc/wireguard/wg0.conf ]; then
server_private="$(wg genkey)"
server_public=$(echo "${server_private}" | wg pubkey)
server_public=$(echo -n "${server_private}" | wg pubkey)

cat >/etc/wireguard/wg0.conf <<EOF
[Interface]
PrivateKey = $server_private
# PublicKey = $server_public
Address = 10.0.0.254/24
ListenPort = 51820
SaveConfig = true
Address = 10.0.0.254/32
ListenPort = $wireguard_port
MTU = $wireguard_mtu
SaveConfig = false
EOF

if [[ ${DOMAIN} && ${PEERS} ]]; then
count=${PEERS//[a-z]/}
for peer_number in $(seq $count); do
peer_private="$(wg genkey)"
peer_public=$(echo "${peer_private}" | wg pubkey)
peer_public=$(echo -n "${peer_private}" | wg pubkey)

cat >/etc/wireguard/peer$peer_number.conf <<EOF
[Interface]
PrivateKey = $peer_private
# PublicKey = $peer_public
Address = 10.0.0.$peer_number/15
Address = 10.0.0.$peer_number/32
MTU = $wireguard_mtu
SaveConfig = false
[Peer]
PublicKey = $server_public
Endpoint = $DOMAIN:51820
Endpoint = $DOMAIN:$wireguard_port
AllowedIPs = 10.0.0.254/32
PersistentKeepalive = 25
EOF

cat >>/etc/wireguard/wg0.conf <<EOF
[Peer]
# peer$peer_number
PublicKey = $peer_public
AllowedIPs = 10.0.0.$peer_number/32
EOF
Expand Down

0 comments on commit 96f1009

Please sign in to comment.