当 IP 地址更改(最有可能使用 dhclient 挂钩)时,如何在 (Ubuntu) Linux 计算机上运行脚本?

发布于 2024-07-06 21:53:31 字数 229 浏览 5 评论 0原文

我有一个脚本可以联系一些消息来源并告诉他们“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空名 2024-07-13 21:53:31

我建议将脚本放入 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文