Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i have a slackware box acting as a gateway for a lan...
the slackware box has a dhcp-configured connection to the internet...
it is also running dhcp-server and dnsmasq (for the machines on the lan)...
but i'd like to know how to make the slackware box use it's local dnsmasq also, while still obtaining all it's regular configuration from the ISP's dhcp server...
i want someone who sits to use the slackware box (yes, it's an X workstation) to be able to enjoy dnsmasq's awesome dns request cache (just like if they were on one of the other machines on the lan), instead of dealing directly with my ISP's dns servers ...
if i put that in /etc/resolv.conf, won't it be overwritten next time the dhcp client runs??
should i be lookng for a way to add "nameserver 127.0.0.1" to the top of my /etc/resolv.conf after the dhcp client has written to /etc/resolv.conf???
also, i believe dnsmasq looks at the /etc/resolv.conf of the machine it's running on, right (please correct me if i'm wrong)??
so i'm wondering if perhaps this can have a negative effect on dnsmasq... if dnsmasq detects "localhost" as a "real" dns server then could it end up in some kinda infinite loop??
or perhaps dnsmasq ignores localhost as a real (isp) dns server when found in /etc/resolv.conf??
As my connection is via ppp, I redirected resolv-file to the one assembled by ppp. I was looking the case of the dhcp client and I suggest you to read "man dhclent-script", where it talks about HOOKS to not overwrite the /etc/resolv.conf.
Hi,
In your last post you referenced dhcpcd as you dhcp client. The dhclient-script is for another dhcp client named "dhclient". For dhcpcd you have to edit the script "/etc/dhcpc/dhcpcd-ethN.exe, where N is your ethernet. Look at "man dhcpcd".
i took a good look at the dhcpcd manual and at that script, but no luck...
i think that script only runs when dhcpcd detects a change in the ip address, mine looks like this:
Code:
bash-2.05b# cat /etc/dhcpc/dhcpcd-eth0.exe
PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
#!/bin/sh
echo "(dhcpcd) IP address changed to $1" | logger
for now, i could still use dnsmasq locally by setting the dns servers in the alternate location manually, but if/when my isp changes the dns server addresses i would be out of business...
Hi man,
It is not so hard! All the variables got from the dhcp server are in the an script like file which is the first parameter to the dhcpcd-eth0.exe. The second parameter tell us about the reason it is called, "up", "down" or "new" for a lease renew. The third parameter is just for debug. So, all we need is to interpret the passed file and generate our resolv.conf. Here go my suggestion:
Code:
Modelo:/mnt/ref/tmp/dhcpcd/etc/dhcpc# cat dhcpcd-eth0.exe
#!/bin/sh
echo "(dhcpcd) IP address changed to $1" | logger
#
# man 8 dhcpcd states parameter
# - 1 is <HostInfoFilePath>
# - 2 is <up|down|new>
# - 3 is -d if debug
#
case $2 in
up|new) # We want to check for dns changes when
# starting up or renewing the lease
if [ -e "$1" ] # File exists ?
then
. "$1" # source it
fi
if [ "$DNS" != "" ] # Variable DNS declared?
then
RES=/etc/resolv.conf.masq # destination file
TMP=/tmp/resolv.conf.$$ # temporary file
[ -e $TMP ] && rm $TMP # remove it if it exists
for i in `echo $DNS | sed 's/,/ /g'` # process dns server addresses
do
echo nameserver=$i >>$TMP # create the resolv.conf line
done
# if destination file does not exist or
# destination file differs
if [ ! -e $RES ] || \
[ `diff $TMP $RES | wc -l` -ne 0 ]
then
mv $TMP $RES # replace destination with the new one
else
rm $TMP # clean temporary file
fi
fi
;;
*)
;;
esac
Of course, you have to use the "-R" for not replacing the current resolv.conf.
there's a file called pathnames.h in the tarball...
i simply changed /etc/resolv.conf to /etc/resolv.masq, i recompiled, and it did the trick...
Quote:
bash-2.05b# cat pathnames.h
/*
* dhcpcd - DHCP client daemon -
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <yoichi@fore.com>
* Copyright (C) 1998 Sergei Viznyuk <sv@phystech.com>
*
* Dhcpcd is an RFC2131 and RFC1541 compliant DHCP client daemon.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
i just ran into this thread and i thought i'd share the method i eventually ended-up using for this issue (in case it might be useful for someone else)...
instead of editing scripts and/or source code, i simply added these three lines to my /etc/rc.d/rc.local file:
Hi win32sux,
Nice to read you again! Your method is simple and smart. However you may run into problems if you stay on line long enough to get a renew. As your resolv.conf is different from the newly created, dhcpcd will give you another without you take notice.
I did a look into dhcpcd source and it appears the script runs after dhcpcd writing of a new resolv.conf. So you can put your commands in the dhcpcd script to make sure even if you get a renewal of the lease, you stay with the proper resolv.conf and resolv.dnsmasq.
well, you're absolutely right - the main issue with my method is that upon dhcp renewal localhost would once again be using the ISP's nameservers... i was actually aware of this, but because the machine in question is an X workstation which gets turned on and off sporadically, it didn't really affect me at all... i've actually never seen a renewal on this machine...
however, i think you're idea is great, and i will do as you suggested...
i'm gonna put my three lines in the dhcpcd script so that they are run right after any renewal... this would make the solution more apt for anyone trying this on a real dhcp gateway which is online 24/7...
i'll post the location where i placed the lines once i get it right...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.