My Vodafone Cable Router often assigns wrong (private) IPs to my upstream interface via DHCP.
Using ifstated we can detect this change and trigger a new DHCP request as long as the wrong IP gets assigned.
cat <<"EOF"> /etc/ifstated.conf
wrong_ip = '( "ifconfig em0 | grep -q 192.168." every 20 )'
state dhcp {
init {
run "logger -p daemon.info -t ifstated entering state dhcp"
}
if $wrong_ip {
run "logger -p daemon.info -t ifstated detected wrong ip state dhcp"
run "sh /etc/netstart em0"
}
if ! $wrong_ip {
run "logger -p daemon.info -t ifstated detected correct ip state dhcp"
}
}
EOF
rcctl enable ifstated
rcctl start ifstated