CentOS Linux上搭建PPPoE服务器及拨号设置

CentOS Linux上搭建PPPoE服务器及拨号设置

搭建PPPoE,成功了的话,就觉得超级简单,在CentOS Linux更是5步左右就能搞定。
 
1、安装pppoe,安装完成后,会有pppoe-server命令
yum install rp-pppoe

2、安装完成后,会在动在/etc/ppp目录下生成pppoe-server-options文件,文件内容如下,照着改就可以了
写道
# PPP options for the PPPoE server 
# LIC: GPL 
require-pap 
require-chap 
login 
lcp-echo-interval 10 
lcp-echo-failure 2 
logfile /var/log/pppoe.log

可以先添加系统用户: 
useradd pppoe # 添加用户
passwd pppoe # 设置密码

3、添加用户名密码,修改/etc/chap-secrets 和 /etc/ppp/pap-secrets 文件,添加下列一行

写道
"pppoe"        *        "123456"        *

很通俗,用户名:pppoe,密码是:123456

4、添加防火墙规则,做nat转换
写道
iptables -A POSTROUTING -t nat -s 10.10.10.0/24 -j MASQUERADE 
iptables -A FORWARD -p tcp --syn -s 10.10.10.0/24 -j TCPMSS --set-mss 1256 
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -w net.ipv4.ip_forward=1

扫描二维码关注公众号,回复: 1595752 查看本文章

第一条是添加nat,转换来自10.10.10.0/24网段的ip
第二天是修改mtu,根据自身需求改了
第三条打开转发
第四条是修改转发文件
 
5、启动pppoe
写道
pppoe-server -I eth0 -L 10.10.10.1 -R 10.10.10.100-200

这条命令的作用是:-I eth0  在eth0端口上检测pppoe discover包
-L 10.10.10.1    虚拟网关的意思,就是pppoe服务器端虚拟网关ip
-R 10.10.10.100-200  分配虚拟IP,分别是10.10.10.100到10.10.10.200
还有一些其他的参数你可以参考一下,直接man pppoe-server自己看了,每个参数都有默认值
 
成功完成上述步骤,就完成了搭建pppoe服务器端了,下面就是windows验证了
我的是windows xp系统,win7或者路由器应该都没问题
不过要改下验证方式,在“属性”--》“安全”--》“高级--设置”--》将“数据加密”改为“可选加密”,然后勾选上chap或者pap验证就可以了
输入用户名密码,不可意外就可以连接成功了
 
不过只是局域网的,意义并不大。
 
顺带贴一下pppoe建立的原理过程
写道
PPPoE 的验证过程
PPPoE 的验证过程包括 2 个阶段,Discovery 阶段和 PPP Session 阶段。
Discovery 阶段,包含 4 个步骤:
Step 1: PADI
PPPoE 客户端发送主动发现初始包(PPPoE Active Discovery Initiation,PADI),以太头中的目的地址是以太广播地址 FF:FF:FF:FF:FF:FF,PPPOE 头中的 CODE 为 0x09,SESSION_ID 值必须为 0,负载部分必须只包含一个 Service-Name 类型的 TAG 表示请求的服务类型,另外可以包含其他 TAG,整个 PPPOE 包不能超过 1484 字节;
Step 2: PADO
服务器端 PPPoE 进程在网络接口侦听到 PADI 包后,发送主动发现提议包(PPPoEActive Discovery Offer, PADO),用来回应客户机的 PADI 包,以太头中的目的地址是客户机的MAC 地址,PPPOE 头中的 CODE 为 0x07, SESSION_ID 值必须为 0,负载部分必须包含一个 AC-Name 类型的 TAG,用来指示本 AC 的名称,一个在 PADI 包中指定的Service- Name 的 TAG,另外可以包含其他 Service-Name 的 TAG。如果 AC 不对该客户机提供服务,AC 就不回应 PADO 包。
Step 3: PADR
PPPoE 客户端收到 PADO 包后,在 PADO 包中选择一个(可能有多个 PPPoE 服务器,通常选取最快的一个)发送主动发现请求包(PPPoEActive Discovery Request,PADR),以太头中的目的地址是所选取的 PADO 包的源以太头地址(即 PPPoE 服务器的 MAC 地址),PPPOE 头中的 CODE 为 0x19,SESSION_ID 值必须为 0,负载部分必须只包含一个 Service-Name 类型的 TAG 表示请求的服务类型,另外可以包含其他 TAG。
Step 4: PADS
MAC 地址匹配的 PPPoE 服务器收到 PADR 包后,发送主动发现会话确认包(PPPoE Active Discovery Session-confirmation, PADS),将产生一个 SEESSION_ID 值用来标志本次 PPP 会话,以 PADR 包方式发送给客户机。以太头中的目的地址是客户机的 MAC 地址,PPPOE 头中 的 CODE 为 0x65,SESSION_ID 值必须为所生成的那个SESSION_ID,负载部分必须只包含一个 Service-Name 类型的 TAG, 表示该服务类型被 PPPoE 服务器接受,另外可以包含其他 TAG。如果 PPPoE 服务器不接受 PADR 中的

Server-Name,PADS 中则包含一个 Service-Name -Error 类型的 TAG,这时 SESSION_ID 设置为 0。

PPP Session 阶段:
当客户端与服务器端远成发现阶段之后,即进入会话阶段,在 PPP 会话阶段,PPP 包被封装在 PPPOE 以太帧中,以太包目的地址都是单一的,以太协议为 0x8864,PPPOE 头的CODE必须为0,SESSION_ID必须一直为发现阶段协商出的SEESION_ID值,PPPOE的负载是整个 PPP 包,PPP 包前是两字节的 PPP 协议 ID 值。
在 Session 阶段,主机或服务器任何一方都可发 PADT(PPPoE Active Discovery Terminate)报文通知对方结束 Session。

PPPoE 的身份验证发生在会话(PPP Session)阶段。可以这样更解,rp-pppoe 包负责Discovery 及会话终止 PADT,ppp 包负责会话阶段的数据传输。

来源 https://www.cnblogs.com/fwonfo/p/7819457.html

1、检查是否安装 rp-pppoe 包

rpm -qa rp-pppoe

如果没有安装,则通过yum安装

yum install -y rp-pppoe

2、服务端

(1)设置支持IP转发

vi /etc/sysctl.conf
net.ipv4.ip_forward = 1  # 修改为1

(2)修改服务器配置

vi /etc/ppp/pppoe-server-options
复制代码
# PPP options for the PPPoE server
# LIC: GPL
require-pap    # 认证方式为pap, 还可以配置为chap方式
login
lcp-echo-interval 10
lcp-echo-failure 2
复制代码

(3)添加认证账户

添加系统账户

useradd test  # 添加系统用户test
passwd test   # 设置账户密码, 这里设置密码为 123

添加pppoe认证账户,认证账户必须为系统账户,这里使用刚添加的 test/123

# 若采用chap认证方式

vi /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
"test"          *       "123"                   *

# 若采用pap认证方式

vi /etc/ppp/pap-secrets
# Secrets for authentication using PAP
# client        server  secret                  IP addresses
"test"          *       "123"                   *

(4)修改配置文件 /etc/ppp/options

vi /etc/ppp/options
# local    # local for chap
auth       # auth for pap
lock       # lock for pap

(5)启动pppoe服务

pppoe-server -I eth1 -L 192.168.0.101 -R 192.168.0.200 -N 10
# -L 虚拟PPPoE接口
# -R 起始地址
# -N 地址个数

3、客户端

(1)与服务端一样,先安装 rp-pppoe 包

(2)使用root用户,执行 pppoe-setup

pppoe-setup
复制代码
Welcome to the PPPoE client setup.  First, I will run some checks on
your system to make sure the PPPoE client is installed properly...


LOGIN NAME

Enter your Login Name (default root): test    # 输入拨号认证账户

INTERFACE

Enter the Ethernet interface connected to the PPPoE modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethX, where 'X' is a number.
(default eth0):                               # 默认以 eth0 连接拨号

Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped.  If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses.  You may have some problems with demand-activated links.
Enter the demand value (default no):

DNS

Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here:

PASSWORD

Please enter your Password:                   # 输入认证账户密码
Please re-enter your Password:

USERCTRL

Please enter 'yes' (three letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes):

FIREWALLING

Please choose the firewall rules to use.  Note that these rules are
very basic.  You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security.  If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself.  Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc.  If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.

The firewall choices are:
0 - NONE: This script will not set any firewall rules.  You are responsible
          for ensuring the security of your machine.  You are STRONGLY
          recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
                for a LAN
Choose a type of firewall (0-2): 0

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no):no

** Summary of what you entered **

Ethernet Interface: eth0
User name:          test
Activate-on-demand: No
DNS:                Do not adjust
Firewalling:        NONE
User Control:       yes
Accept these settings and adjust configuration files (y/n)?y
复制代码

输入y之后,会提示 ifup ppp0 拨号

复制代码
Congratulations, it should be all set up!

Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/pppoe-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.
复制代码

拨号成功后,ppp0的ip为从服务端分配的地址。

猜你喜欢

转载自www.cnblogs.com/lsgxeva/p/9184068.html