Centos7 IPv6 Route And Dhcpv6 Server(借鉴补充)

Stella981
• 阅读 808

软件:radvd、dhcp

1)启用ipv6

vi /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

vi /etc/sysconfig/network

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

使配置生效并查看效果

sysctl -p

cat /proc/sys/net/ipv6/conf/all/forwarding

2)配置网卡

vi /etc/sysconfig/network-scripts/ifcfg-ens33

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

BOOTPROTO=static

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=no

IPV6_DEFROUTE=yes

IPV6_PEERDNS=yes

IPV6_PEERROUTES=yes

IPV6_FAILURE_FATAL=no

IPV6_ADDR_GEN_MODE=stable-privacy

NAME=ens33

UUID=c99f931f-acbe-4769-99de-63625a57ddba

DEVICE=ens33

ONBOOT=yes

#IPADDR=x.x.x.x

#GATEWAY=x.x.x.x

#NETMASK=X.X.X.X

PEERDNS=yes

PEERROUTES=yes

IPV6ADDR=2100:8:8:8::1/64

#IPV6_DEFAULTGW=2100:8:8:8::1000

IPV6FORWARDING=yes

#//IPV6 SLAAC configure client

#IPV6_AUTOCONF=no

#DHCPV6C=yes

vi ifcfg-ens34

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

BOOTPROTO=dhcp

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=no

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

IPV6_ADDR_GEN_MODE=stable-privacy

NAME=ens34

UUID=d684b872-93b2-44e2-af4e-56e9c0e3ee86

DEVICE=ens34

ONBOOT=yes

PEERDNS=yes

IPV6ADDR=2300:8:8:8::1/64

IPV6FORWARDING=yes

重启网络服务

systemctl restart network

3)安装并配置radvd

yum -y install radvd

vi /etc/radvd.conf

interface ens33
{
    AdvSendAdvert on;
    AdvManagedFlag off;       #dhcpv6  无状态 
    AdvOtherConfigFlag on;   #dhcpv6  无状态   如果AdvManagedFlag和AdvOtherConfigFlag都为on,就是dhcpv6 有状态
    MinRtrAdvInterval 30;
    MaxRtrAdvInterval 100;

AdvLinkMTU 1480;

    prefix 2100:8:8:8::/64       #dhcpv6  无状态   如果是dhcpv6有状态,需要注释掉
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr off;
    };
#    RDNSS 2300:8:8:8::1
#    {};
};

systemctl enable radvd

systemctl start radvd

4)安装并配置DHCP

yum -y install dhcp

vi /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 2300:8:8:8::1;

option dhcp6.domain-search "test.example.com","example.com";

option dhcp6.preference 255;

option dhcp6.info-refresh-time 21600;

option dhcp6.rapid-commit;

dhcpv6-lease-file-name "/var/lib/dhcpd/dhcpd6.leases";

# The subnet where the server is attached

subnet6 2100:8:8:8::/64 { 

        #    Range for clients

        range6 2100:8:8:8::2 2100:8:8:8::1000;       #DHCPV6  有状态时使用,dhcpv6 无状态时要注释掉

        #    Range for clients requesting a temporary address

        #range6 2001:db8:0:1::/64 temporary;

        #    Additional options

        #option dhcp6.name-servers fec0:0:0:1::1;

        #option dhcp6.domain-search "domain.example";

        #     Prefix range for delegation to sub-routers

        prefix6 2200:8:8:8:: 2200:8:8:1000:: /64;

}

systemctl enable dhcpd6

systemctl start dhcpd6

5)关闭防火墙

systemctl stop firewalld.service

注意:必须要关闭防火墙否则造成dhcpv6分配地址无法下发。

6)路由配置,可通过如下脚本来配置

cat /etc/pyFile/dhcpd6RoutePolicy.py

#!/usr/bin/python3
import os,re,time
os.system('ip -6 route add 2200:8:8::/48 via fe80::1111 dev ens33')
while 1:
        try:
                repDate = os.popen("cat /var/log/messages |grep 'Sending Reply'|tail -1").readlines()
                repv6ip = re.findall(r'\bfe80[a-f|0-9|:]*\b',repDate[0])
                rouDate = os.popen('ip -6 route |grep via').readlines()
                if rouDate=='':
                        os.system('ip -6 route add 2200:8:8::/48 via %s dev ens33'%repv6ip[0])
                else:                  
                        rouv6ip = re.findall(r'\bfe80[a-f|0-9|:]*\b',rouDate[0])
        except Exception as e:
                print(f"{e}")
        finally:
                if repv6ip == rouv6ip:
                        pass
                else:
                        os.system('ip -6 route del 2200:8:8::/48 via %s dev ens33'%rouv6ip[0])
                        os.system('ip -6 route add 2200:8:8::/48 via %s dev ens33'%repv6ip[0])
                time.sleep(30)
                print("checking route of dhcpd6......")

7) Centos7中开机启动

chmod +x /etc/rc.d/rc.local

vi /etc/rc.d/rc.local

chmod +x /etc/pyFile/dhcpd6RoutePolicy.py
/usr/bin/python3 /etc/pyFile/dhcpd6RoutePolicy.py &

[root@localhost ~]# ps aux |grep python3
root       6913  0.0  0.7 134672  7388 ?        S    19:42   0:00 /usr/bin/python3 /etc/pyFile/dhcpd6RoutePolicy.py
root       7150  0.0  0.0 112724   988 pts/0    S+   19:44   0:00 grep --color=auto python3
[root@localhost ~]#

延伸----无状态与有状态之间切换的简易操作

 [root@localhost pyFile]# pwd
/etc/pyFile
[root@localhost pyFile]# ls
DHCPD6.py  dhcpd6RoutePolicy.py  SLAAC.py
[root@localhost pyFile]#

[root@localhost pyFile]# ls /etc/radvd.conf
radvd.conf       radvd.conf.bak   radvd.conf.bak1  radvd.conf.bak2

[root@localhost pyFile]# ls /etc/dhcp/dhcpd6.conf
dhcpd6.conf          dhcpd6.conf.bak      dhcpd6.conf.bak1     dhcpd6.conf.bak2     dhcpd6.conf.rpmsave

-------DHCPD6 无状态

cat /etc/radvd.conf.bak1

interface ens33
{
    AdvSendAdvert on;
    AdvManagedFlag off;
    AdvOtherConfigFlag on;
    MinRtrAdvInterval 30;
    MaxRtrAdvInterval 100;
    prefix 2100:8:8:8::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr off;
    };
};

[root@localhost pyFile]# cat /etc/dhcp/dhcpd6.conf.bak1
default-lease-time 2592000;
preferred-lifetime 604800;
option dhcp-renewal-time 3600;
option dhcp-rebinding-time 7200;

allow leasequery;

option dhcp6.name-servers 2300:8:8:8::1;
option dhcp6.domain-search "test.example.com","example.com";
option dhcp6.preference 255;
option dhcp6.info-refresh-time 21600;
option dhcp6.rapid-commit;
dhcpv6-lease-file-name "/var/lib/dhcpd/dhcpd6.leases";
# The subnet where the server is attached
subnet6 2100:8:8:8::/64 {
        # Prefix range for delegation to sub-routers
prefix6 2200:8:8:8:: 2200:8:8:1000:: /64;
}

[root@localhost pyFile]# cat SLAAC.py
#!/usr/bin/python3
import os,time
os.system('systemctl stop radvd')
time.sleep(1)
os.system('systemctl stop dhcpd6')
time.sleep(1)
os.system('cp /etc/radvd.conf.bak1 /etc/radvd.conf')
time.sleep(1)
os.system('cp /etc/dhcp/dhcpd6.conf.bak1 /etc/dhcp/dhcpd6.conf')
time.sleep(1)
os.system('systemctl start radvd')
time.sleep(1)
os.system('systemctl start dhcpd6')
time.sleep(1)
[root@localhost pyFile]#

----------DHCPD6  有状态

cat /etc/radvd.conf.bak2

 interface ens33
{
    AdvSendAdvert on;
    AdvManagedFlag on;
    AdvOtherConfigFlag on;
    MinRtrAdvInterval 30;
    MaxRtrAdvInterval 100;
};

[root@localhost pyFile]# cat /etc/dhcp/dhcpd6.conf.bak2
default-lease-time 2592000;
preferred-lifetime 604800;
option dhcp-renewal-time 3600;
option dhcp-rebinding-time 7200;

allow leasequery;

option dhcp6.name-servers 2300:8:8:8::1;
option dhcp6.domain-search "test.example.com","example.com";
option dhcp6.preference 255;
option dhcp6.info-refresh-time 21600;
option dhcp6.rapid-commit;
dhcpv6-lease-file-name "/var/lib/dhcpd/dhcpd6.leases";
# The subnet where the server is attached
subnet6 2100:8:8:8::/64 {
        # Range for clients
        range6 2100:8:8:8::2 2100:8:8:8::9;

        # Prefix range for delegation to sub-routers
prefix6 2200:8:8:8:: 2200:8:8:1000:: /64;
}

 cat DHCPD6.py
#!/usr/bin/python3
import os,time
os.system('systemctl stop radvd')
time.sleep(1)
os.system('systemctl stop dhcpd6')
time.sleep(1)
os.system('cp /etc/radvd.conf.bak2 /etc/radvd.conf')
time.sleep(1)
os.system('cp /etc/dhcp/dhcpd6.conf.bak2 /etc/dhcp/dhcpd6.conf')
time.sleep(1)
os.system('systemctl start radvd')
time.sleep(1)
os.system('systemctl start dhcpd6')
time.sleep(1)
[root@localhost pyFile]#

[root@localhost pyFile]# cd /etc/pyFile/ 

[root@localhost pyFile]# ls -al
总用量 24
drwxr-xr-x.  2 root root   67 3月  27 22:51 .
drwxr-xr-x. 77 root root 8192 3月  27 22:53 ..
-rwxr-xr-x.  1 root root  382 3月  27 22:22 DHCPD6.py
-rwxr-xr-x.  1 root root 1050 3月  27 22:51 dhcpd6RoutePolicy.py
-rwxrwxrwx.  1 root root  382 3月  27 22:22 SLAAC.py

chmod +x DHCPD6.py

chmod +x SLAAC.py

./SLAAC.py

./DHCPD6.py

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
2年前
java将前端的json数组字符串转换为列表
记录下在前端通过ajax提交了一个json数组的字符串,在后端如何转换为列表。前端数据转化与请求varcontracts{id:'1',name:'yanggb合同1'},{id:'2',name:'yanggb合同2'},{id:'3',name:'yang
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Souleigh ✨ Souleigh ✨
3年前
前端性能优化 - 雅虎军规
无论是在工作中,还是在面试中,web前端性能的优化都是很重要的,那么我们进行优化需要从哪些方面入手呢?可以遵循雅虎的前端优化35条军规,这样对于优化有一个比较清晰的方向.35条军规1.尽量减少HTTP请求个数——须权衡2.使用CDN(内容分发网络)3.为文件头指定Expires或CacheControl,使内容具有缓存性。4.避免空的
Stella981 Stella981
2年前
Android So动态加载 优雅实现与原理分析
背景:漫品Android客户端集成适配转换功能(基于目标识别(So库35M)和人脸识别库(5M)),导致apk体积50M左右,为优化客户端体验,决定实现So文件动态加载.!(https://oscimg.oschina.net/oscnet/00d1ff90e4b34869664fef59e3ec3fdd20b.png)点击上方“蓝字”关注我
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
2年前
35岁是技术人的天花板吗?
35岁是技术人的天花板吗?我非常不认同“35岁现象”,人类没有那么脆弱,人类的智力不会说是35岁之后就停止发展,更不是说35岁之后就没有机会了。马云35岁还在教书,任正非35岁还在工厂上班。为什么技术人员到35岁就应该退役了呢?所以35岁根本就不是一个问题,我今年已经37岁了,我发现我才刚刚找到自己的节奏,刚刚上路。
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
4个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这