What Is DNS Cache?

A DNS cache (sometimes referred to as a DNS resolver cache) is temporary info, maintained by a computer's OS, that contains records of all the recent visits and tried visits to websites and different internet domains.



In different words, a DNS cache is simply a memory of recent DNS lookups that your pc will quickly ask when it's attempting to work out a way to load a web site.

Most people only hear the phrase "DNS cache" once it refers to flushing/clearing the DNS cache so as to assist fix an internet connectivity issue. there is a lot of on that at the bottom of this page.

The Purpose of a DNS Cache

The internet depends on the domain name system (DNS) to maintain an index of all public websites and their corresponding IP addresses. you'll think of it as a phone book.

With a phone book, we do not need to memorize everyone's telephone number, that is the solely way phones can communicate: with a number. within the same way, DNS is used so we are able to avoid having to memorize each website's IP address, that is the solely way network equipment will communicate with websites.

This is what happens behind the curtain when you ask your browser to load a web site.

You type in a uniform resource locator like seocop.xyz and your browser asks your router for the IP address. The router contains a DNS server address stored, so it asks the DNS server for the IP address of that hostname. The DNS server finds the IP address that belongs to seocop.xyz and so is able to know what web site you are requesting, after that your browser will then load the suitable page.

This happens for each web site you wish to go to. whenever a user visits a web site by its hostname, the web browser initiates a request out to the web, however, this request can not be completed till the site's name is "converted" into an IP address.


The problem is that despite the fact that there are a lot of public DNS servers your network will use to try to speed up the conversion/resolution method, it's still faster to own a local copy of the "phone book," that is wherever DNS caches come into play.

The DNS cache tries to speed up the method even more by handling the name resolution of recently visited addresses before the request is distributed out to the web.

How a DNS Cache Works

Before a browser issues its requests to the outside network, the pc intercepts each and looks up the domain name within the DNS cache info. The info contains a list of all recently accessed domain names and also the addresses that DNS calculated for them the first time a request was made.

The contents of a local DNS cache will be viewed on Windows using the command ipconfig /displaydns, with results kind of like this:


In DNS, the "A" record is that the portion of the DNS entry that contains the ip address for the given hostname. The DNS cache stores this address, the requested web site name, and several|and several other} other parameters from the host DNS entry.

What Is DNS Cache Poisoning?

A DNS cache becomes poisoned or polluted when unauthorized domain names or IP addresses are inserted into it.

Occasionally a cache might become corrupted because of technical glitches or administrative accidents, however, DNS cache poisoning is usually related to pc viruses or different network attacks that insert invalid DNS entries into the cache.

Poisoning causes client requests to be redirected to the incorrect destinations, sometimes malicious websites or pages jam-packed with advertisements.

For example, if the docs.google.com record from above had a different "A" record, then once you entered docs.google.com in your browser, you would be taken elsewhere.

This poses a huge drawback for fashionable websites. If Associate in Nursing offender redirects your request for Gmail.com, as an example, to an internet site that appears like Gmail however is not, you may find yourself littered with a phishing attack like whaling.

DNS Flushing: What It does and how to try and do It

When troubleshooting cache poisoning or different internet connectivity problems, a pc administrator may need to flush (i.e. clear, reset, or erase) a DNS cache.

Since clearing the DNS cache removes all the entries, it deletes any invalid records too and forces your pc to repopulate those addresses the next time you are trying accessing those websites. These new addresses are taken from the DNS server your network is ready up to use.

So, to use the example above, if the Gmail.com record was poisoned and redirecting you to a weird web site, flushing the DNS may be a smart start to obtaining the regular Gmail.com back again.

In Microsoft Windows, you'll be able to flush the local DNS cache using the ipconfig /flushdns command in a command prompt. you know it works when you see the Windows ip configuration successfully flushed the DNS Resolver Cache or successfully flushed the DNS Resolver Cache message.

Through a command terminal, macOS users ought to use dscacheutil -flushcache, however, know that there's not a "successful" message when it runs, therefore you are not told if it worked. UNIX system users should enter the /etc/rc.d/init.d/nscd restart command.

A router will have a DNS cache similarly, that is why rebooting a router is usually a troubleshooting step. For a similar reason you may flush the DNS cache on your pc, you'll reboot your router to clear the DNS entries stored in its temporary memory.


0 Comments:

Program to Swap Two Numbers in C++

This example contains two different techniques to swap numbers in C++. The first program uses a temporary variable to swap numbers, whereas the second program doesn't use temporary variables.



Example 1: Swap Numbers (Using Temporary Variable)


  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a = 4, b = 10, temp;
  6. cout << "Before swapping." << endl;
  7. cout << "a = " << a << ", b = " << b << endl;
  8. temp = a;
  9. a = b;
  10. b = temp;
  11. cout << "\nAfter swapping." << endl;
  12. cout << "a = " << a << ", b = " << b << endl;
  13. return 0;
  14. }

Output

Before swapping.
a = 4, b = 10

After swapping.
a = 10, b = 4
To perform swapping in the above example, three variables are used.

The contents of the first variable are copied into the temp variable. Then, the contents of the second variable are copied to the first variable.

Finally, the contents of the temp variable are copied back to the second variable which completes the swapping process.

Example 2: Swap Numbers Without Using Temporary Variables.


  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a = 4, b = 10;
  6. cout << "Before swapping." << endl;
  7. cout << "a = " << a << ", b = " << b << endl;
  8. a = a + b;
  9. b = a - b;
  10. a = a - b;
  11. cout << "\nAfter swapping." << endl;
  12. cout << "a = " << a << ", b = " << b << endl;
  13. return 0;
  14. }

Output

Before swapping.
a = 4, b = 10

After swapping.
a = 10, b = 4

Check out these related examples:



0 Comments:

Find the non-repeating number in C++

Non-Repeating Element

c++


Find the first non-repeating element in a given array of integers.

Examples:

Input : -4 2 -4 3 2
Output : 3
Explanation : The first number that does not 
repeat is : 3

Input : 8 3 8 6 7 3
Output : 6

Code:

//Simple CPP program to find first non- repeating element.

#include <bits/stdc++.h>
using namespace std;

int nonRepeating(int arr[], int n)
{
for (int i = 0; i < n; i++) {
int j;
for (j = 0; j < n; j++)
if (i != j && arr[i] == arr[j])
break;
if (j == n)
return arr[i];
}
return -1;
}

int main()
{
int arr[] = { 8,3,8,6,7,3 };
int n = sizeof(arr) / sizeof(arr[0]);
cout << nonRepeating(arr, n);
return 0;
}


Output:
6

0 Comments: