Linux搭建IPv6+DHCP+DNS服务器详解

如果您想搭建一个IPV6网络,且实现全内网自动获取IPV6地址、域名解析,还要搭建IPV6网站……那本文可能算得上一篇非常nice的教程。

操作系统:CentOS7.5
应用软件:radvd、dhcp、bind

配置网络环境

启用ipv6

修改配置/etc/sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
net.ipv6.conf.all.forwarding = 1

修改配置/etc/sysconfig/network

NETWORKING_IPV6=yes
IPV6FORWARDING=yes
HOSTNAME=dhcpserver
ONBOOT=yes

使配置生效并查看效果:

sysctl -p
cat /proc/sys/net/ipv6/conf/all/forwarding

配置网卡

修改配置/etc/sysconfig/network-scripts/ifcfg-ens33

PEERDNS=yes
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6ADDR=2001:db8:8:1::1/64
IPV6FORWARDING=yes
systemctl restart network

安装并配置radvd

需要注意的是,radvd用于无状态自动配置地址,客户端通过网络接口接收路由器宣告的全局地址前缀,再结合接口ID形成全球单播地址,但是不能获取DNS

yum -y install radvd

修改配置/etc/radvd.conf

interface ens33
{
    AdvManagedFlag on;
    AdvSendAdvert on;
    AdvOtherConfigFlag on;
    AdvLinkMTU 1480;
    MinRtrAdvInterval 30;
    MaxRtrAdvInterval 100;
    prefix 2001:db8:8::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr on;
    };
};

备注:当我把radvd的prefix前缀改为96时,提示只能64,不知道为什么,见下图:

systemctl enable radvd
systemctl start radvd

安装并配置DHCP

需要注意的是,dhcp用于有状态自动配置地址,客户端从服务器的地址池中配置地址,能获取DNS

yum -y install dhcp

修改配置/etc/dhcp/dhcpd6.conf

default-lease-time 2592000;
preferred-lifetime 604800;
option dhcp-renewal-time 3600;
option dhcp-rebinding-time 7200;
allow leasequery;
option dhcp6.name-servers 2001:db8:8::1;
option dhcp6.domain-search "dhcpserver";
option dhcp6.preference 255;
option dhcp6.rapid-commit;
option dhcp6.info-refresh-time 21600;
dhcpv6-lease-file-name "/var/lib/dhcpd/dhcpd6.leases";

subnet6 2001:db8:8::/96 {
    range6 2001:db8:8::10 2001:db8:8::80;
}
systemctl enable dhcpd6
systemctl start dhcpd6

这时,在其他计算机上就可以正常获取到IPV6地址了,同时自动获取DNS,如下图:

安装并配置DNS

yum -y install bind

本文省略named的详细配置方法,以下只是部分配置内容,通过添加一个正向解析举例而已,修改配置/etc/named.conf

options {
	listen-on port 53 { any; };
	listen-on-v6 port 53 { 2001:db8:8::1; };
};
zone "dhcpserver.com" IN {
    type master;
    file "dhcpserver.com.zone";
};

修改配置/var/named/dhcpserver.com.zone

$TTL 1D
@      IN SOA  @ dhcpserver.com. (
                                    0      ; serial
                                    1D     ; refresh
                                    1H     ; retry
                                    1W     ; expire
                                    3H )   ; minimum
       NS      @
       A       127.0.0.1
       AAAA    ::1
www    A       127.0.0.1
www    AAAA    ::1
systemctl enable named
systemctl start named

至此,DNS解析也开始正常工作。

附加知识

Windows下重新获取IPV6方法:

ipconfig /release6
ipconfig /renew6

Linux IPV6 SLAAC(无状态地址自动获取) 的网卡配置:

IPV6_AUTOCONF=no
DHCPV6C=yes

如果您搭建了IPv6的网站,也可以通过IPv6地址访问,如下图:

原创文章禁止转载:技术学堂 » Linux搭建IPv6+DHCP+DNS服务器详解

赞 (0) 打赏

精彩评论

4+1=

感谢您的支持与鼓励

支付宝扫一扫打赏

微信扫一扫打赏