-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdhclient-exit-hook.sh
More file actions
38 lines (36 loc) · 1.56 KB
/
Copy pathdhclient-exit-hook.sh
File metadata and controls
38 lines (36 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
######################################################################
## rddclient hook for dhclient (DHCP client)
######################################################################
## Automatically updates DNS when DHCP lease is obtained/renewed.
##
## Installation (Debian/Ubuntu):
## 1. Copy to: /etc/dhcp/dhclient-exit-hooks.d/rddclient
## 2. Make executable: chmod +x /etc/dhcp/dhclient-exit-hooks.d/rddclient
## 3. Restart dhclient or renew lease: sudo dhclient -r && sudo dhclient
##
## Installation (Red Hat/Fedora):
## 1. Copy to: /etc/dhcp/dhclient-exit-hooks
## 2. Make executable: chmod +x /etc/dhcp/dhclient-exit-hooks
##
## Environment variables provided by dhclient:
## $reason - Why dhclient is running (BOUND, RENEW, REBIND, etc.)
## $new_ip_address - New IP address assigned
## $old_ip_address - Previous IP address (if any)
##
######################################################################
# Only run on IP address changes
case "$reason" in
BOUND|RENEW|REBIND|REBOOT)
# Check if IP address actually changed
if [ -n "$new_ip_address" ] && [ "$new_ip_address" != "$old_ip_address" ]; then
logger -t rddclient "DHCP IP change detected: $old_ip_address -> $new_ip_address"
# Update DNS with new IP
if [ -x /usr/local/bin/rddclient ]; then
/usr/local/bin/rddclient --ip "$new_ip_address" 2>&1 | logger -t rddclient
else
logger -t rddclient "Error: /usr/local/bin/rddclient not found"
fi
fi
;;
esac