LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 06-02-2009, 01:56 PM   #1
Unr3a164
Member
 
Registered: Apr 2007
Distribution: Windows 8.1. Attempting to get Slack 14.1 working.
Posts: 147

Rep: Reputation: 16
Manually set DNS.


I am trying to make it so that my laptop ONLY uses a specific DNS server for name resolution. Here is what my current resolv.conf file looks like:


Code:
# Generated by NetworkManager
domain mygateway.net
search mygateway.net
nameserver 192.168.0.1

Now, the router that I am forced to use while at work, is set to a DNS server called "mypubgateway.net". Now, these DNS servers will randomly re-route certain webpages to a spyware/adware site, wsearch.net. I have spoken to my IT department at work, and they refuse to change the DNS settings in the router to something else (such as OpenDNS servers). So I am taking matters into my own hands.

What I am looking to do is to force Linux to look at the OpenDNS servers by default, without having to set a static IP. I still want DHCP to work to assign my laptop an IP so that it can access the network, but use the DNS servers of MY choice. Now, I have edited my resolv.conf file to look like this:

Code:
# Generated by NetworkManager
domain home.net
search home.net
nameserver 208.67.222.220

And I have edited out "domain-name-servers" and "search domains" from my /etc/dhcp3/dhclient.conf file and it looks like this now:


Code:
# Configuration file for /sbin/dhclient, which is included in Debian's
#	dhcp3-client package.
#
# This is a sample configuration file for dhclient. See dhclient.conf's
#	man page for more information about the syntax of this file
#	and a more comprehensive list of the parameters understood by
#	dhclient.
#
# Normally, if the DHCP server provides reasonable information and does
#	not leave anything out (like the domain name, for example), then
#	few changes must be made to this file, if any.
#

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name "<hostname>";
#send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
#send dhcp-lease-time 3600;
#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers 127.0.0.1;
request subnet-mask, broadcast-address, time-offset, routers,
	domain-name, host-name,
	netbios-name-servers, netbios-scope, interface-mtu,
	rfc3442-classless-static-routes, ntp-servers;
#require subnet-mask, domain-name-servers;
#timeout 60;
#retry 60;
#reboot 10;
#select-timeout 5;
#initial-interval 2;
#script "/etc/dhcp3/dhclient-script";
#media "-link0 -link1 -link2", "link0 link1";
#reject 192.33.137.209;

#alias {
#  interface "eth0";
#  fixed-address 192.5.5.213;
#  option subnet-mask 255.255.255.255;
#}

#lease {
#  interface "eth0";
#  fixed-address 192.33.137.200;
#  medium "link0 link1";
#  option host-name "andare.swiftmedia.com";
#  option subnet-mask 255.255.255.0;
#  option broadcast-address 192.33.137.255;
#  option routers 192.33.137.250;
#  option domain-name-servers 127.0.0.1;
#  renew 2 2000/1/12 00:00:01;
#  rebind 2 2000/1/12 00:00:01;
#  expire 2 2000/1/12 00:00:01;
#}

The problem that I am having is that if I reboot, or re-query DHCP, it resets my resolv.conf file to what it is defaultly, and I get the wsearch.net site in place of certain pages. What can I do to use OpenDNS by default, but still be able to query an IP address from the router via DHCP so I don't have to keep going into my resolv.conf file and manually set DNS? I apologize for the long post, and appreciate any help that you can give. Thanks.


Dirk
 
Old 06-02-2009, 02:01 PM   #2
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
How about just copying your resolv.conf file to the /etc/resolv.conf file whenever you log in. Just add teh command to your .bash_profile

cp -f /root/resolv.conf /etc/resolv.conf
 
Old 06-02-2009, 02:22 PM   #3
Unr3a164
Member
 
Registered: Apr 2007
Distribution: Windows 8.1. Attempting to get Slack 14.1 working.
Posts: 147

Original Poster
Rep: Reputation: 16
I was not aware that you could even do that.... lol.. Thanks for the tip.

I think I found it. The .profile file in my home foler. Where do I put the line of code? This is what it currently looks like;

Code:
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

Last edited by Unr3a164; 06-02-2009 at 02:28 PM.
 
Old 06-02-2009, 03:22 PM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
There are some people for whom death by firing squad is genuinely too good, but, if you are going to bring about a long, slow, painful death for your IS department, please be very careful that you don't get caught.

This can be particularly difficult if you indulge in mass murder, so it is probable that alternative solutions are to be prefered in the short term

Err, um, I'm sure that I am ignoring something about your setup, but here are a couple of suggestions/comments:

If you want to modify resolv.conf, ideally you would use the correct interface for that. I thought that there was a sys call for that (modify_resolvconf), but that seems to have been made obsolete by the modular netconfig, which looks to have the capability of doing everything. Potentially. But, I have no idea how to use this new version.

But what about running your own DNS server in caching-only mode? You could still let the system give you an ip via dhcp, but hook your dns cache up to whatever upstream dns data source that you like. Or data sources, so you could have several sources, and only go beyond the first when it times out. (And, while you could use Bind for this, I wouldn't. Dnsmasq/Maradns/Djbdns/Powerdns seem much more appropriate.)
 
Old 06-02-2009, 03:34 PM   #5
Unr3a164
Member
 
Registered: Apr 2007
Distribution: Windows 8.1. Attempting to get Slack 14.1 working.
Posts: 147

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by salasi View Post
There are some people for whom death by firing squad is genuinely too good, but, if you are going to bring about a long, slow, painful death for your IS department, please be very careful that you don't get caught.

This can be particularly difficult if you indulge in mass murder, so it is probable that alternative solutions are to be prefered in the short term

Err, um, I'm sure that I am ignoring something about your setup, but here are a couple of suggestions/comments:

If you want to modify resolv.conf, ideally you would use the correct interface for that. I thought that there was a sys call for that (modify_resolvconf), but that seems to have been made obsolete by the modular netconfig, which looks to have the capability of doing everything. Potentially. But, I have no idea how to use this new version.

But what about running your own DNS server in caching-only mode? You could still let the system give you an ip via dhcp, but hook your dns cache up to whatever upstream dns data source that you like. Or data sources, so you could have several sources, and only go beyond the first when it times out. (And, while you could use Bind for this, I wouldn't. Dnsmasq/Maradns/Djbdns/Powerdns seem much more appropriate.)

I would have absolutely no clue how to do any of that. Lol. As far as the network that I am connecting to, it is not that important. I work in a call center for a major U.S. ISP. We have a couple wireless gateway modems in the call center that Tier 3's (what I am) can use to hook a personal laptop to.

The network and settings on the modem are controlled by the IT department though, and they are stickler for corporate rules (even if that means doing potential damage to employee computers running windows). And corporate rules says not to mess with the default factory settings on the modems, excluding SSID, WEP keys, etc.

I know that setting my own DNS settings in the resolv.conf file will allow me to browse using my own DNS. How to setup that script so that everytime I login the resolv.conf file gets overwritten would would be awesome if I knew how to do it. Thanks for the input though.
 
Old 06-02-2009, 07:04 PM   #6
Unr3a164
Member
 
Registered: Apr 2007
Distribution: Windows 8.1. Attempting to get Slack 14.1 working.
Posts: 147

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by DotHQ View Post
How about just copying your resolv.conf file to the /etc/resolv.conf file whenever you log in. Just add teh command to your .bash_profile

cp -f /root/resolv.conf /etc/resolv.conf

What file do I put that in? ~/.profile?
 
Old 06-03-2009, 04:31 AM   #7
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
What file do I put that in? ~/.profile?
You can't put it in your ~/.profile because the command will run as yourself, and it needs to be run as root. So it will fail.

Put it in /etc/rc.local just before the final line which says exit 0
Then it will be run as root, after the computer has finished booting, and before you have had time to login.

You will need to be root to edit the file /etc/rc.local
 
Old 06-03-2009, 05:04 AM   #8
irabinovitch
LQ Newbie
 
Registered: Sep 2003
Location: Los Angeles, CA
Distribution: Ubuntu, Debian
Posts: 13

Rep: Reputation: 1
Please dont use init script for this.

Many of the suggestions above would work, but are hacks at best. The correct way to configure this is to use dhclient, and I'd highly recommend against any weird init or login scripts to copy/replace resolv.conf.

You were on the right track by trying to edit your dhclient.conf file. dhclient offers the supersede directive as a method for overriding any options set by your DHCP server. Here is a quote from the man page:

Code:
supersede [ option declaration ] ;

If for some option the client should always use a locally-configured value or values rather than whatever is supplied by the server, these values can be defined in the supersede statement.

So in this case, to make it use the OpenDNS name server you provided in your post. You would add the following to your dhclient.conf file.
Dont forget the semi-colon at the end, or it wont work as expected.:

Code:
supersede domain-name-servers 208.67.222.220;
supersede domain-name "home.net";
 
Old 06-03-2009, 05:19 AM   #9
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
There is an option with dhcpcd to not change the /etc/resolv.conf file. So you can put whatever nameserver to your /etc/resolv.conf file and use your own custom nameserver.
 
Old 06-05-2009, 08:02 AM   #10
Unr3a164
Member
 
Registered: Apr 2007
Distribution: Windows 8.1. Attempting to get Slack 14.1 working.
Posts: 147

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by irabinovitch View Post
Many of the suggestions above would work, but are hacks at best. The correct way to configure this is to use dhclient, and I'd highly recommend against any weird init or login scripts to copy/replace resolv.conf.

You were on the right track by trying to edit your dhclient.conf file. dhclient offers the supersede directive as a method for overriding any options set by your DHCP server. Here is a quote from the man page:

Code:
supersede [ option declaration ] ;

If for some option the client should always use a locally-configured value or values rather than whatever is supplied by the server, these values can be defined in the supersede statement.

So in this case, to make it use the OpenDNS name server you provided in your post. You would add the following to your dhclient.conf file.
Dont forget the semi-colon at the end, or it wont work as expected.:

Code:
supersede domain-name-servers 208.67.222.220;
supersede domain-name "home.net";

Wow. This does EXACTLY what I was looking for it to do. If I had just looked a little closer at the configuration file, I would have seen the options myself. But I thank you for providing this info to me. I was getting really tired of going into the resolv.conf file and manually editing it every time I logged in. Thank you so much for showing me that option in the dhclient.conf file. It work's brilliantly. Thank you again.

And thank you for everyone who gave an input. I learned a lot from everyone who posted something. So thank you too.

Last edited by Unr3a164; 06-05-2009 at 08:09 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Manually set ip-adres jonaskellens Linux - Newbie 11 11-15-2008 01:26 PM
Manually having to set essid reverse Debian 3 10-09-2007 06:30 AM
I'm Having Trouble Trying to Manually Set Cap_Sys_Nice Flag... paintballer1016 Linux - General 3 07-19-2007 07:53 AM
Can I set the IRQ's for my devices manually? Galik Linux - Hardware 1 06-05-2004 05:43 AM
How to set up a proxy manually? posat Linux - Newbie 2 04-15-2004 12:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration