我正在我的 Virtualbox Debian 机器上测试 dnsmasq DHCP 的配置。在生产中,我希望 dnsmasq 为通过 qemu + libvirt + openvswitch 运行的客户系统提供静态 IP 地址(我已经介绍过了,它们通过 docker 运行,可以正常工作)
dnsmasq 配置:
# Tried both eth0 and br0 for an interface - more about it near bottom
interface=br0
domain-needed
bogus-priv
no-resolv
local=/mydomain.io/
no-poll
no-hosts
domain=mydomain.io
dhcp-range=192.168.1.129,192.168.1.254,255.255.255.128,192.168.1.255,12h
dhcp-option=3
log-queries
log-dhcp
Dockerfile:
FROM alpine:3.5 MAINTAINER [email protected]
# webproc release settings ENV WEBPROC_VERSION 0.1.7 ENV WEBPROC_URL https://github.com/jpillora/webproc/releases/download/$WEBPROC_VERSION/webproc_linux_amd64.gz
# fetch dnsmasq and webproc binary RUN apk update \
&& apk add --no-cache dnsmasq \
&& apk add --no-cache --virtual .build-deps curl \
&& curl -sL $WEBPROC_URL | gzip -d - > /usr/local/bin/webproc \
&& chmod +x /usr/local/bin/webproc \
&& apk del .build-deps
# configure dnsmasq run mkdir -p /etc/default/ RUN echo -e "ENABLED=1\nIGNORE_RESOLVCONF=yes" > /etc/default/dnsmasq
# run! CMD ["webproc","--config","/etc/dnsmasq.conf","--","dnsmasq","--no-daemon","--dhcp-broadcast"]
构建并运行容器的命令:
docker build -t dnsmasq .
docker run -d --name=dnsmasq --volume=/data/dnsmasq.conf:/etc/dnsmasq.conf -p 53:53/udp -p 192.168.56.101:5380:8080 --net host -e "USER=foo" -e "PASS=bar" dnsmasq
docker 日志 dnsmasq
[webproc] 2017/01/11 07:17:09 loaded config files changes from disk
[webproc] 2017/01/11 07:17:09 agent listening on http://0.0.0.0:8080...
dnsmasq: started, version 2.76 cachesize 150
dnsmasq: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify
dnsmasq-dhcp: DHCP, IP range 192.168.1.129 -- 192.168.1.254, lease time 12h
dnsmasq: using local addresses only for domain mydomain.io
dnsmasq: cleared cache
dnsmasq-dhcp: no address range available for DHCP request via eth0
dnsmasq-dhcp: no address range available for DHCP request via eth0
dnsmasq-dhcp: no address range available for DHCP request via eth0
check_dhcp 命令(来自 surveillance-plugins-basic 包)
/usr/lib/nagios/plugins/check_dhcp -v -s 192.168.1.129 -r 192.168.1.130
Requested server address: 192.168.1.129
DHCP socket: 3
Hardware address: 08:00:27:b6:c1:90
DHCPDISCOVER to 255.255.255.255 port 67
DHCPDISCOVER XID: 984913524 (0x3AB49674)
DHCDISCOVER ciaddr: 0.0.0.0
DHCDISCOVER yiaddr: 0.0.0.0
DHCDISCOVER siaddr: 0.0.0.0
DHCDISCOVER giaddr: 0.0.0.0
send_dhcp_packet result: 548
recv_result_1: 548
recv_result_2: 548
receive_dhcp_packet() result: 548
receive_dhcp_packet() source: 10.0.2.2
Result=OK
DHCPOFFER from IP address 10.0.2.2 via 10.0.2.2
DHCPOFFER XID: 984913524 (0x3AB49674)
DHCPOFFER chaddr: 080027B6C190
DHCPOFFER ciaddr: 0.0.0.0
DHCPOFFER yiaddr: 10.0.2.15
DHCPOFFER siaddr: 10.0.2.4
DHCPOFFER giaddr: 0.0.0.0
Option: 53 (0x01)
Option: 1 (0x04)
Option: 3 (0x04)
Option: 6 (0x08)
Option: 15 (0x04)
Option: 51 (0x04)
Option: 54 (0x04)
Lease Time: 86400 seconds
Renewal Time: 0 seconds
Rebinding Time: 0 seconds
Added offer from server @ 10.0.2.2 of IP address 10.0.2.15
No (more) data received (nfound: 0)
Result=ERROR
Total responses seen on the wire: 1
Valid responses for this machine: 1
CRITICAL: Received 1 DHCPOFFER(s), 0 of 1 requested servers responded, requested address (192.168.1.130) was not offered, max lease time = 86400 sec.
当连接到br0使用 check_dhcp 命令后,interface=br0 我甚至没有得到
dnsmasq-dhcp: no address range available for DHCP request via eth0
... 在日志中。与 dnsmasq 连接到 eth0 时相反,我的 dnsmasq 被忽略了,我从 docker dhcp 服务器获得了响应。
最后但同样重要的是我的路线-n
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.128 0.0.0.0 255.255.255.128 U 0 0 0 br0
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
~谢谢你的帮助,非常感谢
答案1
我解决了同样的“挑战”。最后我发现,我没有设置主机服务器的 IP 地址。手动设置 IP 后,dnsmasq 就可以正常工作了。
ip addr add <IP> dev <NET_INTERFACE>