Jun 23

wvdial and resolv.conf fileDo you use wvdial and want to set custom DNS, but find that even though you put your DNS address in ‘/etc/resolv.conf’, wvdial always uses the ones provided by your ISP and your entries in the file are dynamically overwritten.

So how do make your entries stick and get used. There are two setting which are required to be changed, you require root previlages to do the changes.
[1] The first one is in the file ‘/etc/wvdial.conf’ , in this file if there is an entry for ‘Auto DNS’, change it to below else add the below line:
Auto DNS = 0

[2] In the file ‘/etc/ppp/peers/wvdial’, either comment (#) or remove the following line:
usepeerdns

Next time you connect using wvdial it should be using the servers mentioned in your ‘/etc/resolv.conf’ file.

Jun 20

IMG : Local DNS Cache TutorialIf you are facing slow connections and slow browsing experience, then you can speed up your browsing by a small factor by caching your DNS queries locally and using it.

But before you go ahead the first question that would surely pop up in your mind is what is this DNS? And what does it do? To answer the first question I would take a simple example of your mobile phone, when you want to call your friends, you first find their name in the contacts and click on dial. You could have directly entered their number and dialled, but remembering a few numbers is possible but not all, hence you store them as contacts in your phone.

In the Internet too we have the same concept each site has an IP address which is nothing but a set of numbers, but it would be very difficult to remember the numbers for each site, so we have a DNS server which basically takes the site name and gives back the IP address for the site.

But why cache it locally? The answer is simple, there are a set of sites you would visit regularly and it takes a few milliseconds to get the IP address, so why not store it the first time it is got and use that the next time you visit the same site again. A few milliseconds may not seem a long time, but when on a slow connection it does make a difference and ultimately result in faster browsing experience.

So in Linux we have a simple light weight program ‘dnsmasq’. The steps mention here are applicable to all Linux Distributions, the only exception being the first step to install the software for which you can use your distributions software installed to install the program. I am using Linux Mint, which is based on Ubuntu so the steps are specific to it.

Follow the following steps to install and get ‘dnsmasq’ running, please note that in the below ’sudo gedit’ is entered in the terminal to open the gedit editor with root previliges, you can use any other editor such as vim. ’sudo’ may not work in all distributions in which case you can just issue ’su’ command and for each of the ’sudo gedit’ you can just run ‘gedit’:

Steps:

  • In Ubunutu/Mint you could just give the below command to install ‘dnsmasq’:
    sudo apt-get install dnsmasq

  • The next step is editing the file ‘/etc/dnsmasq.conf’, you need root previliges to edit this file. In the terminal you can issue the following command:
    sudo gedit /etc/dnsmasq.conf

  • Find the following string in the file:
    #listen-address=

  • Now remove the ‘#’ at the starting, and change it to the below string:
    listen-address=127.0.0.1

  • Save and close ‘/etc/dnsasq.conf’
  • Next you need to edit the file ‘/etc/dhcp3/dhclient.conf’, issue the following command
    sudo gedit /etc/dhcp3/dhclient.conf

  • Search for ‘prepend domain-name-servers’ in the opened file, and change it to below and remove any ‘#’ character if present at the start of the line.
    prepend domain-name-servers 127.0.0.1;

  • Save and close ‘/etc/dhcp3/dhclient.conf’
  • Next you need to edit the file ‘/etc/resolv.conf’, issue the following command to open it:
    sudo gedit ‘/etc/resolv.conf’

  • Add the following to the start of the file:
    nameserver 127.0.0.1

  • Your other DNS servers should come after the above line, for example my file is as below (I use OpenDNS):
    nameserver 127.0.0.1
    nameserver 208.67.222.222
    nameserver 208.67.220.220

Thats it, your local DNS caching server is set up and ready for use, you can issue the following command to restart the ‘dnsmasq’ program:
sudo /etc/init.d/dnsmasq restart

In case you want to test if your queries are actually hitting the local DNS cache, issue the below command a couple of time, you can yourself see the difference it the resolution time:
dig nithinkamath.info

The output is as below, important things to note is the ‘Query time’ and ‘SERVER’, since I had already visited ‘nithinkamath.info’ it gives 0msec:
; < <>> DiG 9.5.1-P2 < <>> nithinkamath.info
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37197
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;nithinkamath.info. IN A

;; ANSWER SECTION:
nithinkamath.info. 9894 IN A 69.73.144.233

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Jun 20 12:30:49 2009
;; MSG SIZE rcvd: 51

If you are still facing any issue, let me know by leaving a comment below.