刷新DNS缓存

本文详细介绍了DNS缓存的工作原理及刷新DNS缓存的方法,包括使用命令提示符、禁用并重新启用网卡以及刷新DNS缓存的步骤。同时,文章还探讨了DNS缓存中毒的问题以及预防措施。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在日常工作中,常有人问到域名解析了不是即时生效的嘛,怎么还是原来的呢?答案就是在本地DNS有解析缓存,电脑第一次访问后,在一定的时间内就将其缓存下来,下次访问该域名时电脑通过查找本地DNS缓存,就可以直接知道IP了,而不用再进行域名解析了,这就提高了效率,这就是DNS缓存,而域名更改过解析后,虽然DNS服务器上已经更新,但本地还有DNS缓存,造成还是老的IP,可以通过下面的方法来解决:

刷新DNS缓存的方法一

首先进入命令提示符下(开始——运行——cmd);

先运行:ipconfig /displaydns这个命令,查看一下本机已经缓存了那些的dns信息的,然后输入下面的命令

ipconfig /flushdns

这时本机的dns缓存信息已经清空了,我们可以再次输入第一次输入的命令来看一下,

ipconfig /displaydns

刷新DNS缓存的方法二

直接禁用网卡再启用网卡,这样也可以




How To Flush DNS


When surfing the Internet, a problem that can arise for consumers is getting a number of DNS errors or 404 errors in the web browser despite a working Internet connection. If this is the case, then learning how to flush DNS for your computer’s operating system (OS) is key to restoring the proper quality of service for your computer’s web browsing capability. The act of flushing the DNS removes the local resolution for the website name saved or cached on your computer which can result in a slower initial revisit to the webpage; however, it will eliminate browsing errors encountered from the entry being corrupted.

What is DNS?

The Domain Name System (DNS) is a database system which translates the plain language web address or URL into an IP address. The system was created since it’s easier to remember a domain name such as www.tech-faq.com than 123.456.789.10. Typically, every local computer network will have at least one server that handles DNS requests or queries (called a name server) which performs a caching or quick-lookup function to minimize the time it takes to resolve domain look-ups. If the local name server doesn’t have a domain name stored, it will request the identity from the next name server it knows about and so forth.

History of DNS

Before DNS was invented in 1982, the idea of using a name vice a computer host’s numerical address on the network dates to the ARPANET. Prior to 1982, every computer on the network would have a HOSTS.TXT file that would be retrieved from a computer at SRI. The field would map the names to numerical addresses. The hosts file is still in use on modern operating systems to map 127.0.0.1 to the “localhost.” The rapid growth of computer networks; however, made the hand edited hosts file almost unusable. As a result, Paul Mockapetris invented the Domain Name System in 1983 and wrote the first implementation. The original implementation was subsequently published as an IETF standard and has been superseded since that time. The first Unix implementation of DNS was completed in 1984 by Douglas Terry, David Riggle, Mark Painter, and Songnian Zhou referred to as BIND (Berkeley Internet Name Domain) server. BIND would later be ported to Windows NT in the early 1990s.

DNS Cache Poisoning

Similar to other fundamental Internet constructs, the Domain Name System was not originally designed to be secure. DNS cache poisoning is the term used to describe a data integrity or security compromise in DNS. The vulnerability occurs when data gets introduced to DNS cache that did not come from or originate with an authoritative DNS source. This can occur from a malicious attack or from a bad or misconfiguration of DNS cache. Once a DNS server has received the non-authenticated information and caches or saves to the database, it is then considered poisoned when the bad information starts to be supplied to client machines of the server. At the minimum, a poisoned server will send end-users to incorrect websites. During malicious attacks, they may be directed to malicious web pages designed to infect the client computer or pretend to be legitimate websites designed to steal user’s information and/or money.

Preventing DNS Cache Poisoning

Many of the traditional DNS cache poisoning attacks are prevented by making DNS servers trust the information passed to them by other DNS servers less. This is accomplished by ignoring DNSrecords that are returned to the requesting server not related to the query. The most current version of BIND addresses poisoning attacks in this manner. Additionally, implementing source port randomization for DNS requests (makes requests harder to spoof) along with using cryptographically-secure random numbers to select the source port and nonce significantly reduce the probability of DNS attacks. Secure DNS or DNSSEC is the current initiative being slowly deployed to fully solve the DNS cache poisoning issue by using electronic signatures and public key certificates to validate the authenticity of data.

Common Problems with DNS

There are wide arrays of DNS issues that can arise at the network administrator or power user level. For the end-user; however, the majority of DNS problems arise from either bad configuration entries or the local computer’s DNS storage requiring flushing. Independent of the type of operating system, many home computer users will input the DNS Server for their respective Internet Service Provider (ISP) incorrectly resulting in a failed Internet connection. Each ISP will have a slightly different configuration process; however, the IP address of the DNS server for your home network to use will be provided on registration for service. Many times the ISP will use the address for their actual DNS server, where others it will be the same as the Gateway IP for the service (also the IP address of the router).

How to Flush DNS in Windows Using the Command Prompt

Step 1 – Close all open web browsers and applications on your computer.

Step 2 – Open the Windows command prompt by selecting the “Start” menu and entering “cmd” in the search text field box followed by clicking the “enter” key.

Step 3 – At the command prompt, enter “ipconfig /flushdns” followed by pressing the “enter” key. After a moment, Windows will display a message similar to: “Successfully flushed the DNS ResolverCache.” Once the message is displayed, the DNS will be flushed removing all incorrect entries.

Step 4 – View the DNS resolver cache by entering, “ipconfig /displaydns” at the command prompt followed by clicking the “Enter” key.

How to Turn Off DNS Caching in Windows

If clearing DNS cache does not solve frequent DNS errors on the computer running Microsoft Windows, client-side DNS caching can be disabled. When DNS caching on the client disabled, your computer will still be “usable,” but just not as efficient or “fast” as it is with the service turned on and working properly.

Step 1 – Open the Windows command prompt by selecting the “Start” menu button and entering “cmd” in the search text field followed by pressing the “enter” key on your computer.

Step 2 –  Enter “net stop dnscache” or “sc servername stop dnscache” at the command prompt followed by pressing the “enter” key on your computer. DNS caching will be disabled until the next time the computer is restarted or rebooted. In order to make the change permanent, the DNS Client Service will need to be changed to disabled using the Microsoft Service Controller or

Services tool.

Steps to Stop DNS Client Services in Windows Using the Services Tool

Step 1 – Open the Windows command prompt. Then, input services.msc at the command prompt and press the enter key.

Step 2 – Locate the “DNS Client” application and double click the program icon.

Step 3 – Select the “Stop” menu button. Conversely, the application can be restarted in the same location of the services user interface.

Changing DNS Cache Settings in Windows

An alternative method that can be used to modify Windows DNS caching on the client-side is to change two of the registry entries in the registry associated with the service.

Step 1 – Select the “Start” menu button and enter “regedit” in the search text field followed by pressing the “enter” key.

Step 2 – Click the “Edit” and “Find”  and enter “DNSCache” or use the menu on the left hand side of the editor to locate: HKEY_LOCAL_MACHINESYSTEM -> CurrentControlSet -> Services -> Dnscache -> Parameters.

Step 3 – The MaxCacheTTL is the maximum amount of time that Windows will cache a DNS lookup. The default value at the time of this writing is 86,400 seconds. You can change this entry to 1 to force windows to clear the cache every second. This can result in a negative performance drop on your computer.

Step 4 – Another registry key setting that can be changed is MaxNegativeCacheTTL which is the maximum amount of time that a failed DNS result will be cached. This is normally set to 900 seconds, but if you change it to 0, Windows will not store failed look-ups.

*Note, the path to the DNS cache registry key will be slightly different based on the version of Windows installed on your computer. Modifying the registry should be done with caution and not by those who lack significant computer experience.

How to Flush DNS in Mac OS X

If you are an Internet or web developer or do a fair amount of administrator tasks on your Mac, then the requirement to flush DNS cache will arise. Depending on what version of the OS is installed on your computer (Leopard vs Tiger), there will be a slightly different command to flush DNS.

Step 1 – If Mozilla Firefox is installed on your computer, exit the application if it is open.

Step 2 – Open the terminal on your computer.

Step 3 – On a computer running Lion (Mac OS X 10.5, 10.6, or 10.7) enter the following command followed by pressing the “return” key:

dscacheutil –flushcache

Step 4 – In Mac OS X 10.4 Tiger, enter the following command followed by pressing the “return” key:

lookupd –flushcache

How to Flush DNS in Linux

In many builds of Linux the nscd daemon is used to manage the client DNS cache. For builds that use this method, restarting the nscd daemon is the primary means to flush DNS cache. Other builds of Linux may run BIND or dnsmasq as the primary name service.

Steps to Flush NSCD DNS Cache

NSCD is used to speed up consecutive access to the same data and improve overall system performance.

Step 1 – Enter “$sudo /etc/init.d/nscd restart and press the “enter” or “return” key.

Step 2 – Once nscd restarts the DNS will be flushed. Alternatively, you can enter “# service nscd restart.”

Steps to Flush DNSMASQ DNS Cache

DNMASQ is used as a lightweight DHCP, TFTP, and DNS server. It was primarily designed to provide DHCP and DNS services to a LAN, accepts DNS queries, and answers them. It is also installed on a number of routers to cache DNS queries or look-ups.

Step 1 – Enter “$ sudo /etc/init.d/dnsmasq restart”

Step 2 – Once dnsmasq restarts the DNS will be flushed.

Steps to Flush BIND Server DNS Cache

Similar to nscd and dnsmasq, to flush DNS cache in BIND simply requires a restart to clear the cache.

Step 1 – Enter “# /etc/init.d/named restart” followed by pressing the “enter” or “return” key.

Step 2 – Once BIND completes restart the DNS will be flushed.

How to Disable Firefox DNS Cache

Unlike other popular web browsers, Firefox runs its own DNS cache separate from the client services on your computer. As a result, if you commonly switch between a VPN, home ISP, or other connections, undesired results may occur if you access services which require use of your VPN, etc. For this reason, when you take actions to fully flush DNS on your computer, FireFox should be closed. If DNS issues persist on your computer and FireFox is your preferred browser, then the answer may lay in disabling DNS Cache in the browser specifically.

Step 1 – Launch Mozilla Firefox on your computer.

Step 2 – Install the Firefox DNS cache plugin.

Step 3 – Right click the “Home” menu button on Firefox and then select the “Customize” menu option.

Step 4 – Locate the “DNS Cache” menu button and then drag it beside the “Home” button on Firefox followed by clicking the “Done” button.

Step 5 – Click the “DNS Cache” menu button whenever you want to have Firefox DNS cache disabled.

Step 6 – Alternatively, you can change the FireFox DNS settings to have the cache expire after 0 seconds. To do so, enter “about:config” in the location bar followed by pressing the “enter” or “return” key. Right click at a blank location on the subsequently displayed record and select “New” and “Integer.”

Step 7 – Enter “network.dnsCacheExpiration” as the preference name with “0” as the integer value. If “network.dnsCacheExpiration” already exists, modify the integer value to “0.” If you want to restore FireFox defaults, simply change the value back to the default of  “3600.” With 0 entered, DNS cache in FireFox will automatically expire on your computer.

Video on How to Flush DNS

The following video provides highlights on how to flush DNS in Microsoft Windows, MAC OS X, and Linux.


<think>好的,我现在需要回答用户关于如何在不同操作系统中刷新DNS缓存的问题。首先,我得回顾用户提供的引用内容,看看有没有相关的信息可以直接使用。 根据引用[1],在Linux上可以通过重启nscd服务或者删除DNS缓存文件来刷新缓存,比如使用`sudo systemctl restart nscd`或者`sudo rm -rf /var/cache/bind/named_dump.db`。引用[2]提到不同Linux发行版可能有不同的方法,需要根据具体情况选择。引用[3]详细说明了Ubuntu上查看和刷新DNS缓存的步骤,可能涉及nscd或者systemd-resolved服务。引用[4]则给出了更多关于nscd的参数和安装方法,以及在Windows中使用`ipconfig /flushdns`的命令。 接下来,我需要将这些信息整理成不同操作系统的步骤。首先,Windows系统比较明确,用ipconfig命令就行。对于Linux,可能需要分发行版来处理,比如Ubuntu可能使用systemd-resolved,而CentOS或RHEL可能用nscd。此外,macOS的部分没有在引用中提到,但根据我的知识,macOS通常使用dscacheutil或者killall命令来刷新DNS缓存。 需要注意的是,用户可能不知道不同Linux发行版之间的差异,所以需要分别说明。例如,Ubuntu 18.04及以上可能默认使用systemd-resolved,而旧版本或某些发行版可能使用nscd或者dnsmasq。此外,有些系统可能没有安装nscd,需要先安装才能使用相关命令。 另外,用户可能关心是否需要管理员权限,所以在命令前加上sudo是必要的。同时,提醒用户谨慎操作,特别是在删除缓存文件时,避免误删其他文件。 最后,生成相关问题的时候,需要考虑用户可能的后续问题,比如检查DNS缓存是否刷新成功,或者遇到问题如何解决等。</think>[系统级指令响应] ### 不同操作系统中刷新 DNS 缓存的方法 #### **Windows 系统** 1. **命令提示符执行**: ```cmd ipconfig /flushdns ``` 此命令会立即清除本地 DNS 缓存[^4]。 #### **Linux 系统**(分发行版) 1. **使用 `systemd-resolved`(Ubuntu 18.04+)**: ```bash sudo systemd-resolve --flush-caches ``` 验证结果:`sudo systemd-resolve --statistics`[^3]。 2. **使用 `nscd` 服务(通用方法)**: ```bash sudo systemctl restart nscd # 重启服务刷新缓存 nscd -i hosts # 直接清除 hosts 缓存[^4] ``` 若未安装 nscd,需先执行: ```bash sudo apt-get install nscd # Debian/Ubuntu sudo yum install nscd # RHEL/CentOS ``` 3. **清除 DNS 缓存文件**(部分系统): ```bash sudo rm -rf /var/cache/bind/named_dump.db # 删除缓存文件[^1] ``` #### **macOS 系统** 1. **终端执行**: ```bash sudo dscacheutil -flushcache sudo killall -HUP mDNSResponder ``` 需组合使用两条命令确保完全刷新。 --- ### **操作注意事项** - **权限要求**:所有命令均需管理员权限(Windows 需以管理员身份运行 CMD)。 - **服务依赖性**:Linux 中若未启用 `nscd` 或 `systemd-resolved`,相关命令可能无效。 - **谨慎操作**:直接删除文件可能影响服务稳定性[^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值