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

ifcfg配置参数介绍:https://blog.csdn.net/chinaltx/article/details/86497165

一、不指定分配地址

  • 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
    #禁止NetworkManager管理网卡
    NM_CONTROLLED=no 
    HWADDR=
    #USERCTL=no
    PEERDNS=yes
    BOOTPROTO=dhcp #只能小写
    #BOOTPROTO=dhcp6  打开这个只会获取ipv6的地址
    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 (NM_CONTROLLED=yes )

相关文件在/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

红色部分为租约信息和配置文件路径。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值