当 IP 地址更改(最有可能使用 dhclient 挂钩)时,如何在 (Ubuntu) Linux 计算机上运行脚本?
我有一个脚本可以联系一些消息来源并告诉他们“IP 地址 XXX.XXX.XXX.XXX 是我当前的”。 我的测试 Web 服务器通过 DHCP 拥有动态 IP 地址,除此之外,它还需要在 IP 地址更改时更新 DDNS 条目。 然而,这并不是它唯一做的事情,所以我需要运行我自己的自定义脚本。
我怀疑这可以通过附加为给定 dhclient 挂钩运行的脚本来实现。 但是我仍然需要知道应该使用哪个钩子以及如何使用。
I have a script which contacts a few sources and tell them "the IP-address XXX.XXX.XXX.XXX is my current one". My test web server has a dynamic IP-address through DHCP and amongst other things it needs to update a DDNS entry when its IP-address changes. However it's not the only thing it does, so I will need to run my own custom script.
I suspect that this is possible by a attaching the script to be run for a given dhclient hook. However I still need to know which hook I should use, and how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议将脚本放入 dhclient-exit-hooks.d 中。 因为如果地址更改已经完成,您应该只更改 DDNS 条目。 但是,我不确定如果分配地址失败,是否会调用 dhclient-exit-hooks。
编辑:手册页(man dhclient-script)说,exit-hooks 脚本将在 shell 变量(exit_status)中获取退出代码。 所以你可以检查一下。
I would recommend to put the script into dhclient-exit-hooks.d. Because you should just change the DDNS entry, if the address change has been finished. However, I am not sure if dhclient-exit-hooks are called, if assigning an address fails.
Edit: The man pages (man dhclient-script) says, that the exit-hooks script will get the exit code in a shell variable (exit_status). So you could check it.