ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

随笔1个月前发布 王德佛
35 0 0

环境介绍:

1:服务器环境:

1.1:ubuntu18.04,两张网卡,

网卡1(ens33):能拿到ipv4和ipv6地址并能正常访问ipv4和ipv6网站(192.168.1.90,2409:8a63:e5d:9310:20c:29ff:fe0d:b769)

网卡2(ens38):作为服务网卡(172.18.1.1 )

 

一、安装pppoe服务器

1. 安装服务

sudo apt install pppoe

 

2.修改配置文件

  2.1 修改文件/etc/ppp/options,修改ms-dns为172.18.1.1,223.5.5.5,开启pap,关闭chap(或开启chap,关闭pap,windows拨号只支持chap)

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

   2.2 添加pppoe用户名密码,修改/etc/ppp/pap-secerts文件或/etc/ppp/chap-secerts

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

   2.3 添加/etc/ppp/pppoe-server-options文件,并写入以下内容

auth
require-pap
logfile /var/log/pppd.log
+ipv6

   2.4 开启数据转发

sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sudo sysctl -p

  2.5 添加iptables规则

sudo iptables -t nat -A POSTROUTING -s 172.18.1.0/24 -o ens33 -j MASQUERADE
# 注意:上述规则重启后失效,需要重新添加

 

3. 开启服务

sudo pppoe-server -I ens38 -L 172.18.1.1 -R 172.18.1.100 -N 20

 

4. 验证服务

ps -ef|grep pppoe
# 查看该进程是否成功启动

 

5. 停止服务

ps -ef | grep pppoe-server |grep -v grep|awk '{print $2}'| sudo xargs kill -9

 

二、安装dhcp服务

1. 安装服务

sudo apt install isc-dhcp-server

 

2.修改配置文件

  2.1 修改配置文件/etc/default/isc-dhcp-server

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

   2.2 配置地址池等信息,/etc/dhcp/dhcpd.conf,在最后添加以下内容

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

 

  2.3 开启数据转发

sudo echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sudo sysctl -p

  2.4 添加iptables规则

sudo iptables -t nat -A POSTROUTING -s 172.18.1.0/24 -o ens33 -j MASQUERADE
# 注意:上述规则重启后失效,需要重新添加

 

3. 开启服务

sudo systemctl start isc-dhcp-server

 

4. 验证服务,下挂设备能拿到地址并ping百度

systemctl status isc-dhcp-server

 

三、安装ipv6 radvd服务器

1. 安装radvd服务

sudo apt install radvd

 

2.添加配置文件

  2.1 创建文件/etc/radvd.conf并将以下内容写入配置文件, ens38为接口名。注意需要使用制表符作为缩进

#log-level 8
#log-mode full
#stateless
interface ens38 {
AdvSendAdvert on;
MinRtrAdvInterval 30;
MaxRtrAdvInterval 600;
AdvManagedFlag off; #M bit=1
AdvOtherConfigFlag off; #O bit=1
AdvLinkMTU 1500;
AdvSourceLLAddress on;
AdvDefaultPreference medium;
prefix 2201:db8:0:1::/64
{
AdvOnLink on;
AdvAutonomous on; #A bit=1
AdvRouterAddr off;
AdvPreferredLifetime 3600;
AdvValidLifetime 7200;
};
RDNSS 2201:db8:0:1::1 {

};
};

   2.2 开启ipv6转发,修改文件/etc/sysctl.conf,将net.ipv6.conf.all.forwarding=1所在行前面的注释去除

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

   2.3 执行ipv6转发立即生效

sudo sysctl -p

 

3. 开启服务

sudo systemctl start radvd

 

4. 验证服务,执行以下命令,并抓包查看是否有RA报文

sudo systemctl status radvd

 

四、安装ipv6 dhcpv6服务器

1. 安装服务

sudo apt install isc-dhcp-server

 

2. 修改配置文件

  2.1 修改配置文件/etc/default/isc-dhcp-server

ubuntu18.04安装pppoe,dhcp,radvd,dhcpv6

   2.2 添加配置文件/etc/dhcp/dhcpd6.conf,添加地址池,内容如下

default-lease-time 600;
max-lease-time 7200; 
log-facility local7; 
subnet6 2201:db8:0:1::/64 {
        # Range for clients
        range6 2201:db8:0:1::129 2201:db8:0:1::254;

        # Range for clients requesting a temporary address
        range6 2201: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 pd
        prefix6 2201:db8:0:100:: 2201:db8:0:f00:: /56;


}

  2.3 创建文件 /var/lib/dhcp/dhcpd6.leases

touch /var/lib/dhcp/dhcpd6.leases

chown dhcpd:dhcpd /var/lib/dhcp/dhcpd6.leases

  2.4 开启dhcpv6转发

sudo echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf 

  2.5 写入iptables6规则

sudo ip6tables -t nat -A POSTROUTING -s 2201:db8:0:1/64 -o ens33 -j MASQUERADE 
# 注意:上述规则重启后失效,需要重新添加

 

3. 开启服务

sudo systemctl start isc-dhcp-server

 

4. 验证服务

sudo systemctl status isc-dhcp-server

 

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...