This documemtaion does not go into actually setting up the service at Cloudflare One, instead focus on the BASH script for updating a change IP address for users using the free tier of Cloudflare One gateway. On linux setup a cron job to execute script every so often to check for dynamic ip change from your ISP and update Cloudflare gateway with new IP to keep location secure. See script below.
#!/bin/bash
API_TOKEN="your_api_token"
ACCOUNT_ID="your_account_id"
LOCATION_ID="your_location_id"
# Get current public IP
CURRENT_IP=$(curl -s https://api.ipify.org)
CIDR_IP=$CURRENT_IP/32
# File to store last IP
IP_FILE="$HOME/.last_cf_ip"
if [ -f "$IP_FILE" ]; then
LAST_IP=$(cat $IP_FILE)
else
LAST_IP=""
fi
if [ "$CURRENT_IP" != "$LAST_IP" ]; then
echo "IP changed to $CURRENT_IP. Updating Cloudflare..."
curl -s -X PUT "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/locations/$LOCATION_ID" \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
--data @- <<EOF
{
"client_default":true,
"name":"your_location_name",
"networks":[{"network":"$CIDR_IP"}]
}
EOF
echo $CURRENT_IP > $IP_FILE
else
echo "IP unchanged."
fi