ubuntu 中 /etc/hosts 文件的高级工作

0 networking hosts

我有一个分布式 Java 应用程序,并且具有与 NFS 共享的网络连接。该应用程序正在使用 DNS 连接到网络共享。

我们想测试应用程序运行时的网络连接故障。因此,我们/etc/hosts在应用程序运行时编辑文件,模拟网络连接失败。我们得到了预期的结果。

我只是不明白如何使用hosts新(假)IP 地址编辑文件并使用已运行进程的新 IP 进行实时更新。

有人可以解释一下操作系统中的实现以及新 IP 如何映射到已经运行的进程吗?

操作系统是否hosts一直监视文件并更新,还是在创建新连接时检查文件?

Dav*_*vid 5

直接来自hosts联机帮助页

Modifications to this file normally take effect immediately, except in
cases where the file is cached by applications.
Run Code Online (Sandbox Code Playgroud)

保存文件会触发重新读取。