歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> CentOS 7配置DNS和DHCP服務

CentOS 7配置DNS和DHCP服務

日期:2017/3/3 17:48:19   编辑:學習Linux

CentOS 7配置DNS和DHCP服務

CentOS 7配置DNS和DHCP服務


安裝Dnsmasq

  • Dnsmasq 提供 DNS 緩存和 DHCP 服務功能。作為域名解析服務器(DNS),dnsmasq可以通過緩存 DNS 請求來提高對訪問過的網址的連接速度。作為DHCP 服務器,dnsmasq 可以用於為局域網電腦分配內網ip地址和提供路由。DNS和DHCP兩個功能可以同時或分別單獨實現。dnsmasq輕量且易配置,適用於個人用戶或少於50台主機的網絡。此外它還自帶了一個 PXE 服務器。
  • DHCP服務概述: 名稱:DHCP - Dynamic Host Configuration Protocol 動態主機配置協議
    功能:DHCP(Dynamic Host Configuration
    Protocol,動態主機配置協議)是一個局域網的網絡協議,使用UDP協議工作,主要有兩個用途:
    1、 給內部網絡或網絡服務供應商自動分配IP地址,主機名,DNS服務器,域名
    2、 配和其它服務,實現集成化管理功能。如:無人執守安裝服務器 特點: C/S 模式 客戶端/服務端 自動分配IP地址,方便管理
    DHCP不會同時租借相同的IP地址給兩台主機; DHCP管理員可以約束特定的計算機使用特定的IP地址;
    可以為每個DHCP作用域設置很多選項; 客戶機在不同子網間移動時不需要重新設置IP地址。每次都自動獲取IP地址就可以了。 DHCP的缺點:
    當網絡上存在多服務器時,一個DHCP服務器不能查出已被其它服務器租出去的IP地址;
    DHCP服務器不能跨路由器與客戶機通信,除非路由器允許BOOTP協議轉發。 端口: DHCP服務使用:端口67(bootps)
    68(bootpc) 。 例:查看
    # cat /etc/services | grep boot
    安裝並配置Dnsmasq
[root@vdevops ~]# yum -y install dnsmasq
[root@vdevops ~]# vi /etc/dnsmasq.conf# line 19: 取消注釋(從不轉發普通名稱)domain-needed# line 21: 取消注釋 (從不轉發非路由地址空間中的地址)bogus-priv# line 41: 取消注釋 (查詢每個服務器嚴格按照resolv.conf中的順序)strict-order# line 55: 添加下面一行 (查詢特定域名到特定的DNS服務器)server=/linuxprobe.org/10.1.1.53# line 123: 取消注釋 (自動添加域名)expand-hosts# line 133: 添加 (定義域名)domain=srv.world[root@vdevops ~]# systemctl start dnsmasq[root@vdevops ~]# systemctl enable dnsmasq 

對於DNS記錄,將它們添加到/etc/hosts中,然後,Dnsmasq將回答客戶端的查詢。

[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 

如果防火牆是開啟的,需要做下面設置

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

驗證以從內部網絡中的客戶端解析名稱或IP地址,在其他服務器上面操作

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

將DNS設置更改為Dnsmasq Server(將“eno16777736 ”替換為您自己的環境,即更改接口的DNS)

[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:配置DHCP服務器##在Dnsmasq中啟用集成DHCP功能並配置DHCP服務器

[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,12h
  • 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 2016-10-27 18:14:55 CST; 6s ago Main PID: 7786 (dnsmasq) CGroup: /system.slice/dnsmasq.service └─7786 /usr/sbin/dnsmasq -k

Oct 27 18:14:55 vdevops.org systemd[1]: Started DNS caching server.. Oct 27 18:14:55 vdevops.org systemd[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 DBus 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 12h 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. “`

參考鏈接: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

http://xxxxxx/Linuxjc/1184686.html TechArticle

Copyright © Linux教程網 All Rights Reserved