Skip to content

Instantly share code, notes, and snippets.

@djdembeck
Last active May 2, 2025 05:03
Show Gist options
  • Save djdembeck/4c2f251bf7a53a0ff9e1de2305043e40 to your computer and use it in GitHub Desktop.
Save djdembeck/4c2f251bf7a53a0ff9e1de2305043e40 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
#!/bin/bash
# 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.
# 1. Find your DHCP IP.
# 2. Set Internet IPv4 to Static IP, and enter your DHCP address. Gateway is going to be .1
# 3. Add your static IP block to Additional IP Addresses
# 4. Place this script in the on_boot.d/ directory: https://github.com/unifi-utilities/unifios-utilities/tree/main/on-boot-script
# 5. After reboot, check the script is working: 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 3.0.20
PUBLIC_DHCP_IP=""
# eth8 is RJ45, eth9 is SFP+ on UDMP
WAN_PORT="eth9"
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 &
# /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
}
@BennettStaley
Copy link

amazing. worked like a charm. Going to fork this to keep it. 🫡

@miles267
Copy link

I have ATT fiber with a /28 block of static IPs. If I remove my ATT gateway, I can only get an active internet connection if I set the WAN to DHCP v4. Then I’m no longer able to use my static IPs since the Additional IPs option is no longer an option in the UDM SE. I’ve had to add my ATT gateway device back into service to use my static IPs. Does this enable you to setup a WAN with DHCP but still use your static IPs block?

@BennettStaley
Copy link

BennettStaley commented Dec 26, 2024

I have ATT fiber with a /28 block of static IPs. If I remove my ATT gateway, I can only get an active internet connection if I set the WAN to DHCP v4. Then I’m no longer able to use my static IPs since the Additional IPs option is no longer an option in the UDM SE. I’ve had to add my ATT gateway device back into service to use my static IPs. Does this enable you to setup a WAN with DHCP but still use your static IPs block?

By remove your Gateway... are you using a WAS-110? I am in this case! A way to avoid this script entirely is by setting up Source and Destination NAT rules, though I didn't like how I couldn't route entire networks within the UI,

So here are my steps to properly find your ip, subnet, and gateway and setup this script to ping ATT for DHCP renewal automatically, allowing you to use the UI to set static ips! :)

  1. ssh into your UDM
  2. type in ifconfig
  3. find your eth, mine was eth10. Yours might be 10, 9, or something similar because of the UDM's ports.
  4. it should say something similar to inet xxx.xxx.129.89 netmask 255.255.254.0 --- (inet is your public ip, and make note of your netmask.
  5. plug those values into an ip subnet calculator.

this told me that my ip range was actually xxx.xxx.128.1-xxx.xxx.129.254 So my gateway would be the first one in that range, xxx.xxx.128.1 and, my public ip fell somewhere within it xxx.xxx.129.89
Note the second column. If i had just taken my ip and plugged in a 1 for the last column, it would not work. Your mileage may vary here.

Now we can take the ip, subnet, and gateway we just got and plug them into the static ip section of UI's internet page. Then add your static ips as additional ips.

Lastly follow the instructions about setting up this script, filling in your WAN_PORT and PUBLIC_DHCP_IP (what we found earlier)

this will run automatically and request ATT keep your ip lease running, and allow the UDM to set it up statically.

the second smaller script should be created in /etc/logrotate.d/udhcpc and contain

# Rotate the logs to keep them from filling up the system

/var/log/udhcpc.log {
        weekly
        rotate 1
        size 100K
        compress
        delaycompress
}

which just makes the log size smaller

I can help you set this up privately if you run into trouble and (obviously) don't want to post your public ips. I've been using it since I posted that comment with only one issue where ATT was actually having a service outage and the script failed.

@miles267
Copy link

Thanks. I’ve been using a BGW320-505 with the IP Passthrough option, connected to my UDM SE. in the BGW320-505’s Public Subnet section, I had set my static IPs, netmask and gateway provided by ATT. So I’ve recently removed my BGW320-505. I’m on a 1 Gbps fiber connection with conventional GPON. I’m able to now obtain an active internet connection using my DFP device (not the WAS-110) but only if I define my UDM SE WAN as DHCP v4. If I populate the same static IPs, netmask and gateway (previously on the BGW320-505), the internet connection drops. When I set the WAN back to DHCP and run whatsmyip, it returns an ATT Public IP I don’t even recognize. And as you’ve said, I can no longer use my additional static IP block given by ATT. For the time being, I’ve returned the BGW320-505 to service with my static IP info until I can figure out how to replicate my static Ip config without the BGW. Will this process achieve what I’m hoping? Thanks for such quick responses.

@BennettStaley
Copy link

Thanks. I’ve been using a BGW320-505 with the IP Passthrough option, connected to my UDM SE. in the BGW320-505’s Public Subnet section, I had set my static IPs, netmask and gateway provided by ATT. So I’ve recently removed my BGW320-505. I’m on a 1 Gbps fiber connection with conventional GPON. I’m able to now obtain an active internet connection using my DFP device (not the WAS-110) but only if I define my UDM SE WAN as DHCP v4. If I populate the same static IPs, netmask and gateway (previously on the BGW320-505), the internet connection drops. When I set the WAN back to DHCP and run whatsmyip, it returns an ATT Public IP I don’t even recognize. And as you’ve said, I can no longer use my additional static IP block given by ATT. For the time being, I’ve returned the BGW320-505 to service with my static IP info until I can figure out how to replicate my static Ip config without the BGW. Will this process achieve what I’m hoping? Thanks for such quick responses.

Interesting. It may not be possible in this case if ATT is returning a public IP that is different every time. For me, I have had the same IP leased to me for over 3 years.

this is specifically for pinging ATT and sort of doing a "keep alive" for your DHCP lease. If you can set it to static in the UDM and your internet stays up, this will work for you. ATT drops your lease on their end after a specific time, which this script will keep alive.

@steRnbear87
Copy link

@BennettStaley can I take you on that offer to help set this up please? I might need help implementing the script.

@BennettStaley
Copy link

@BennettStaley can I take you on that offer to help set this up please? I might need help implementing the script.

For sure, what is a good way to chat with you? I use discord mainly.

@steRnbear87
Copy link

@BennettStaley can I take you on that offer to help set this up please? I might need help implementing the script.

For sure, what is a good way to chat with you? I use discord mainly.

Discord is fine with me. @sternbear

@jtybiz1
Copy link

jtybiz1 commented Feb 23, 2025

I have ATT fiber with a /28 block of static IPs. If I remove my ATT gateway, I can only get an active internet connection if I set the WAN to DHCP v4. Then I’m no longer able to use my static IPs since the Additional IPs option is no longer an option in the UDM SE. I’ve had to add my ATT gateway device back into service to use my static IPs. Does this enable you to setup a WAN with DHCP but still use your static IPs block?

By remove your Gateway... are you using a WAS-110? I am in this case! A way to avoid this script entirely is by setting up Source and Destination NAT rules, though I didn't like how I couldn't route entire networks within the UI,

So here are my steps to properly find your ip, subnet, and gateway and setup this script to ping ATT for DHCP renewal automatically, allowing you to use the UI to set static ips! :)

  1. ssh into your UDM
  2. type in ifconfig
  3. find your eth, mine was eth10. Yours might be 10, 9, or something similar because of the UDM's ports.
  4. it should say something similar to inet xxx.xxx.129.89 netmask 255.255.254.0 --- (inet is your public ip, and make note of your netmask.
  5. plug those values into an ip subnet calculator.

this told me that my ip range was actually xxx.xxx.128.1-xxx.xxx.129.254 So my gateway would be the first one in that range, xxx.xxx.128.1 and, my public ip fell somewhere within it xxx.xxx.129.89 Note the second column. If i had just taken my ip and plugged in a 1 for the last column, it would not work. Your mileage may vary here.

Now we can take the ip, subnet, and gateway we just got and plug them into the static ip section of UI's internet page. Then add your static ips as additional ips.

Lastly follow the instructions about setting up this script, filling in your WAN_PORT and PUBLIC_DHCP_IP (what we found earlier)

this will run automatically and request ATT keep your ip lease running, and allow the UDM to set it up statically.

the second smaller script should be created in /etc/logrotate.d/udhcpc and contain

# Rotate the logs to keep them from filling up the system

/var/log/udhcpc.log {
        weekly
        rotate 1
        size 100K
        compress
        delaycompress
}

which just makes the log size smaller

I can help you set this up privately if you run into trouble and (obviously) don't want to post your public ips. I've been using it since I posted that comment with only one issue where ATT was actually having a service outage and the script failed.

I am in this boat right now. I just bypassed att gateway with was-110 and tried snat and dnat to map my LAN ip to an external ip from the block i bought from att. I'm going to try your method and just want to check how well it worked for you since you set it up? any issues in the long run? Also, should I specify the full /25 range(.1 to .127) in the IP range field of the static IP in udm pro se? or just the usable ones which is .1 to .125?

@usmcfiredog
Copy link

I have ATT fiber with a /28 block of static IPs. If I remove my ATT gateway, I can only get an active internet connection if I set the WAN to DHCP v4. Then I’m no longer able to use my static IPs since the Additional IPs option is no longer an option in the UDM SE. I’ve had to add my ATT gateway device back into service to use my static IPs. Does this enable you to setup a WAN with DHCP but still use your static IPs block?

I was able to get my /28 to work. Let me know if you would like some assistance with this

@usmcfiredog
Copy link

I have ATT fiber with a /28 block of static IPs. If I remove my ATT gateway, I can only get an active internet connection if I set the WAN to DHCP v4. Then I’m no longer able to use my static IPs since the Additional IPs option is no longer an option in the UDM SE. I’ve had to add my ATT gateway device back into service to use my static IPs. Does this enable you to setup a WAN with DHCP but still use your static IPs block?

By remove your Gateway... are you using a WAS-110? I am in this case! A way to avoid this script entirely is by setting up Source and Destination NAT rules, though I didn't like how I couldn't route entire networks within the UI,
So here are my steps to properly find your ip, subnet, and gateway and setup this script to ping ATT for DHCP renewal automatically, allowing you to use the UI to set static ips! :)

  1. ssh into your UDM
  2. type in ifconfig
  3. find your eth, mine was eth10. Yours might be 10, 9, or something similar because of the UDM's ports.
  4. it should say something similar to inet xxx.xxx.129.89 netmask 255.255.254.0 --- (inet is your public ip, and make note of your netmask.
  5. plug those values into an ip subnet calculator.

this told me that my ip range was actually xxx.xxx.128.1-xxx.xxx.129.254 So my gateway would be the first one in that range, xxx.xxx.128.1 and, my public ip fell somewhere within it xxx.xxx.129.89 Note the second column. If i had just taken my ip and plugged in a 1 for the last column, it would not work. Your mileage may vary here.
Now we can take the ip, subnet, and gateway we just got and plug them into the static ip section of UI's internet page. Then add your static ips as additional ips.
Lastly follow the instructions about setting up this script, filling in your WAN_PORT and PUBLIC_DHCP_IP (what we found earlier)
this will run automatically and request ATT keep your ip lease running, and allow the UDM to set it up statically.
the second smaller script should be created in /etc/logrotate.d/udhcpc and contain

# Rotate the logs to keep them from filling up the system

/var/log/udhcpc.log {
        weekly
        rotate 1
        size 100K
        compress
        delaycompress
}

which just makes the log size smaller
I can help you set this up privately if you run into trouble and (obviously) don't want to post your public ips. I've been using it since I posted that comment with only one issue where ATT was actually having a service outage and the script failed.

I am in this boat right now. I just bypassed att gateway with was-110 and tried snat and dnat to map my LAN ip to an external ip from the block i bought from att. I'm going to try your method and just want to check how well it worked for you since you set it up? any issues in the long run? Also, should I specify the full /25 range(.1 to .127) in the IP range field of the static IP in udm pro se? or just the usable ones which is .1 to .125?

I got my /28 to work basically like I had it working when I was on the BGW. I couldn't get the SNAT/DNAT to work, so I just created a /28 DMZ network and put my public servers in that VLAN. Use both the firewall on the UDMP to open only the ports that are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment