mirror of
https://github.com/angristan/wireguard-install.git
synced 2024-11-24 22:06:01 +03:00
Merge client's IPv4 and IPv6 questions
The host bit would surely be the same for both IPv4 and IPv6.
This commit is contained in:
parent
9d600fce15
commit
812ea87ca9
@ -62,10 +62,9 @@ If you want to customise your installation, you can export them or specify them
|
|||||||
- `CLIENT_DNS_1=176.103.130.130`
|
- `CLIENT_DNS_1=176.103.130.130`
|
||||||
- `CLIENT_DNS_2=176.103.130.131`
|
- `CLIENT_DNS_2=176.103.130.131`
|
||||||
- `CLIENT_NAME=client`
|
- `CLIENT_NAME=client`
|
||||||
- `CLIENT_DOT_IPV4=2`
|
- `CLIENT_DOT=2`
|
||||||
- `CLIENT_DOT_IPV6=2`
|
|
||||||
|
|
||||||
If the server is behind NAT, you can specify its endpoint with the `SERVER_PUB_IP` variable. If the endpoint is the public IP address which it is behind, you can use `SERVER_PUB_IP=$(curl ifconfig.co)` (the script will default to this). The endpoint can be an IP or a domain.
|
If the server is behind NAT, you can specify its endpoint with the `SERVER_PUB_IP` variable. If the endpoint is the public IP address which it is behind, you can use `SERVER_PUB_IP=$(curl https://ifconfig.co)` (the script will default to this). The endpoint can be an IP or a domain.
|
||||||
|
|
||||||
Other variables can be set depending on your choice (`SERVER_NIC`). You can search for them in the `installQuestions()` function of the script.
|
Other variables can be set depending on your choice (`SERVER_NIC`). You can search for them in the `installQuestions()` function of the script.
|
||||||
|
|
||||||
@ -79,8 +78,7 @@ The following Bash script adds a new user `foo` to an existing WireGuard configu
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export MENU_OPTION="1"
|
export MENU_OPTION="1"
|
||||||
export CLIENT_NAME="foo"
|
export CLIENT_NAME="foo"
|
||||||
export CLIENT_DOT_IPV4="3"
|
export CLIENT_DOT="3"
|
||||||
export CLIENT_DOT_IPV6="3"
|
|
||||||
./wireguard-install.sh
|
./wireguard-install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -139,8 +139,7 @@ function installWireGuard() {
|
|||||||
CLIENT_DNS_1=${CLIENT_DNS_1:-176.103.130.130}
|
CLIENT_DNS_1=${CLIENT_DNS_1:-176.103.130.130}
|
||||||
CLIENT_DNS_2=${CLIENT_DNS_2:-176.103.130.131}
|
CLIENT_DNS_2=${CLIENT_DNS_2:-176.103.130.131}
|
||||||
CLIENT_NAME=${CLIENT_NAME:-client}
|
CLIENT_NAME=${CLIENT_NAME:-client}
|
||||||
CLIENT_DOT_IPV4=${CLIENT_DOT_IPV4:-2}
|
CLIENT_DOT=${CLIENT_DOT:-2}
|
||||||
CLIENT_DOT_IPV6=${CLIENT_DOT_IPV6:-2}
|
|
||||||
|
|
||||||
# Behind NAT, we'll default to the publicly reachable IPv4.
|
# Behind NAT, we'll default to the publicly reachable IPv4.
|
||||||
SERVER_PUB_IP=${SERVER_PUB_IP:-$(curl https://ifconfig.co)}
|
SERVER_PUB_IP=${SERVER_PUB_IP:-$(curl https://ifconfig.co)}
|
||||||
@ -270,10 +269,10 @@ function newClient() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
until [[ ${IPV4_EXISTS} == '0' ]]; do
|
until [[ ${IPV4_EXISTS} == '0' ]]; do
|
||||||
until [[ ${CLIENT_DOT_IPV4} =~ ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do
|
until [[ ${CLIENT_DOT} =~ ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do
|
||||||
read -rp "Client's WireGuard IPv4: ${SERVER_WG_IPV4::-1}" -e -i "${CLIENT_DOT_IPV4}" CLIENT_DOT_IPV4
|
read -rp "Client's WireGuard Host ID (valid for both IPv4 and IPv6): ${SERVER_WG_IPV4::-1}" -e -i "${CLIENT_DOT}" CLIENT_DOT
|
||||||
done
|
done
|
||||||
CLIENT_WG_IPV4="${SERVER_WG_IPV4::-1}${CLIENT_DOT_IPV4}"
|
CLIENT_WG_IPV4="${SERVER_WG_IPV4::-1}${CLIENT_DOT}"
|
||||||
IPV4_EXISTS=$(grep -c "$CLIENT_WG_IPV4" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
IPV4_EXISTS=$(grep -c "$CLIENT_WG_IPV4" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
||||||
|
|
||||||
if [[ ${IPV4_EXISTS} == '1' ]]; then
|
if [[ ${IPV4_EXISTS} == '1' ]]; then
|
||||||
@ -282,20 +281,7 @@ function newClient() {
|
|||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
CLIENT_WG_IPV6="${SERVER_WG_IPV6::-1}${CLIENT_DOT}"
|
||||||
until [[ ${IPV6_EXISTS} == '0' ]]; do
|
|
||||||
until [[ ${CLIENT_DOT_IPV6} =~ ^[a-f0-9]{1,4}$ ]]; do
|
|
||||||
read -rp "Client's WireGuard IPv6: ${SERVER_WG_IPV6::-1}" -e -i "${CLIENT_DOT_IPV4}" CLIENT_DOT_IPV6
|
|
||||||
done
|
|
||||||
CLIENT_WG_IPV6="${SERVER_WG_IPV6::-1}${CLIENT_DOT_IPV6}"
|
|
||||||
IPV6_EXISTS=$(grep -c "${CLIENT_WG_IPV6}" "/etc/wireguard/${SERVER_WG_NIC}.conf")
|
|
||||||
|
|
||||||
if [[ ${IPV6_EXISTS} == '1' ]]; then
|
|
||||||
echo ""
|
|
||||||
echo "A client with the specified IPv6 was already created, please choose another IPv6."
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Generate key pair for the client
|
# Generate key pair for the client
|
||||||
CLIENT_PRIV_KEY=$(wg genkey)
|
CLIENT_PRIV_KEY=$(wg genkey)
|
||||||
|
Loading…
Reference in New Issue
Block a user