-
-
Save djdembeck/4c2f251bf7a53a0ff9e1de2305043e40 to your computer and use it in GitHub Desktop.
#!/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 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.
@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
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! :)
- ssh into your UDM
- type in
ifconfig
- find your eth, mine was eth10. Yours might be 10, 9, or something similar because of the UDM's ports.
- 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.- 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 itxxx.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 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
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! :)
- ssh into your UDM
- type in
ifconfig
- find your eth, mine was eth10. Yours might be 10, 9, or something similar because of the UDM's ports.
- 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.- 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 itxxx.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.
@BennettStaley can I take you on that offer to help set this up please? I might need help implementing the script.