Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Force ubuntu to use certain DNS

  1. #1
    Join Date
    Oct 2009
    Beans
    20

    Force ubuntu to use certain DNS

    I have a VPN tunnel set up, and would like Ubuntu to only do DNS lookups via the VPN provider. I tried to do this:

    Set up static ip, by setting /etc/network/interfaces to this:
    Code:
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto eth0
    iface eth0 inet static
    address 192.168.1.5
    netmask 255.255.255.0
    gateway 192.168.1.1
    network 192.168.1.0
    broadcast 192.168.1.255
    Doing sudo /etc/init.d/networking restart

    Then setting /etc/resolv.conf to
    Code:
    nameserver [dnsserver1]
    Problem is, after a couple of hours resolv.conf get rewritten to:
    Code:
    domain lan
    search lan
    nameserver 192.168.1.1
    And then all DNS queries get sent to my router. What process is changing my DNS settings, and what should I do to set up static DNS?

    Im using Ubuntu 9.04 server.

  2. #2
    Join Date
    Oct 2007
    Location
    Chennai, India
    Beans
    3,803
    Distro
    Ubuntu Development Release

    Re: Force ubuntu to use certain DNS

    Quote Originally Posted by baltazar3 View Post
    would like Ubuntu to only do DNS lookups via the VPN provider
    You can edit your /etc/dhcp3/dhclient.conf, and add the VPN's DNS servers to the "prepend" line; this will ensure that the VPN's DNS servers are used everytime.

    From a terminal:
    Code:
    sudo nano /etc/dhcp3/dhclient.conf
    look for a line like
    Code:
    #prepend domain-name-servers 127.0.0.1;
    and change it to read
    Code:
    prepend domain-name-servers 208.67.220.220 208.67.222.222;
    (Remember to remove the "#" commenting out the line in the beginning, or there will be no effect). Please change the server addresses in red to reflect the DNS servers you want. Multiple addresses are separated with spaces, and the line ends with a ";" semicolon.

    To test, you can either restart, or relogin, or just give the command
    Code:
    sudo /etc/init.d/networking restart
    Cheers,PRShah
    Make your own: Ubuntu, Kubuntu, Xubuntu, Mythbuntu All-in-One Live DVD
    "I never make mistakes; I thought I did, once.. but I was wrong."

  3. #3
    Join Date
    Oct 2009
    Beans
    20

    Re: Force ubuntu to use certain DNS

    Quote Originally Posted by prshah View Post
    You can edit your /etc/dhcp3/dhclient.conf, and add the VPN's DNS servers to the "prepend" line; this will ensure that the VPN's DNS servers are used everytime.
    That was the first thing I tried. I set the prepend directive and also removed domain-name-servers from request line in the same file. But resolv.conf got changed anyway. That's why I thougt that I should use static instead of dhcp.

    It may be something that happens when the vpn line goes down then up again, but I dont know what scripts etc gets called when this happens.

    Edit: Forgot to add that Im using openvpn as a client.

  4. #4
    Join Date
    May 2006
    Location
    Amsterdam
    Beans
    1,731
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Force ubuntu to use certain DNS

    You can also set dns-* options in your interfaces file. Or change the hooks on openvpn so it writes the correct DNS entries.

    Code:
        dns-domain euronet.nl
        dns-search  euronet.nl wanadoo.nl online.nl
        dns-nameservers 194.134.5.5 194.134.0.97
    This makes sure my DNS entries are always correct
    Upgrade Ubuntu | Upgrade unsupported Ubuntu versions | Always backup | Howto upgrade flash
    Minimal CD install | Remove old kernels | My blog | Linux user #462801 | Conscience doth make cowards of us all. -- Shakespeare

  5. #5
    Join Date
    Dec 2009
    Location
    Chennai, India
    Beans
    117

    Re: Force ubuntu to use certain DNS

    Hi,

    I think it would be nice if you look at the "supersede domain-name-servers x.x.x.x;"

    option in /etc/dhcp3/dhclient.conf .


    Further details are there in the following link


    http://ubuntuforums.org/archive/index.php/t-191239.html


  6. #6
    Join Date
    Oct 2007
    Location
    Chennai, India
    Beans
    3,803
    Distro
    Ubuntu Development Release

    Re: Force ubuntu to use certain DNS

    Quote Originally Posted by suseendran.rengabashyam View Post
    "supersede domain-name-servers x.x.x.x;"
    supercede and prepend do _mostly_ the same thing; the primary difference between the two is that the prepend option will ensure that your supplied servers are contacted _first_ for DNS resolution, and then it will fallback to the servers supplied by a DHCP negotiation.

    supercede will not have any fallback; it will always use the supplied DNS servers.

    I don't know how valid it will be when you try to use a non-VPN connection; eg a mobile Internet connection or so.
    Cheers,PRShah
    Make your own: Ubuntu, Kubuntu, Xubuntu, Mythbuntu All-in-One Live DVD
    "I never make mistakes; I thought I did, once.. but I was wrong."

  7. #7
    Join Date
    Oct 2009
    Beans
    20

    Re: Force ubuntu to use certain DNS

    Ok trying with supersede now.

    Am I supposed to use dhcp client at all though when the network interface is configured to be static?

    Its a bit difficult to test as resolv.conf only gets overwritten once every few hours. Is there any way to provoke the dhcp client to try to rewrite resolv.conf? Restarting the network with /etc/init.d/networking restart dosent overwrite it.

  8. #8
    Join Date
    Oct 2009
    Beans
    20

    Re: Force ubuntu to use certain DNS

    I added
    Code:
    supersede domain-name-servers [vpn providers dns]
    to /etc/dhcp3/dhclient.conf

    But resolv.conf still gets overwritten.

  9. #9
    Join Date
    Dec 2009
    Location
    Chennai, India
    Beans
    117

    Re: Force ubuntu to use certain DNS

    Hi,
    I stumbled upon the following link


    http://www.subvs.co.uk/openvpn_resolvconf


    Let me know if this helps you.

  10. #10
    Join Date
    Jan 2006
    Location
    Not heaven... Iowa
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Force ubuntu to use certain DNS

    I saw one thread that solved a similar problem by installing resolvconf and another that solved the same symptoms by removing it.
    Linux User #415691 Ubuntu User #8629
    Iowa Team (LoCo): [Wiki] [Launchpad]
    IRC channel: #ubuntu-us-ia on irc.freenode.net

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •