Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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 ...
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.
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".
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:
Modelo:/mnt/ref/tmp/dhcpcd/etc/dhcpc# cat dhcpcd-eth0.exe
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 ?
. "$1" # source it
if [ "$DNS" != "" ] # Variable DNS declared?
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
echo nameserver=$i >>$TMP # create the resolv.conf line
# if destination file does not exist or
# destination file differs
if [ ! -e $RES ] || \
[ `diff $TMP $RES | wc -l` -ne 0 ]
mv $TMP $RES # replace destination with the new one
rm $TMP # clean temporary file
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...
bash-2.05b# cat pathnames.h
* dhcpcd - DHCP client daemon -
* Copyright (C) 1996 - 1997 Yoichi Hariguchi <email@example.com>
* Copyright (C) 1998 Sergei Viznyuk <firstname.lastname@example.org>
* 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.
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...