Forked from djdembeck/07-renew-public-att-dhcp.sh
Last active
December 30, 2024 03:13
-
-
Save BennettStaley/15c15449426ded164261700534fd14a2 to your computer and use it in GitHub Desktop.
UDMP Allow use of AT&T DHCP IP as static IP and keeps the lease alive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# testing retry ability - 12/29/2024 | |
# Polls AT&T's DHCP server for updates, to keep static IPs alive. | |
# This allows UDM Pro users to set their DHCP IP as 'static' in the 'Internet' section | |
# allowing the use of static IP configuration in Unifi Network. | |
# Steps: | |
# 1. Find your IP, netmask (subnet), and gateway. `ifconfig` will list your interfaces. | |
# eth8 is RJ45, eth9 and eth10 are top and bottom SFP+ respectively (on UDM) | |
# 2. find your gateway with a subnet calculator. Enter the netmask (subnet) we found with `ifconfig` | |
# Your gateway will be the first one in the range listed | |
# https://www.calculator.net/ip-subnet-calculator.html | |
# 3. In the UDM's internet settings, change it from DHCPv4 to Static IP, and enter the ip, subnet, and gateway we found and apply | |
# Your internet should stay up at this point, but will decay. Setting up this script will keep it alive. | |
# 4. Add your static IP block to the "Additional IP Addresses" section | |
# 5. ssh into your UDM. | |
# 6. install the on-boot-script from unifi-utilities: | |
# https://github.com/unifi-utilities/unifios-utilities/tree/main/on-boot-script | |
# (I ran into issues installing this, stating there was no internal storage. However the systemctl "on-boot" was still enabled. It doesn't really matter since the script will still trigger on boot and run our keep alive script, and just exit with a bad code) | |
# 7. Place this entire script in the directory `/data/on_boot.d/` and name it `07-renew-public-att-dhcp.sh` | |
# use vi or install nano. If you don't know what either of these are, install nano: `apt-get install nano` | |
# you can run `nano /data/on_boot.d/07-renew-public-att-dhcp.sh` to edit it | |
# 7.5. edit the lines below to meet your needs. | |
# 8. run `chmod +x /data/on_boot.d/07-renew-public-att-dhcp.sh` to make our new script executable | |
# 9. add a the included log rotate script to `/etc/logrotate.d/` and name it `udhcpc` | |
# `nano /etc/logrotate.d/udhcpc` | |
# 10. kick off our script for the first time by running `/data/on_boot.d/07-renew-public-att-dhcp.sh` | |
# and check the logs with `cat /var/log/udhcpc.log` | |
# 11. if everything looks good, reboot your UDM and ssh back into it once booted and check the logs again. | |
# `cat /var/log/udhcpc.log` | |
# Credit to https://community.ui.com/questions/Additional-IP-with-DHCP-primary-on-UDM-Pro/ceeaa11b-b1f2-442d-a8ba-6cdfcc29c7f6 | |
# Tested on 4.1.13 | |
PUBLIC_DHCP_IP="" # public ip we got earlier | |
WAN_PORT="eth10" # see above for likely eths | |
# both of these are customizable | |
RETRY_LIMIT=10 # Number of retries | |
RETRY_INTERVAL=30 # Seconds to wait between retries | |
# dont touch these | |
attempt=0 | |
success=false | |
while [[ $attempt -lt $RETRY_LIMIT && $success == false ]]; do | |
nohup /usr/bin/busybox-legacy/udhcpc --foreground --interface $WAN_PORT --script /usr/share/ubios-udapi-server/ubios-udhcpc-script -r $PUBLIC_DHCP_IP >/var/log/udhcpc.log 2>&1 & | |
pid=$! | |
wait $pid | |
exit_status=$? | |
if [[ $exit_status -eq 0 ]]; then | |
echo "Command executed successfully." | |
success=true | |
else | |
echo "Command failed with status $exit_status. Attempting retry in $RETRY_INTERVAL seconds..." | |
sleep $RETRY_INTERVAL | |
fi | |
((attempt++)) | |
done | |
if [[ $success == false ]]; then | |
echo "Failed to execute command after $RETRY_LIMIT attempts." | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/logrotate.d/udhcpc | |
# Rotate the logs to keep them from filling up the system | |
/var/log/udhcpc.log { | |
weekly | |
rotate 1 | |
size 100K | |
compress | |
delaycompress | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment