1.dnsmasq介绍
Dnsmasq为小型网络提供网络基础设施:DNS,DHCP,路由器通告和网络引导。它被设计为轻量级且占用空间小,适用于资源受限的路由器和防火墙。它还被广泛用于智能手机和便携式热点的共享,并支持虚拟化框架中的虚拟网络。支持的平台包括Linux(带有glibc和uclibc),Android,* BSD和Mac OS X. Dnsmasq包含在大多数Linux发行版以及FreeBSD,OpenBSD和NetBSD的端口系统中。Dnsmasq提供完整的IPv6支持。

完整介绍请查看
dnsmasq详解&手册
2.应用场景
两台EC20开发板,通过以太网口进行连接通讯,其中一台当服务端,另外一台当客户端并且由服务端分配ip。
服务端使用dnsmasq这个工具来创建DHCP服务器。

部分参数简单说明:
-i, --interface=
指定接口监听。例如监听桥bridge0。
-I, --except-interface=
不要监听指定接口。不要监听lo回环接口。
-z, --bind-interfaces
设置dnsmasq只绑定监听接口。
–dhcp-range=
设置DHCP分配的地址范围
文档详细说明:
Man page of DNSMASQ
3.DHCP客户端配置
dhclient与udhcpc其实是同一个概念的东西,都是用来配置DHCP客户端。
Ubuntu系统使用dhclient进行配置,EC20开发板使用udhcpc进行配置。之前不了解,差点又要去移植dhclient,还好百度了一下。
udhcpc是一个面向嵌入式系统的非常小的DHCP客户端,字母的缩写微- DHCP -客户端(μDHCPc)。
/ # udhcpc -h
udhcpc: option requires an argument -- 'h'
BusyBox v1.23.1 (2019-02-28 19:55:01 CST) multi-call binary.
Usage: udhcpc [-fbqvRB] [-a[MSEC]] [-t N] [-T SEC] [-A SEC/-n]
[-i IFACE] [-P PORT] [-s PROG] [-p PIDFILE]
[-oC] [-r IP] [-V VENDOR] [-F NAME] [-x OPT:VAL]... [-O OPT]...
-i,--interface IFACE Interface to use (default eth0)
-P,--client-port PORT Use PORT (default 68)
-s,--script PROG Run PROG at DHCP events (default /usr/share/udhcpc/default.script)
-p,--pidfile FILE Create pidfile
-B,--broadcast Request broadcast replies
-t,--retries N Send up to N discover packets (default 3)
-T,--timeout SEC Pause between packets (default 3)
-A,--tryagain SEC Wait if lease is not obtained (default 20)
-n,--now Exit if lease is not obtained
-q,--quit Exit after obtaining lease
-R,--release Release IP on exit
-f,--foreground Run in foreground
-b,--background Background if lease is not obtained
-S,--syslog Log to syslog too
-a[MSEC],--arping[=MSEC] Validate offered address with ARP ping
-r,--request IP Request this IP address
-o,--no-default-options Don't request any options (unless -O is given)
-O,--request-option OPT Request option OPT from server (cumulative)
-x OPT:VAL Include option OPT in sent packets (cumulative)
Examples of string, numeric, and hex byte opts:
-x hostname:bbox - option 12
-x lease:3600 - option 51 (lease time)
-x 0x3d:0100BEEFC0FFEE - option 61 (client id)
-F,--fqdn NAME Ask server to update DNS mapping for NAME
-V,--vendorclass VENDOR Vendor identifier (default 'udhcp VERSION')
-C,--clientid-none Don't send MAC as client identifier
-v Verbose
Signals:
USR1 Renew lease
USR2 Release lease
因开发板内部使用桥接的方式,因此udhcpc -i bridge0
/usrdata/grpc_test # udhcpc -i bridge0
udhcpc (v1.23.1) started
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending discover...
Sending select for 172.16.234.92...
Lease of 172.16.234.92 obtained, lease time 3600
开发板接受到DHCP服务器分配的IP。
但为啥ip没有修改成功能?

本文介绍dnsmasq在网络基础设施中的应用,包括DNS、DHCP服务的提供,以及在资源受限设备上的轻量级解决方案。同时,深入探讨了dnsmasq的日志存储配置,DHCP客户端配置细节,及在EC20开发板上实现DHCP自动获取IP的过程。
最低0.47元/天 解锁文章
1735

被折叠的 条评论
为什么被折叠?



