[IPv6]手把手教你用Debian11搭建IPv6路由器

通过骚操作拿到了1个/48的很奢侈的IPv6段.想着怎么给网络内的设备用,这就需要有一个提供Stateless,Stateful地址分配、广播的服务器提供服务。这样设备连入接入网络之后就可以获取到地址和地址段(不得不吐槽一下IPv6的这个设定)。本文采用Debian11 操作系统,RADVD负责Stateless,ISC-DHCP-Server作为双栈DHCP服务,下面简要介绍主要流程。

组件安装

apt install radvd isc-dhcp-server

系统配置

/etc/sysctl.conf中添加,看懂的自己调整,看不懂的直接抄作业就好

net.core.rmem_max=2500000
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.tcp_fastopen = 3

RADVD

/etc/radvd.conf中写入配置

interface eth0
{
    AdvSendAdvert on;
    AdvIntervalOpt on;
    MinRtrAdvInterval 60;
    MaxRtrAdvInterval 300;
    AdvLinkMTU 1280;
    AdvOtherConfigFlag on;
    AdvHomeAgentFlag off;
    prefix 2000:dad:face:cafe::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr on;
        AdvValidLifetime 3600;
        AdvPreferredLifetime 3600;
    };
};

RADVD只支持/64段,所以随便拿出来一个啦,eth0是要广播地址的网卡,2000:dad:face:cafe::/64是准备广播的段(老爹脸咖啡是什么鬼)

DHCPv4(纯IPv6请跳过)

/etc/dhcp/dhcpd.conf写入

option domain-name "dad.face";
option domain-name-servers 8.8.8.8, 1.1.1.1;

default-lease-time 3600;
max-lease-time 7200;
ddns-update-style none;
subnet 192.168.0.0 netmask 255.255.255.0 {
   range 192.168.0.30 192.168.0.230;
   option routers 192.168.0.1;
   option broadcast-address 192.168.0.255;
}

能点进来看这篇文章的,我相信大家都看得懂。

DHCPv6

/etc/dhcp/dhcpd6.conf写入

default-lease-time 3600;
preferred-lifetime 3600;
max-lease-time 7200;
allow leasequery;
option dhcp6.name-servers 2001:4860:4860::8888,2606:4700:4700::1111;
option dhcp6.domain-search "cola.moe";
option dhcp6.rapid-commit;
option dhcp6.info-refresh-time 600;
subnet6 d00b:ace:cafe::/48 {
        range6 d00b:ace:cafe:ace::10 d00b:ace:cafe:ace::ffff;

        range6 d00b:ace:cafe:bee:: temporary;

        prefix6 d00b:ace:cafe:1000:: d00b:ace:cafe:9999:: /64;
}

temporary是临时地址的分配,对就windows地址详情里面那个临时地址,prefix是用来给PD用的,可以指定块大小比如/64,剩下那个就是给主机用的啦。

服务启动项

由于isc-dhcp-server过于古老,启动文件不够现代,建议systemctl disable isc-dhcp-server;systemctl stop isc-dhcp-server;rm /etc/init.d/isc-dhcp-server  一键三连删除,换成systemd的

/etc/systemd/system/dhcpd.service写入

[Unit]
Description=DHCPD Service
After=network-online.target softether.service
Wants=network-online.target softether.service

[Service]
Type=simple
PIDFile=/var/run/dhcpd.pid
ExecStart=/usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf eth0
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

eth0是准备提供dhcp服务的端口

/etc/systemd/system/dhcpd6.service写入

[Unit]
Description=DHCPD6 Service
After=network.target softether.service
Wants=network.target softether.service

[Service]
Type=simple
PIDFile=/var/run/dhcpd6.pid
ExecStart=/usr/sbin/dhcpd -6 -q -cf /etc/dhcp/dhcpd6.conf tap_soft
Restart=always
RestartSec=5


[Install]
WantedBy=multi-user.target

启动前记得建立租约文件

touch /var/lib/dhcp/dhcpd.leases
touch /var/lib/dhcp/dhcpd6.leases

后续操作

至此,服务配置完成,剩余的就看各位如何套娃了,比如结合[网络]给Debian11开启Full Cone NAT支持这篇文章,给IPv4加NAT等等等等。

[IPv6]手把手教你用Debian11搭建IPv6路由器

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

滚动到顶部