Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the modification of hosts file by linux does not take effect

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly discusses the solution that the modification of hosts file by inux does not take effect. There is a certain reference value, friends in need can refer to, follow the editor to see the solution.

1. Linux often does not take effect after modifying the hostName of native alias / etc/hosts

Linux often does not take effect after modifying the hostName of the native alias / etc/hosts

For example, our / etc/hosts content is as follows:

# 192.68.1.10 message.xxx.com192.68.1.11 message.xxx.com

But ping message.xxx.com still points to 192.68.1.10.

Correlation

There are two general solutions:

1)。 Restart, which is the most direct, reliable and stable method, if sometimes it is not convenient to restart, you can use the second method.

2)。 Modify the / etc/sysconfig/network file to change the HOSTNAME to the corresponding alias, as follows:

NETWORKING=yesHOSTNAME=host1

Restart the network service after modification

Service network restart (essentially / etc/init.d/network)

3)。 If it still doesn't work after restarting the server, it should be caused by the native dns cache.

Check whether nscd is enabled: ps-ef | grep nscd

Directly shut down the Linux nscd caching service:

/ etc/init.d/nscd stop

2. DNS of Linux

Linux itself does not have dns cache, if you want to use dns cache, you need to install a service program NSCD (name service cache daemon).

Nscd caches three service passwd group hosts, so it records three libraries, two caches for each of the source / etc/passwd, / etc/hosts and / etc/resolv.conf, one for finding records and one for no records. Each cache has a time to live (TTL).

Installation:

Yum install nscd

Modify the configuration file / etc/nscd.conf, turn on dns cache, and modify this line

Enable-cache hosts yes

Dns caching is available only if the nscd service is enabled, otherwise there is no dns cache.

Start, stop, restart services

Service nscd start | stop | restart

Configuration of nscd:

By editing the / etc/nscd.conf file, add the following line to open the local DNS cache:

Enable-cache hosts yes

The configuration on Ali CVM is as follows:

[root@iZ2571ykq ~] # cat / etc/nscd.conf # logfile / var/log/nscd.logthreads 6max-threads 128server-user nscddebug-level 5paranoia noenable-cache passwd noenable-cache group noenable-cache hosts yespositive-time-to-live hosts 5negative-time-to-live hosts 20suggested-size hosts 211check-files hosts yespersistent hosts yesshared Hosts yesmax-db-size hosts 33554432

The relevant parameters are explained as follows:

Logfile debug-file-name: specifies the file name to which debug information is written.

Debug-level value: sets the desired debugging level.

Threads number: this is the number of threads started waiting for requests. A minimum of 5 threads will be created.

Server-user user: if this option is set, nscd will run as that user, not as root. If each user uses a separate cache (- S parameter), this option is ignored

Enable-cache service: enables or disables established service caching.

Positive-time-to-live service value: sets the TTL (time to Live) for items (successful requests) for which service is positive in the specified cache. Value is in seconds. A higher value increases the cache hit ratio, which reduces the average response time, but increases cache consistency issues.

Negative-time-to-live service value: sets the TTL (time to live) for items (failed requests) for which service is negative in the specified cache. Value is in seconds. If there are files owned by uid (user ID) that are not in the system database (for example, when unpacking linux kernel source code as root), performance will be significantly improved; small values should be maintained to reduce cache consistency issues.

Suggested-size service value: this is the size of the internal hash table, and value should keep a prime number for optimization.

Check-files service: enables or disables checking for changes to files belonging to the specified service. These files are / etc/passwd, / etc/group, and / etc/hosts.

Viewing and clearing of nscd

The nscd cache DB file is under / var/db/nscd.

Nscd-g view statistics

Clear the nscd cache:

Nscd-I passwdnscd-I groupnscd-I hosts

Of course, delete the cache or stop the nscd service:

Rm-f / var/db/nscd/hostsservice nscd restart

Or stop the nscd service service nscd stop directly.

After reading this article, can you solve the problem that the linux modification of the hosts file does not take effect? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report