2009-05-10
一、安装
代码: 全选
apt-get install dnsmasq
代码: 全选
sudo vi /etc/dnsmasq.conf
代码: 全选
#-----------------------------------------------------------------------
dhcp-range=192.168.1.50,192.168.1.150,255.255.255.0,12h
dhcp-option=3,192.168.1.1
expand-hosts
domain=myhome.cn
#dhcp-option=44,192.168.1.3
#dhcp-boot=pxelinux.0
dhcp-boot=pxelinux.0,boothost,192.168.1.3 #syslinux启动文件名、tftp服务器IP,与上面注释的两行含义相同
enable-tftp
tftp-root=/home/tftp-root #注意:tftp-root目录、上级目录以及其中所有文件,需要为dnsmasq用户开放read权限,否则tftp会报权限错误。
#-----------------------------------------------------------------------
三、服务启停
取消自启支服务:
代码: 全选
sudo update-rc.d -f dnsmasq remove
代码: 全选
sudo service dnsmasq stop|start|restart
代码: 全选
sudo dnsmasq -d --log-dhcp
四、为Windows PXE安装修正路径符号、文件名大小写问题
问题:
1、windows 路径是\,故tftp 要能识别并在服务端转化为/
2、windows 安装光盘的文件是小写,但是向 tftp 发的文件请求有的大写,有的小写,没有统一起来,tftp要能识别
3、由于dnsmasq不支持rules进行替换,只能其tftp.c源代码进行修改,并重新出dnsmasq执行文件进行替换。
修改:
1、下载源文件dnsmasq-2.47.tar.gz,解开后找到src/tftp.c,找到check_tftp_fileperm函数,把处理逻辑由找不到文件即return NULL;改为替换\->/、文件名转换小写后再试一遍(据说Windows安装文件均为小写文件名,若不是,需要事先将安装文件全转换小写)。
2、修改完成后执行make编译生成dnsmasq
3、覆盖:
代码: 全选
sudo service dnsmasq stop
cp /usr/sbin/dnsmasq /usr/sbin/dnsmasq.default
cp src/dnsmasq /usr/sbin/
sudo service dnsmasq start
代码: 全选
279c279
< char *packet = daemon->packet, *namebuff = daemon->namebuff,*pt;
---
> char *packet = daemon->packet, *namebuff = daemon->namebuff;
289c289
< /*---old default code---
---
>
302,338c302
< */
<
< //for windows:path \ to /,file name to lowercase...Change by XStar 2009.05.10
< //-----------------------------------------------------------------
< if ((fd = open(namebuff, O_RDONLY)) == -1)
< {
< if (errno == ENOENT)
< {
< //--------tolower and try again
< pt = namebuff;
< while(*pt !=0) {
< *pt = *pt=='\\'?'/':*pt;
< *pt = tolower(*pt);
< pt++; }
<
< if ((fd = open(namebuff, O_RDONLY)) == -1)
< {
< if (errno == ENOENT)
< {
< *len = tftp_err(ERR_FNF, packet, _("file %s not found"), namebuff);
< return NULL;
< }
< else if (errno == EACCES)
< goto perm;
< else
< goto oops;
< }
< //--------
< }
< else if (errno == EACCES)
< goto perm;
< else
< goto oops;
< }
< //-----------------------------------------------------------------
< //change end.
<
---
>
代码: 全选
sudo vi /etc/dnsmasq.conf
代码: 全选
dhcp-boot=PXELINUX.0,boothost,192.168.1.3 #syslinux
注意:因为文件名修改小写时是按全路径修改的,必须保证文件存放的路径(从根目录开始至tftp-root目录,以及下面的子目录)、文件名全为小写。