I also use this script I made for wireguard automation.. might help somebody, this automatically 'randomizes' (gets new) IP and randomizes exposed port
(from list of ports you define in variable and of course you have reserved in your account)
This should be in (docker-compose related) `.env` file
AIRVPN_WG_PRIVATE_KEY=xxxxxxxxxxxxxxxxxxxx
AIRVPN_WG_PRESHARED_KEY=xxxxxxxxxxxxxxxxxxxxxx
AIRVPN_WG_ADDRESSES=x.x.x.x/32,x:x:x:x:x:x:x:x/128
AIRVPN_PEER_PORT=xxxxx
AIRVPN_DEVICE_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AIRVPN_SERVER_NAMES=xxxxx xxxxx
AIRVPN_COUNTRIES=xxxxx
AIRVPN_CUNTRY_CODE=xx
AIRVPN_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
AIRVPN_PORTS=xxxx xxxx xxxxx xxxxx xxxxx xxxxx xxxx xxxx xxxx xxxx xxxx xxxxx
And this is `docker-compose.yml` part:
gluetun:
image: qmcgaw/gluetun
container_name: gluetun
ports:
- 8888:8888/tcp # HTTPPROXY
sysctls:
- net.ipv6.conf.all.disable_ipv6=0
cap_add:
- NET_ADMIN
environment:
- TZ=Europe/Amsterdam
- HTTPPROXY=on
- HTTPPROXY_STEALTH=on
- VPN_TYPE=wireguard
- VPN_SERVICE_PROVIDER=airvpn
- SERVER_NAMES=${AIRVPN_SERVER_NAMES}
- SERVER_COUNTRIES=${AIRVPN_COUNTRIES}
- FIREWALL_VPN_INPUT_PORTS=${AIRVPN_PEER_PORT}
- WIREGUARD_ADDRESSES=${AIRVPN_WG_ADDRESSES}
- WIREGUARD_PRIVATE_KEY=${AIRVPN_WG_PRIVATE_KEY}
- WIREGUARD_PRESHARED_KEY=${AIRVPN_WG_PRESHARED_KEY}
volumes:
- /volume1/docker/gluetun:/gluetun
devices:
- /dev/net/tun:/dev/net/tun
restart: always
mem_limit: 1024m
memswap_limit: 1024m
Finally put this part to `.bashrc` (or alternative), `source .bashrc` then execute 'rand' function
(change path to your env file as well as docker compose file)
* you should have `jq`, `awk`, `sed`, `curl` and `shuf` binaries available.
export DOCKER_ENV_FILE=/volume1/docker/.env
export DOCKER_COMPOSE_FILE=/volume1/docker/docker-compose.yml
rand () {
CURRENT_DEVICE_ID=$(awk -F '=' '/AIRVPN_DEVICE_ID/ {print $2}' $DOCKER_ENV_FILE)
AIRVPN_API_KEY=$(awk -F '=' '/AIRVPN_API_KEY/ {print $2}' $DOCKER_ENV_FILE)
AIRVPN_CUNTRY_CODE=$(awk -F '=' '/AIRVPN_CUNTRY_CODE/ {print $2}' $DOCKER_ENV_FILE)
AIRVPN_PORTS=$(awk -F '=' '/AIRVPN_PORTS/ {print $2}' $DOCKER_ENV_FILE)
[ ! -f $CURRENT_DEVICE_ID ] && \
curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/disconnect/?device=$CURRENT_DEVICE_ID" && sleep 1 && \
curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/devices/?action=delete&id=$CURRENT_DEVICE_ID" && sleep 1
AIRVPN_DEVICE_ID=$(curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/devices/?action=add" | jq -r .id[0:50]) && sleep 10
CONFIG_FILE=$(curl -s -H "API-KEY:$AIRVPN_API_KEY" "https://airvpn.org/api/generator/?protocols=wireguard_3_udp_1637&servers=${AIRVPN_CUNTRY_CODE}&system=linux&device_id=New%20device")
AIRVPN_WG_ADDRESSES=$(awk '/Address/ {print $3$4}' <<<$CONFIG_FILE)
AIRVPN_WG_PRESHARED_KEY=$(awk '/PresharedKey/ {print $3}' <<<$CONFIG_FILE)
AIRVPN_WG_PRIVATE_KEY=$(awk '/PrivateKey/ {print $3}' <<<$CONFIG_FILE)
AIRVPN_PEER_PORT=$(shuf -n1 -e $AIRVPN_PORTS)
sed -i 's#^AIRVPN_WG_ADDRESSES=.*$#AIRVPN_WG_ADDRESSES='"$AIRVPN_WG_ADDRESSES"'#g' $DOCKER_ENV_FILE
sed -i 's#^AIRVPN_WG_PRESHARED_KEY=.*$#AIRVPN_WG_PRESHARED_KEY='"$AIRVPN_WG_PRESHARED_KEY"'#g' $DOCKER_ENV_FILE
sed -i 's#^AIRVPN_WG_PRIVATE_KEY=.*$#AIRVPN_WG_PRIVATE_KEY='"$AIRVPN_WG_PRIVATE_KEY"'#g' $DOCKER_ENV_FILE
sed -i 's#^AIRVPN_PEER_PORT=.*$#AIRVPN_PEER_PORT='"$AIRVPN_PEER_PORT"'#g' $DOCKER_ENV_FILE
sed -i 's#^AIRVPN_DEVICE_ID=.*$#AIRVPN_DEVICE_ID='"$AIRVPN_DEVICE_ID"'#g' $DOCKER_ENV_FILE
docker-compose --env-file $DOCKER_ENV_FILE -f $DOCKER_COMPOSE_FILE up --detach --quiet-pull --remove-orphans
}
There is a single limitation, you can only have a single "New device" named device on your account, this gets re-cycled (current deleted and new created) by the script.
This is because we can't set device name via API so I am forced to use the default "New device" name while calling API to generate a new config.
Oh and the api calls must go without using VPN, because understandably, its killing the connection so you'd be unable to finish the process.