修复:修改Interface地址后新增peer地址不会改变

修复了修改Interface地址后,新增peer地址不会改变随Interface改变而改变的问题
This commit is contained in:
Allone8 2022-03-28 14:04:57 +08:00 committed by GitHub
parent 0e06513eb5
commit a74a8e96f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -150,19 +150,20 @@ new_client_setup () {
fi fi
key=$(wg genkey) key=$(wg genkey)
psk=$(wg genpsk) psk=$(wg genpsk)
ipTop=$(cat /etc/wireguard/wg0.conf| grep -oE "([0-9]{1,3}\.){2}[0-9]{1,3}" | head -1)
# Configure client in the server # Configure client in the server
cat << EOF >> /etc/wireguard/wg0.conf cat << EOF >> /etc/wireguard/wg0.conf
# BEGIN_PEER $client # BEGIN_PEER $client
[Peer] [Peer]
PublicKey = $(wg pubkey <<< $key) PublicKey = $(wg pubkey <<< $key)
PresharedKey = $psk PresharedKey = $psk
AllowedIPs = 10.7.0.$octet/32$(grep -q 'fddd:2c4:2c4:2c4::1' /etc/wireguard/wg0.conf && echo ", fddd:2c4:2c4:2c4::$octet/128") AllowedIPs = $ipTop.$octet/32$(grep -q 'fddd:2c4:2c4:2c4::1' /etc/wireguard/wg0.conf && echo ", fddd:2c4:2c4:2c4::$octet/128")
# END_PEER $client # END_PEER $client
EOF EOF
# Create client configuration # Create client configuration
cat << EOF > ~/"$client".conf cat << EOF > ~/"$client".conf
[Interface] [Interface]
Address = 10.7.0.$octet/24$(grep -q 'fddd:2c4:2c4:2c4::1' /etc/wireguard/wg0.conf && echo ", fddd:2c4:2c4:2c4::$octet/64") Address = $ipTop.$octet/24$(grep -q 'fddd:2c4:2c4:2c4::1' /etc/wireguard/wg0.conf && echo ", fddd:2c4:2c4:2c4::$octet/64")
DNS = $dns DNS = $dns
PrivateKey = $key PrivateKey = $key