Configure DNS and DHCP services in CentOS 7

Source: Internet
Author: User
Tags nameserver

Configure DNS and DHCP services in CentOS 7
Install Dnsmasq

  • Dnsmasq provides DNS caching and DHCP services. As a domain name resolution server (DNS), dnsmasq can cache DNS requests to speed up the connection to accessed URLs. As a DHCP server, dnsmasq can be used to assign Intranet IP addresses and provide routes for LAN computers. The DNS and DHCP functions can be implemented simultaneously or separately. Dnsmasq is lightweight and easy to configure. It is suitable for individual users or networks with less than 50 hosts. In addition, it also comes with a PXE Server.
  • DHCP service Overview: Name: DHCP-Dynamic Host Configuration Protocol
    Function: DHCP (Dynamic Host Configuration
    Protocol, Dynamic Host Configuration Protocol) is a LAN network Protocol. It works with UDP and has two main purposes:
    1. automatically assign IP addresses, host names, DNS servers, and domain names to internal network or network service providers
    2. configuration and other services for integrated management. For example, unattended Server Installation features: in C/S mode, the client/server automatically allocates IP addresses to facilitate management.
    DHCP does not lease the same IP address to two hosts at the same time. The DHCP administrator can restrict a specific computer from using a specific IP address;
    You can set many options for each DHCP scope. When the client moves between different subnets, you do not need to reset the IP address. You can automatically obtain the IP address each time. Disadvantages of DHCP:
    When multiple servers exist on the network, one DHCP server cannot find the IP addresses that have been rented out by other servers;
    The DHCP server cannot communicate with clients across vrouters, unless the vro allows BOOTP protocol forwarding. Port: DHCP service use: port 67 (bootps)
    68 (bootpc ). Example: View
    # Cat/etc/services | grep boot
    Install and configure Dnsmasq
[root@vdevops ~]# yum -y install dnsmasq
[Root @ vdevops ~] # Vi/etc/dnsmasq. conf # line 19: uncomment (never forward normal names) domain-needed # line 21: uncomment (never forward addresses in a non-route address space) bogus-priv # line 41: uncomment (query each server strictly according to resolv. strict-order # line 55: Add the following line (query a specific domain name to a specific DNS server) server =/linuxprobe.org/10.1.1.53# line 123: uncomment (automatically add domain name) expand-hosts # line 133: add (define domain Name) domain = srv. world [root @ vdevops ~] # Systemctl start dnsmasq [root @ vdevops ~] # Systemctl enable dnsmasq

For DNS records, add them to/etc/hosts, and then Dnsmasq will answer the client's query.

[root@vdevops ~]# cat vim /etc/hostscat: vim: No such file or directory127.0.0.1   localhost localhost.localdomain vdevops.com 10.1.1.53 linuxprobe.org# add records10.1.1.56 vdevops.com vdevops[root@vdevops ~]# systemctl restart dnsmasq 

If the firewall is enabled, perform the following settings:

[root@vdevops ~]# systemctl start firewalld[root@vdevops ~]# firewall-cmd --add-service=dns --permanentsuccess[root@vdevops ~]# firewall-cmd --reloadsuccess

Verify to resolve the name or IP address from the client in the internal network and operate on other servers

[root@linuxprobe ~]#  yum -y install bind-utils

Change DNS settings to Dnsmasq Server (replace "eno16777736" with your own environment, that is, change the DNS of the Interface)

[root@linuxprobe ~]# nmcli c modify eno16777736 ipv4.dns 10.1.1.56[root@linuxprobe ~]# nmcli c down eno16777736; nmcli c up eno16777736
[root@linuxprobe ~]# dig vdevops.org; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.4 <<>> vdevops.org;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30866;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; WARNING: recursion requested but not available;; QUESTION SECTION:;vdevops.org.           IN  A;; ANSWER SECTION:vdevops.org.        128 IN  A   180.168.41.175;; Query time: 46 msec;; SERVER: 10.1.1.1#53(10.1.1.1);; WHEN: Thu Oct 27 18:07:23 CST 2016;; MSG SIZE  rcvd: 45
[Root @ linuxprobe ~] # Dig-x 10.1.1.56; <> DiG 9.9.4-RedHat-9.9.4-29.el7_2.4 <>-x 10.1.1.56; global options: + cmd; Got answer :;; -> HEADER <-opcode: QUERY, status: NOERROR, id: 13696; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0; question section:; 56.1.1.10.in-addr. arpa. in ptr; answer section: 56.1.1.10.in-addr. arpa. 0 in ptr vdevops.org .;; query time: 2 msec; SERVER: 10.1.1.56 #53 (10.1.1.56); WHEN: Thu Oct 27 18:07:51 CST 2016; msg size rcvd: 65 ### Dnsmasq: configure the DHCP server # enable the DHCP function and configure the DHCP server in Dnsmasq

[Root @ vdevops ~] # Vi/etc/dnsmasq. conf

  • Line 146: add (range of IP address to lease and term of lease) dhcp-range = 10.1.1.10, 10.1.1.30, 12 h
  • Line 316: add (define default gateway) dhcp-option = option: router, 10.1.1.1
  • -Line 325: add (define NTP, DNS, server and subnetmask) dhcp-option = option: ntp-server, 10.1.1.56 dhcp-option = option: dns-server, 10.1.1.56 dhcp-option = option: netmask, 255.255.255.0 [root @ vdevops ~] # Systemctl restart dnsmasq [root @ vdevops ~] # Systemctl status dnsmasq ● dnsmasq. service-DNS caching server. loaded: loaded (/usr/lib/systemd/system/dnsmasq. service; enabled; vendor preset: disabled) Active: active (running) since Thu 18:14:55 CST; 6 s ago Main PID: 7786 (dnsmasq) CGroup:/system. slice/dnsmasq. service expose-7786/usr/sbin/dnsmasq-k

Oct 27 18:14:55 vdevops.org mongoemd [1]: Started DNS caching server... Oct 27 18:14:55 vdevops.org mongoemd [1]: Starting DNS caching server .... Oct 27 18:14:55 vdevops.org dnsmasq [7786]: started, version 2.66 cachesize 150 Oct 27 18:14:55 vdevops.org dnsmasq [7786]: compile time options: IPv6 GNU-getopt guest no-i18n idn dhcp DHCPv6 no-Lua TFTP no-conntrac... Et auth Oct 27 18:14:55 vdevops.org dnsmasq-dhcp [7786]: DHCP, IP range 10.1.1.10-10.1.1.30, lease time 12 h Oct 27 18:14:55 vdevops.org dnsmasq [7786]: using nameserver 10.1.1.53 #53 for domain linuxprobe.org Oct 27 18:14:55 vdevops.org dnsmasq [7786]: reading/etc/resolv. conf Oct 27 18:14:55 vdevops.org dnsmasq [7786]: using nameserver 10.1.1.1 #53 Oct 27 18:14:55 vdevops.org dnsmasq [7786]: using nameserver 10.1.1.53 #53 for domain linuxprobe.org Oct 27 18:14:55 vdevops.org dnsmasq [7786]: read/etc/hosts-3 addresses Hint: Some lines were ellipsized, use-l to show in full.''

Link: https://wiki.archlinux.org/index.php/Dnsmasq_ (% E7 % AE % 80% E4 % BD % 93% E4 % B8 % AD % E6 % 96% 87) #. E5. AE. 89. E8.A3.85

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.