文件/etc/resolv.conf的更改是否立即生效? [英] Are the changes of file /etc/resolv.conf immediate?

查看:7008
本文介绍了文件/etc/resolv.conf的更改是否立即生效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改文件/etc/resolv.conf.但是DNS再次被解析为旧IP,而不是我更新为的旧IP 我希望避免重新启动服务器.有人可以建议解决方法吗?

I am changing the file /etc/resolv.conf. But the DNS is being resolved to the old IP again, not the one I updated to I wish to avoid restarting the server. Can someone please suggest a workaround?

推荐答案

resolv.conf

因为resolv.conf是普通文件,所以正确,但是对您的问题不那么有用的答案很简单是的,文件在任何进程写入后都会立即更改(与系统中的任何其他普通文件).

resolv.conf

Because the resolv.conf is ordinary file, correct, but not-so-useful answer to your question is simple yes, the file is changed immediately when any process writes it (exactly the same as any other ordinary file in the system).

尽管如此,您的 actual 问题可能是您想知道一个正在解析域名的进程是否确实在使用resolv.conf文件中的新数据.

Nevertheless, your actual question is probably that you want to know if a process, which is resolving domain names does immediately use new data in resolv.conf file.

任何进程都可以根据需要读取和解释此文件,但是在绝大部分情况下(除了专用的DNS实用程序),它仅使用

Any process can read and interpret this file as it wishes, but in absolute majority of situations (let's specialized DNS utilities aside) it simply calls system resolver by using, for example, getaddrinfo() or gethostname() functions.

因此,您需要找出系统解析器如何处理这些文件(实际上不仅是resolv.conf,而且是nsswitch.conf,这也会影响整个过程).可以开始查看相应的联机帮助页( resolv.conf nsswitch.conf ).有一种说法是,相应的文件是在首次由进程调用时由解析程序例程读取的.因此,更改不会传播到已经运行的进程.

So you need to find out how does the system resolver handle these files (it is actually not only resolv.conf but nsswitch.conf too, what affects whole process). One can start looking in respective manpages (resolv.conf and nsswitch.conf). There is a statement, that the respective file is read by the resolver routines the first time they are invoked by a process. Therefore, changes would not be propagated to already running processes.

但是这个说法隐含地假设,程序只是调用getaddrinfo()而并不关心其他任何事情.对于大多数简单的实用程序等来说都是如此,但是如果认为适当的话,有多种方法可以更改此行为.

But this claim implicitly assumes, program simply calls getaddrinfo() and does not care about anything else. It would be true for most simple utilities etc., but there are ways to change this behavior if considered appropriate.

res_init() 函数,通常在首次调用时隐式调用到getaddrinfo()之类,但是应用程序也可以显式调用它.可以读取 res_init()函数读取配置文件(请参阅resolv.conf(5))以获取默认域名,搜索顺序和名称服务器地址.复制系统解析器的状态以重新读取这些文件.但这必须是明确的要求.

There is res_init() function, which is normally called implicitly on first call to getaddrinfo() or alike, but application is free to call it explicitly too. One can read The res_init() function reads the configuration files (see resolv.conf(5)) to get the default domain name, search order and name server address(es). So application has a tool to make its copy of system resolver's state to reread these files. But it has to be explicit request.

因此,最后,唯一可能的答案是取决于.对于小型实用程序,可以期望解析程序文件仅读取一次,并且您必须重新启动此实用程序才能获得更新的数据.较大的,运行时间较长的应用程序(例如Web浏览器)可以使用自己的方式查看resolv.conf,并且在认为适当时可以调用res_init().无论如何,这是与应用程序相关的,与网络管理器或其他任何使用新数据填充resolv.conf的系统无关.

So, in the end, only possible answer is it depends. For the small utility, one can expect the resolver files are read only once, and you have to restart this utility to have updated data. Larger, long-running applications (web browser for example) can have its own way of watching resolv.conf and they can call res_init() when deemed appropriate. In any case, this is application-dependent, it has nothing to do with network manager or whichever other system filling resolv.conf with new data.

这篇关于文件/etc/resolv.conf的更改是否立即生效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆