Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Post History

60%
+1 −0
Q&A 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 ...

1 answer  ·  posted 2y ago by CanisSomnolentus‭  ·  last activity 1y ago by jimbobmcgee‭

Question networking
#3: Post edited by user avatar CanisSomnolentus‭ · 2022-04-27T17:15:07Z (over 2 years ago)
  • 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 it its copnnected 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:
  • 1. it can only be called when it's clear that the interface has gotten an IP
  • 2. 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?
  • 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:
  • 1. it can only be called when it's clear that the interface has gotten an IP
  • 2. 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?
#2: Post edited by user avatar CanisSomnolentus‭ · 2022-04-27T17:14:36Z (over 2 years ago)
  • I'm playing with NAT, and have a script now that, among others, at startup of my little Linux machine, creates some DNAT rules, which take one incoming special port, and forward that to enother interface with a standard e.g. SSH port, so I can talk to this Linux box, from the outside, and it its copnnected 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:
  • 1. it can only be called when it's clear that the interface has gotten an IP
  • 2. 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?
  • 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 it its copnnected 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:
  • 1. it can only be called when it's clear that the interface has gotten an IP
  • 2. 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?
#1: Initial revision by user avatar CanisSomnolentus‭ · 2022-04-27T17:13:34Z (over 2 years ago)
Dynamic IP & lease loss - "callback" mechanism?
I'm playing with NAT, and have a script now that, among others, at startup of my little Linux machine, creates some DNAT rules, which take one incoming special port, and forward that to enother interface with a standard e.g. SSH port, so I can talk to this Linux box, from the outside, and it its copnnected 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:
1. it can only be called when it's clear that the interface has gotten an IP
2. 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?