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 pleas
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).
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.
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.
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.
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.
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.
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.