Dynamic IP & lease loss - "callback" mechanism?
I'm playing with NAT, and have a script now that, at startup of my little Linux machine, creates some DNAT rules, which take one incoming special port, and forward that to another interface with a standard e.g. SSH port, so I can talk to this Linux box, from the outside, and to its connected 2nd box, as if it were one machine, but different ports.
The interface to the outside world was, so far, configured with static IP. But it might need configuring for dynamic assignment.
So, my simple startup bash script adding the DNAt rules with iptables, then won't work anymore:
- it can only be called when it's clear that the interface has gotten an IP
- the interface could lose the IP (lease) at some point - then the old DNAt rules need to be deleted (?) and new ones added for the updated IP address of the interface in question.
Is there some sort of callback mechanism in Linux that I can hook into, so it tells me when the IP address was changed/assigned, and I can then react to that by fixing the DNAT rules?