If a Linux system is returning outdated information about a user, group, hostname, or other network service, the Name Service Cache Daemon (NSCD) may be holding an old result. Clearing the NSCD cache can make the system look up that information again instead of relying on its cached copy. In most cases, you can invalidate one cache with a short command or restart the daemon to clear its caches more broadly.
This guide explains how to clear the NSCD cache safely, which command to use for common databases, how to check whether NSCD is running, and what to try if clearing the cache does not fix the problem.
What Is the NSCD Cache?
NSCD stands for Name Service Cache Daemon. It is a Linux service that caches certain name-service lookups, such as user and group details or host addresses. The information may come from local files, DNS, LDAP, or another configured source, depending on the system.
Caching can make repeated lookups faster and reduce requests to remote services. However, when the underlying information changes, NSCD may continue to serve a cached result until that entry expires or the cache is invalidated. For example, a newly created directory-service account may not appear immediately on a client that has cached an earlier lookup.
NSCD is not the same as every other Linux cache. Clearing its cache does not automatically clear DNS caches maintained by another service, such as systemd-resolved, or caches managed by SSSD. Before troubleshooting, check which name-service caching software your system actually uses.
Clear a Specific NSCD Cache
The usual way to clear an NSCD cache is to run nscd -i followed by the name of the database you want to invalidate. Run the command with administrator privileges:
sudo nscd -i DATABASE
For example, to invalidate the host lookup cache, run:
sudo nscd -i hosts
This tells NSCD to invalidate its cached entries for that database. It does not remove the underlying host records, users, groups, or other source data. On the next lookup, the system can request fresh information from its configured name-service source.
Common database names include:
-
hosts— hostnames and address lookups. -
passwd— user account information. -
group— group information. -
netgroup— netgroup data, if configured and supported. -
services— network service names and port information.
Other databases may be available depending on the NSCD version and configuration. If you are unsure of the accepted names on your system, consult man nscd or check the local command’s help. Use the exact database name expected by your version; a misspelled or unsupported name will not clear the cache you intended.
Commands for Common NSCD Cache Issues
Use the database that matches the stale information. For example, if a hostname resolves to an old address, clear hosts. If a user lookup returns outdated account details, clear passwd. The following commands show common examples:
sudo nscd -i hosts
sudo nscd -i passwd
sudo nscd -i group
sudo nscd -i netgroup
You can invalidate more than one database by running a separate command for each one. This keeps the operation targeted and makes it easier to understand what changed. You generally do not need to invalidate unrelated databases when diagnosing a single stale lookup.
After invalidating a cache, repeat the lookup that was giving you trouble. For instance, check a hostname with getent hosts example.com, a user with getent passwd username, or a group with getent group groupname. The getent command queries configured name-service sources, making it useful for checking what the system currently sees.
Clear NSCD Caches by Restarting the Service
If you want to clear caches more broadly, or the targeted invalidation command does not appear to work, restart the NSCD service. On many systemd-based Linux distributions, use:
sudo systemctl restart nscd
A restart stops and starts the daemon, which clears its in-memory cache state. The service may begin caching lookups again as soon as new requests arrive. Restarting is broader than invalidating one database, so use it when a targeted cache flush is insufficient or when you are troubleshooting several NSCD-managed databases.
On a system that does not use systemd, the service command may be available instead:
sudo service nscd restart
Service names and management commands can differ across Linux distributions. If either command reports that the service does not exist, first check whether NSCD is installed and whether your system uses a different caching service.
Check Whether NSCD Is Installed and Running
Before clearing the NSCD cache, confirm that the daemon is present. You can check its service status with:
systemctl status nscd
If the command reports that the unit cannot be found, NSCD may not be installed, or the system may use another service for name lookups. You can also check whether the command-line utility is available:
command -v nscd
If the utility is installed but the service is inactive, starting it may be necessary before cache invalidation can take effect. For a systemd-based distribution, the command is typically:
sudo systemctl start nscd
Do not install or enable NSCD automatically just to flush a cache. First identify the caching software configured on the machine. Some environments use SSSD for identity lookups, while DNS caching may be handled by systemd-resolved, dnsmasq, or another resolver. Clearing the wrong service will not update the information you are troubleshooting.
How to Verify That the NSCD Cache Was Cleared
There is not always a simple command that displays every entry in the NSCD cache. A practical check is to invalidate the relevant database and then repeat the lookup using the same tool or application that showed the stale result.
For example, to check a host lookup, run:
getent hosts hostname.example
For a user or group lookup, use:
getent passwd username
getent group groupname
You can also inspect NSCD statistics with:
sudo nscd -g
This command displays information about the daemon and its cache statistics. The exact output varies by version, but it can help confirm that NSCD is running and provide context while troubleshooting. Keep in mind that new lookups may repopulate a cache immediately after you invalidate it, so seeing cache activity afterward does not necessarily mean the invalidation failed.
What to Do If Clearing NSCD Does Not Help
If the information is still wrong after you clear the relevant NSCD database, check the source of the data and the service responsible for it. NSCD only affects lookups that pass through it; it cannot correct an incorrect DNS record, a stale LDAP entry, or a local configuration problem.
-
Confirm the lookup result: Use
getentto see what the system’s configured name-service sources return. - Check the source data: Verify the relevant entry in DNS, LDAP, local files, or the directory service itself.
- Check the active caching service: If the machine uses SSSD, systemd-resolved, or another daemon, follow that service’s cache-clearing procedure instead.
-
Review name-service configuration: Check files such as
/etc/nsswitch.confto understand which sources are queried and in what order. - Allow for propagation: Some directory services and DNS changes take time to become visible across clients and servers.
For DNS specifically, clearing NSCD’s hosts database only affects lookups handled through NSCD. If the system uses systemd-resolved, its DNS cache may need to be flushed separately, for example with sudo resolvectl flush-caches. Use the correct command for the service that is actually managing DNS on your distribution.
Is It Safe to Clear the NSCD Cache?
Yes. Invalidating an NSCD cache is generally a routine administrative operation. It does not delete user accounts, group records, DNS records, or other source information. It simply causes relevant lookups to be refreshed rather than served from the existing cache.
There may be a brief performance impact after a cache is cleared because the next lookups must contact their configured sources. On systems that rely on remote identity or name services, those sources need to be reachable for fresh results to be returned. For that reason, a targeted invalidation is often preferable to restarting the daemon when only one kind of lookup is affected.
Frequently Asked Questions
What is the command to clear the NSCD host cache? Run sudo nscd -i hosts. This invalidates the NSCD cache for host lookups.
How do I clear all NSCD caches? A common approach is to restart the service with sudo systemctl restart nscd. This resets the daemon’s in-memory state. Service management commands may differ on non-systemd systems.
Do I need to reboot after clearing the NSCD cache? No. You can normally invalidate a cache or restart NSCD without rebooting the machine.
Why does the old result return after I clear the cache? The information may still be incorrect at its source, another cache may be involved, or the lookup may be repopulating NSCD with the same result. Check the configured data source and caching service.
Conclusion
To clear the NSCD cache on Linux, invalidate the specific database with sudo nscd -i DATABASE, such as sudo nscd -i hosts for host lookups or sudo nscd -i passwd for user information. If you need a broader reset, restart NSCD with your system’s service manager. Then verify the result with an appropriate lookup command such as getent.
If clearing NSCD does not resolve the issue, confirm that NSCD is actually managing the lookup and investigate the underlying data source or any other active cache service. Using the right cache-clearing method helps refresh information without unnecessary changes to the system.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.