http://debugo.com/dnsmasq/
DNSMASQ is a compact and convenient tool for configuring DNS and DHCP for use in small networks. It provides DNS functionality and optional DHCP capabilities to replace services such as DHCPD (DHCPD service configuration) and bind, which are simpler to configure and more suitable for deployment of virtualization and large data environments.
DHCP service
Some of these key configurations are as follows, configuration files/etc/dnsmasq.conf A very detailed explanation has been given in the comments in. # The network interface address of the Service listener # IF you are want DNSMASQ to listen for DHCP and DNS requests only on # specified interfaces (and the loopback) Give the name of the # interface (eg eth0) here. # Repeat for more than one interface. #interface = # or can specify which interface _not_ to listen on #except-interface= @ or which to listen on (Remember to include 127.0.0.1 if # for this.) listen-address=192.168.1.132,127.0.0.1 # DHCP dynamically allocated address range # Uncomment this to enable the integrated DHCP server, you need # T O Supply the range of addresses available for lease and optionally a lease time dhcp-range=192.168.1.50,192.168.1.150,48h # Static binding of the DHCP service # Always set the name and ipaddr of the host with hardware address # dhcp-host=00:0c:29:5e:f2:6f,192.168.1.2 # Dhcp-host=00:0c:29:5e:f2:6f,192.168.1.201,infinite Unlimited Rental period DHCP-HOST=00:0C:29:5E:F2:6F,192.168.1.201,OS02 DHCP-HOST=00:0C:29:15:63:CF,192.168.1.202,OS03 # Set the default lease # Set the limit on DHCP leases, the default is #dhcp-leaSE-MAX=150 # Leases are kept in the following file # The DHCP server needs somewhere on disk to keep its lease database. # This is defaults to a sane location, but if you want to change it, use # the line below. #dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases # through/etc/hosts to assign the corresponding hostname # Enable the address given for "Judge" in/e Tc/hosts # to is given to a machine presenting the name ' Judge ' when # it asks for a DHCP lease. #dhcp-host=judge # Ignores DHCP requests for the following MAC address # Never an offer DHCP service to a machine whose Ethernet # adress is 11:22:33:44:55:66 #dhcp-host=11:22:33:44:55:66,ignore # DHCP is located in domain # Set the domain for DNSMASQ. This is optional, but if it is set, it # does the following things. # 1) allows DHCP hosts to have fully qualified domain names, as long # as the domain part matches this setting. # 2) Sets the "domain" DHCP option thereby potentially setting the # Domain of all systems configured by DHCP # 3) Provide s the domain part for "expand-hosts" domain=debugo.com # Set default route exit # Dhcp-option Follow RFC 2132 (optioNS and BOOTP vendor Extensions), you can view specific configurations by DNSMASQ--help DHCP many advanced configurations, such as iSCSI connection configurations, can also be given in the Dhcp-option defined by RFC 2132. # option 3 is the default route # Override ' default route supplied by DNSMASQ, which assumes the ' # router is the same machine As the one running DNSMASQ. dhcp-option=3,192.168.0.1 # Set NTP Server. This is set using option name instead of option name # Set the NTP time Server addresses to 192.168.0.4 and 10.10.0.5 #dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 By the-------------------- |
# The network interface address of the Service listener # IF you are want DNSMASQ to listen for DHCP and DNS requests only on # specified interfaces (and the loopback) Give the name of the # interface (eg eth0) here. # Repeat for more than one interface. #interface = # or can specify which interface _not_ to listen on #except-interface= @ or which to listen on (Remember to include 127.0.0.1 if # for this.) listen-address = 192.168.1.132, 127.0.0.1 # DHCP dynamically allocated address range # Uncomment this to enable the integrated DHCP server, Your need # to supply the range of addresses available for lease and optionally a lease time Dhcp-range = 192.168.1.50, 192.168.1.150, 48h # Static binding of the DHCP service # Always set the name and ipaddr of the host with hardware address # dhcp-host=0 0:0c:29:5e:f2:6f,192.168.1.201 # Dhcp-host=00:0c:29:5e:f2:6f,192.168.1.201,infinite Unlimited lease period dhcp-host = 00:0C:29:5E: f2:6f, 192.168.1.201, os02 dhcp-host = 00:0C:29:15:63:CF, 192.168.1.202, Os03 # Set the default lease # set THe limit in DHCP leases, the default is #dhcp-lease-max=150 # Leases are kept in the following file # The DHCP server needs somewhere on di SK to keep its lease database. # This is defaults to a sane location, but if you want to change it, use # the line below. #dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases # through/etc/hosts to assign corresponding hostname # Enable the address given for " Judge "In/etc/hosts" to is given to a machine presenting the name "Judge" where # it asks for a DHCP lease. #dhcp-host=judge # Ignoring DHCP requests for the following MAC addresses # Never offer DHCP service to a machine whose Ethernet # adress is 11:22:33:44 : 55:66 #dhcp-host=11:22:33:44:55:66,ignore # DHCP in domain # Set the domain for DNSMASQ. This is optional, but if it is set, it # does the following things. # 1) allows DHCP hosts to have fully qualified domain names, as long # as the domain part matches This setting. # 2) Sets the "domain" DHCP option thereby potentially setting the # domain of all systems configured by DHCP # 3 provides the domain part for "expand-hosts" domain = Debugo. com # Set default route exit # Dhcp-option Following RFC 2132 (Options and BOOTP vendor Extensions), you can view specific configurations by DNSMASQ--help DHCP many advanced configurations, such as iSCSI connection configurations, can also be provided by the RFC Given in the dhcp-option of the 2132 definition. # option 3 is the default route # Override ' default route supplied by DNSMASQ, which assumes the ' # router is the same machine As the one running DNSMASQ. Dhcp-option = 3, 192.168.0.1 # set NTP Server. This is set using option name rather than option name # Set the NTP time Server addresses to 192 .168.0.4 and 10.10.0.5 #dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5 |
Note: When you assign a host name and IP to a MAC address at the same time, if you write to the two dhcp-host options (shown below), only the one that follows will take effect. The correct options are written as configured. dhcp-host=00:0c:29:5e:f2:6f,192.168.1.201 DHCP-HOST=00:0C:29:5E:F2:6F,OS02
1 2 |
Dhcp-host = 00:0c:29:5e:f2:6f, 192.168.1.201 dhcp-host = 00:0c:29:5e:f2:6f, OS02 |
Restart the client network card. The client NIC has already requested a DHCP lease during the test. So here needs to modify the lease file, let the client regain IP and hostname. [Root@server] vim/var/lib/dnsmasq/dnsmasq.leases 1400240493 00:0c:29:5e:f2:6f 192.168.1.143 os02 * 1400240498 00:0c : 29:15:63:CF 192.168.1.52 os01 *
1 2 3 |
[root @ Server] vim/var/lib/dnsmasq/dnsmasq. Leases 1400240493 00:0c:29:5e:f2:6f 192.168.1.143 OS02 * 1400240498 00:0C:29:15:63:CF 192.168.1.52 os01 * |
Start the DNSMASQ service (IP for server 192.168.1.132) [Root@server] Dnsmasq
1 |
[root @ Server] Dnsmasq |
The following tests are performed on the client:
# Ensure that network interface configuration uses DHCP [root@localhost] cat/etc/sysconfig/network-scripts/ifcfg-eth1 device= "eth1" bootproto=dhcp Ipv6init=no nm_controlled=no onboot= "yes" type= "Ethernet" # Restart Network Service [root@localhost] service network restart shutting down Interface eth0: [OK] shutting down loopback interface: [OK] bringing up loopback interface: [OK] bringing up interf Ace eth0:determining IP information for eth1 ... done. # check IP address [OK] [root@os03] ifconfig eth1 Link encap:ethernet hwaddr 00:0c:29:15: