Jan 19, 2008

UBUNTU: DNS Keep Changing solution



I've encountered problems with DNS at my father's office router. When I connect using windows, there is no problem because windows could find a way to detect the DNS server itself. But with ubuntu, i have to set it manually.

As i connected to the router using DHCP to gain IP, my DNS keep changing to default after certain time. So I had to lock the resolv.conf to prevent my dns from changing. To lock the resolv.conf, I applied this command in terminal:
    • sudo chattr +i /etc/resolv.conf
And everytime I want to connect to other AP(access point), I need to unlock my resolv.conf back. So I have to apply command:
    • sudo chattr -i /etc/resolv.conf
As you can see the different between lock and unlock is the "+" and "-" symbol used before "i" letters. So it's hard for me to type it every time I need to lock and unlock the DNS. I've come to solution and make a bash script. Here is the way to make it simpler:
  • Open up terminal (Application>Accessories>terminal)
  • cd /usr/bin <-- Goto directory /usr/bin where all command was stored.
  • sudo gedit dnslock <-- This will open up text editor for you to write the bash script.
  • Copy this bash script:
    • #!/bin/bash
      #
      # script to record MP3 broadcast stream
      # The command is all on one line ending with a semi-colon
      #
      # $1 is for lock or unlock
      # lock = +
      # unlock = -
      #

      sudo chattr $1"i" /etc/resolv.conf

  • now we have a script called dnslock.
  • sudo chmod 755 dnslock <-- to make script executable.
  • Now, to lock your DNS you just have to apply "dnslock +" command on the terminal without the " quote. In other hands, to unlock it use "dnslock -" command.
Now you can just lock your DNS with simple command. You dont have to memorize the chattr +i or -i anymore. I't simple isnt it?

Happy Ubuntu"ing"!!


Thank you for your unbelievable support on Negative Zero - Permission to read and write blog for nearly 4 years. Don't forget to like Negative Zero on Facebook.
Blogirific.com Blog Directory





Post(s) you might like to read :

Comments
0 Comments

0 comments:

Post a Comment