|
楼主 |
发表于 2012-3-30 03:09
|
显示全部楼层
[ 本帖最后由 buypro2 于 2012-3-30 04:16 编辑 ]
有个令类方法。
就是再装一份optware版本的dnsmasq 。
http://www.dd-wrt.com/phpBB2/viewtopic.php?p=660694
Posting this because it took me a bit of digging to figure out and I did not find a tutorial or howto anywhere else. There may be better ways, if that is the case please let me know - I am still a dd-wrt newb. Hopefully it helps a few of you. It might belong on the wiki but that does not want to let me create an account so I'm posting it here for now.
Here is how I did it and why:
Why: I had a dying computer that was hosting dnsmasq for my SOHO LAN. I have a few computers, some Android devices, VOIP, DNLA, blah blah blah going and I like dnsmasq for the control it gives me over DHCP and DNS. Caching DNS helps as well. I need to retire this poor old PC and move on. I'm not sure why but the built in dnsmasq did not like the configuration options I had in my old dnsmasq.conf and I got tired of trying to figure out what the problem was and decided to just use the optware version which as of this writing is the latest and greatest and is also the same as was running on my Ubuntu computer that was dying. I also had some static addresses that I wanted to assign, etc.
How: I upgraded the E3000 to the lastest 18xxx mega series software and then installed optware following the directions from Optware The Right Way on the wiki. http://www.dd-wrt.com/wiki/index.php/Optware%2C_the_Right_Way
Everything works fine for me at this point except dnsmasq which as I said above, doesn't like whatever I am trying to do.
Once installing optware core was complete I ran into a couple of challenges.
1. How to get the new dnsmasq installed? I'm new to optware and so wasn't real sure.
2. How to get the installed optware version of dnsmasq working?
3. How to get the default to stay shutdown?
4. How to get the optware version to run at startup.
So, I am not a newb when it comes to linux but as I said I am new to dd-wrt and optware.
The blow by blow:
To find out what packages are available (optware must be installed and working) use ipkg:
Code:
ipkg list
That is going to be a ton of crap so try this:
Code:
ipkg list|grep dnsmasq
and you should get this:
Code:
root@fsmsouth:~# ipkg list|grep dnsmasq
dnsmasq - 2.59-1 - DNS and DHCP server
OK, so now install it:
Code:
root@fsmsouth:~# ipkg install dnsmasq
Installing dnsmasq (2.59-1) to /opt/...
Downloading http://ipkg.nslu2-linux.org/feed ... q_2.59-1_mipsel.ipk
Configuring dnsmasq
To complete the installation, you should check /opt/etc/dnsmasq.conf,
and then run /opt/etc/init.d/S56dnsmasq to start dnsmasq.
Now we have it installed but the default dnsmasq supplied with dd-wrt is still running. To complete the next few step it would be helpful if you were using a wired ethernet connection to the router and using a static IP address in case something goes wrong. Something like dnsmasq or the built in dhcp not giving out addresses on the network while you are messing with the router. Just saying you might want to stop right here and assign yourself a fixed IP for a few minutes.
So now that we are using a wire and have a fixed IP (you were paying attention right?), we will proceed.
Go to Setup->Network Address Server Settings (DHCP)
Disable DHCP Server and all DNSMasq options here
Save (down at the bottom of the page)
Go to Services->DNSMasq and disable dnsmasq
Save
Apply Settings
Wait for the router to let you back in (right about now you are wishing you had a static IP address since DHCP is now completely off and dns is shutdown and if you don't have a static ip you are bummed out and I am the honeybadger )
We need a working dnsmasq config and we want it to survive subsequent dnsmasq upgrades etc. The default conf file for the optware version is /opt/etc/dnsmasq.conf so, ssh to the router (or telnet if that is your thing):
Code:
cp /opt/etc/dnsmasq.conf /opt/etc/dnsmasq.local.conf
touch /opt/etc/dnsmasq.local.resolv
touch /opt/etc/dnsmasq.local.hosts
and now lets edit the default file with vi (you are a cool kid eh? or do you use some other editor?)
Code:
vi /opt/etc/dnsmasq.conf
go to the last line of the file and add this (or be a wild child and put it as the first line, it doesn't matter, the whole of the default file is commented out)
Code:
conf-file=/opt/etc/dnsmasq.local.conf
":wq" i.e. save and exit
Now edit /opt/etc/dnsmasq.local.conf and configure it however you want. Most of my version is below, all comment lines are stripped out for your enjoyment (grep -ve "^\#" dnsmasq.local.conf |grep -v '^\W*$')
Code:
domain-needed
bogus-priv
log-facility=/opt/var/log/dnsmasq
resolv-file=/opt/etc/dnsmasq.local.resolv
local=/localnet/
local=/localdomain/
local=//
local=/local.net/
no-hosts
addn-hosts=/opt/etc/dnsmasq.local.hosts
expand-hosts
domain=local.net
dhcp-range=192.168.1.100,192.168.1.199,1d
dhcp-script=/opt/bin/logger
filterwin2k
dhcp-option=66,192.168.1.50
dhcp-option=150,192.168.1.50
dhcp-lease-max=100
dhcp-leasefile=/opt/etc/dnsmasq.leases
dhcp-authoritative
cache-size=300
neg-ttl=3600
local-ttl=300
version
log-async=50
log-dhcp
Yes, I know, /opt/etc/dnsmasq.leases is not really the places to be writing things to but I like having all my dnsmasq stuff in one place - I'm lazy that way.
contents of /opt/etc/dnsmasq.local.hosts - this can be used to replace /etc/hosts when using dnsmasq - but read the man pages for details
Code:
192.168.1.50 copper
contents of /opt/etc/dnsmasq.local.resolv
Code:
# these are the dns servers at opendns.com - put whatever name servers you want here
nameserver 208.67.222.222
nameserver 208.67.222.220
Now we need a service to run. ipkg will have installed a startup script in /opt/etc/init.d called S56dnsmasq but it will not run on my Csico E3000 - it pukes out some errors and doesn't list correctly as a service, have proper start, stop, and status options so I backed up the original, copied the init script from portmap and changed it to run dnsmasq - it could probably be cleaned up even more but this one works for me, we'll also create a link to a shutdown script while we are at it:
Code:
mv /opt/etc/init.d/S56dnsmasq /opt/etc/init.d/T56dnsmasq
cp S55portmap S56dnsmasq
ln -s /opt/etc/init.d/S56dnsmasq /opt/etc/init.d/K56dnsmasq
now edit it and change all occurrences of portmap to dnsmasq. (for the cool kids using vi :1,$s/portmap/dnsmasq/g )
Code:
#!/bin/sh
prefix=/opt
export PATH=${prefix}/bin:${prefix}/sbin:${prefix}/usr/sbin:/sbin:/bin:/usr/sbin:/usr/bin
export LD_LIBRARY_PATH=${prefix}/lib:${LD_LIBRARY_PATH}
NAME=dnsmasq
PROC=dnsmasq
BIN=${prefix}/sbin/dnsmasq
SCRIPT=${0##*/}
if [ -z "$1" ] ; then
case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
S??*) rc="start" ;;
K??*) rc="stop" ;;
*) rc="usage" ;;
esac
else
rc="$1"
fi
# Start/Stop/Status dnsmasq
case "$rc" in
status)
if pidof ${PROC} >/dev/null ; then
echo "${NAME} is running"
else
echo "${NAME} is not running"
fi
;;
start)
if pidof ${PROC} >/dev/null ; then
echo "${NAME} already running"
else
optlog "${SCRIPT}" "Starting ${NAME}:"
${BIN}
fi
;;
stop)
if ! pidof ${PROC} >/dev/null ; then
echo "${NAME} is already stopped"
else
optlog "${SCRIPT}" "Stopping ${NAME}:"
n=1
while [ $n -lt 20 ] ; do
killall ${PROC} >/dev/null 2>&1
pidof ${PROC} >/dev/null || break
sleep 1
let n+=1
done
killall -9 ${PROC} >/dev/null 2>&1
fi
;;
restart)
"$0" stop
sleep 1
"$0" start
;;
*)
echo "Usage: $0 (start|stop|restart|status|usage)"
;;
esac
exit 0
make it executable set it to on and start it, check that it is actually running:
Code:
chmod 755 /opt/etc/init.d/S56dnsmasq
service dnsmasq on
service dnsmasq start
service dnsmasq
ps aux|grep dnsmasq
reboot the router and make sure that dnsmasq comes back - if you set up log-facility and version options in the config you should see messages from dnsmasq in the logs
Thats's it. YMMV |
|