centos 7 上配置dnsmasq 同時支持ipv4和ipv6的DHCP服務

dnsmasq版本: dnsmasq 從2.6*版本開始支持DHCPv6功能

參考:https://blog.csdn.net/qq_35550345/article/details/86628962

dhcpv6原理:https://blog.csdn.net/qq_38265137/article/details/80466734

一、不指定分配地址

  • dnsmasq服務器
  1. 配置dnsmasq服務器ipv6地址(本測試接口爲eth0)
    /etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    TYPE=Ethernet
    
    ONBOOT=yes
    NM_CONTROLLED=no
    BOOTPROTO=dhcp
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=yes
    
    PEERDNS=yes
    
    IPV6INIT=yes
    IPV6to4INIT=yes
    IPV6FORDING=yes
    IPV6ADDR=fd00::1/64

    /etc/sysconfig/network
     

    NETWORKING_IPV6=yes

     

  2. 設置dnsmasq.conf 
    read-ethers
    log-dhcp
    log-queries
    log-facility=/var/log/dnsmasq.log
    addn-hosts = /var/lib/cobbler/cobbler_hosts
    domain=local
    dhcp-lease-max=1800
    server=/local/
    resolv-file=/etc/dnsmasq.upstream
    interface=eth0
    
    cache-size=1024
    
    # This is one of the key options. dnsmasq tries to move out servername
    # and PXE filename from special fields into DHCP options.
    # Some old clients can't understand those DHCP options, so they
    # will not be able to boot via PXE without this option enabled.
    # For example gPXE will not work while iPXE works fine.
    dhcp-no-override
    
    # for many simultaneously DHCPDISCOVVER requests dnsmasq can offer
    # the same IP for two differnt MAC addresses. This option prevents it
    # by assigning IPs one by one instead of using hash algorithm.
    dhcp-sequential-ip
    
    #ipv4
    dhcp-option=6,10.10.1.2
    dhcp-range=internal,10.10.1.128,10.10.1.254,255.255.255.0,120m
    dhcp-option=net:internal,option:router,10.10.1.2
    dhcp-boot=net:internal,pxelinux.0,boothost,10.10.1.2
    
    #ipv6
    dhcp-range=fd00::22, fd00::44, 64, 1h
    enable-ra
    #domain-needed
    #resolv-file=/etc/resolv.dnsmasq.conf
    

    檢查語法並啓動dnsmasq:dnsmasq -test

    殺掉測試進程後啓動dnsmasq &

    dhcp租用信息:/var/lib/dnsmasq/dnsmasq.leases

  • 客戶端配置
  1. 網卡配置
    客戶機上的接口爲eth0,網卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0
    DEVICE=eth0
    ONBOOT=yes
    NM_CONTROLLED=no
    HWADDR=
    #USERCTL=no
    PEERDNS=yes
    BOOTPROTO=DHCP
    BOOTPROTO=dhcp6
    DHCPV6C=yes
    IPV6INIT=yes

     

  2. 網絡配置文件/etc/sysconfig/network
    NETWORKING_IPV6=yes
    
    IPV6_AUTOCONF=yes  #yes表示自動獲取地址

     

  3. 測試:
    dhclient -6 -v eth0

二、指定分配地址

使用dnsmasq 有狀態DHCPv6下發特定租約

上面的方式是dnsmasq按照特定算法給客戶端分配ipv4和ipv6地址,如果想給每個客戶端分配指定地址,需要增加以下配置。

  1. dnsmasq服務器(dnsmasq.conf )
    配置和上面一樣,添加以下語句
    dhcp-host=id:00:03:01:00:08:00:27:5c:b9:f0, [fd00::22]

    修改配置需要重啓dnsmasq服務

  2. 客戶端

    根據官方描述,dhclient版本爲4.1+支持ipv6。爲了支持DUID-LL要在/etc/dhcp/dhclient.conf中寫入:

         ZQ send dhcp6.client-id = concat(00:03:00, hardware);
    /etc/sysconfig/network-scripts/ifcfg-eth0跟上面一樣
    配置/etc/sysconfig/network

    NETWORKING_IPV6=yes
    
    IPV6_AUTOCONF=no  

    客戶端租約文件/var/lib/dhclient/dhclient6.leases
     

三、問題分析

centos7使用NetworkManager啓動dhclient 

相關文件在/var/lib/NetworkManager/

查看dhcliemt進程       

ps aux | grep dhclient 

/sbin/dhclient -d -q -6 -N -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient6-eth0.pid -lf /var/lib/NetworkManager/dhclient6-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease -cf /var/lib/NetworkManager/dhclient6-eth0.conf eth0

紅色部分爲租約信息和配置文件路徑。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章