[PPPOE]RP-PPPOE脚本分析

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_35804181/article/details/72902844

默认配置

配置存放目录:/etc/ppp/pppoe.conf
ppp-pap密码存放目录:/etc/ppp/pap-secrets
ppp-chap密码存放目录:/etc/ppp/chap-secrets
PPP防火墙:/etc/ppp/firewall-standalone和/etc/ppp/firewall-masq
ppp网卡:文件/var/run/ppp0.pid

1.配置文件

配置文件(/etc/ppp/pppoe.conf)如其开头所述,只会用于pppoe-start, pppoe-stop, pppoe-connect和pppoe-status脚本,并不会被pppoe可执行文件使用。

内容解读

普通内容

  • ETH 连接到DSL调制器的网卡
  • USER 拨号用户名
  • DEMAND 进程守护间隔
  • DNSTYPE DNS设置方式,包括从服务器获取和自定义两种
  • PEERDNS 从同级(peer)中获取NDS服务器地址,仅对最近版本的pppd有效。改变到PEERDNS,在Red Hat中更具有兼容性
  • DNS1/DNS2 略
  • DEFAULTROUTE 让PPPoE连接到默认路由

专业内容

  • CONNECT_TIMEOUT 设置拨号最长等待时间,当值为0时,将会立即返回一个成功状态,单位秒。(注意:当在物理不可达的主机上PPPoE时,设置等待超时为0,可确保在调用pppoe-start后一直尝试连接)
  • CONNECT_POLL pppoe-start查询连接是否成功的频率,单位秒
  • ACNAME PPPOE接入器名称
  • SERVICENAME PPPOE服务器名称
  • PING 拨号连接等待显示字符
  • PIDFILE pppoe-connect脚本中存放进程ID文件的名字(PIDFILEPIDFILE.pppoe,$PIDFILE.pppd)
  • SYNCHRONOUS 是否使用同步的PPP。不使用,更安全;若使用,CPU消耗更低;
  • CLAMPMSS 是否固定MSS(Maxitu Segment Size,类似MTU),判断条件:若DSL调制器上只有单一的一台电脑,设置为”no”;若你的电脑在一个LAN中作为网关,则设置为1412。1412对大多数情况来说都是适合的,但需要消耗更多CPU功耗
  • LCP_INTERVAL LCP回显间隔,默认值20
  • LCP_FAILURE LCP失败次数,默认值3
  • PPPOE_TIMEOUT 必须是 4 * LCP_INTERVAL
  • FIREWALL 防火墙等级,默认NONE
  • LINUX_PLUGIN pppd的Linux内核模块插件,若要使用设置为/etc/ppp/plugins/rp-pppoe.so
  • PPPOE_EXTRA 传递给pppoe的额外参数
  • PPPD_EXTRA 传递给pppd的额外参数

高级内容

  • OVERRIDE_PPPD_COMMAND 完全允许pppd调用,赋值”pppd call dsl”
  • RETRY_ON_FAILURE 当失去连接后,pppoe-connect退出

2.设置脚本

rp-pppoe中设置主要使用pppoe-setup脚本,用于设置拨号参数:帐号,密码,网口,DNS;

内容解读

1.检测必要文件是否存在,包括pppoe.conf,pppd,pppoe;
2.执行pppoe.conf,获取对应变量;
3.设置拨号帐号,密码,网口,DNS,是否后台守护(demand),防火墙级别;
4.将拨号帐号,网口,DNS,是否后台守护(demand),防火墙级别在pppoe.conf的的值进行修改保存;
5.将DNS在resolv.conf中进行设置保存;
6.将拨号密码在pap-secrets和chap-secrets脚本中进行设置保存;

3.开始脚本

rp-pppoe中设置主要使用pppoe-start脚本,用于启动拨号;

内容解读

1.执行pppoe.conf,获取对应变量;
2.检测是否已经启动拨号,若启动则退出;(检测原理:kill -0 $PID3.启动连接,并检查是否建立连接

4.状态脚本

rp-pppoe中设置主要使用pppoe-status脚本,用于检测拨号状态;

内容解读

1.检测是否已启动拨号
2.若已经启动,则打印网口信息(/sbin/ifconfig $IF3.根据(/etc/ppp/ppp*.pid和/var/run/ppp*.pid)可获取新生成的ppp名称

5.连接脚本

rp-pppoe中设置主要使用pppoe-connect脚本,用于拨号连接;

5.1.内容解读

1.执行pppoe.conf,获取对应变量;
2.检测变量的有效性
3.若在linux系统,将对应网口的MTU设置为1500,并加载ppp_generic,ppp_async,ppp_synctty模块;
4.若在linux系统,若设置了$LINUX_PLUGIN,加载pppox和pppoe模块
5.若使用同步的PPP,则设置相关变量;
6.设置PPPOE接入器名称(ACNAME)和PPPOE服务器名称(SERVICENAMEOPT7.设置MSS参数
8.设置DNS获取方式
9.若使用后台守护,则qiyong
10.开启PPP防火墙
11.实际执行命令:/usr/bin/setsid /usr/sbin/pppd pty '/usr/sbin/pppoe -p /var/run/pppoe.conf-eth0_pppoe.pid.pppoe -I eth0 -T 80 -U  -m 1412' noipdefault noauth default-asyncmap defaultroute hide-password nodetach usepeerdns mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj novjccomp user sugao_pppoe2 lcp-echo-interval 20 lcp-echo-failure 3 debug

5.2.命令分析

/usr/bin/setsid /usr/sbin/pppd pty ‘/usr/sbin/pppoe -p /var/run/pppoe.conf-eth1_pppoe.pid.pppoe -I eth1 -T 80 -U -m 1412’ noipdefault noauth default-asyncmap defaultroute hide-password nodetach usepeerdns mtu 1492 mru 1492 noaccomp nodeflate nopcomp novj novjccomp user sugao_pppoe2 lcp-echo-interval 20 lcp-echo-failure 3 debug

5.2.1.1.拨号成功信息

Using interface ppp0
Connect: ppp0 <--> /dev/pts/2
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x6fad76e4>]
rcvd [LCP ConfReq id=0x1 <mru 1492> <auth chap MD5> <magic 0x8bd60b9>]
sent [LCP ConfAck id=0x1 <mru 1492> <auth chap MD5> <magic 0x8bd60b9>]
rcvd [LCP ConfAck id=0x1 <mru 1492> <magic 0x6fad76e4>]
sent [LCP EchoReq id=0x0 magic=0x6fad76e4]
rcvd [LCP EchoReq id=0x0 magic=0x8bd60b9]
sent [LCP EchoRep id=0x0 magic=0x6fad76e4]
rcvd [CHAP Challenge id=0xbf <4b949d6c532d4ab15d6bea52cf9293103edeedab3a>, name = "dexin"]
Warning - secret file /etc/ppp/chap-secrets has world and/or group access
sent [CHAP Response id=0xbf <fcfa00e0d14dd08ca7a50330e165899a>, name = "sugao_pppoe2"]
rcvd [LCP EchoRep id=0x0 magic=0x8bd60b9]
rcvd [CHAP Success id=0xbf "Access granted"]
CHAP authentication succeeded: Access granted
CHAP authentication succeeded
sent [CCP ConfReq id=0x1 <bsd v1 15>]
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns2 0.0.0.0>]
rcvd [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
sent [CCP ConfRej id=0x1 <deflate 15> <deflate(old#) 15>]
rcvd [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 172.168.10.2>]
sent [IPCP ConfRej id=0x1 <compress VJ 0f 01>]
rcvd [CCP ConfAck id=0x1 <bsd v1 15>]
rcvd [IPCP ConfNak id=0x1 <addr 182.168.8.33> <ms-dns1 192.168.58.1> <ms-dns2 172.10.1.2>]
sent [IPCP ConfReq id=0x2 <addr 182.168.8.33> <ms-dns1 192.168.58.1> <ms-dns2 172.10.1.2>]
rcvd [CCP ConfReq id=0x2 <bsd v1 15>]
sent [CCP ConfAck id=0x2 <bsd v1 15>]
BSD-Compress (15) compression enabled
rcvd [IPCP ConfReq id=0x2 <addr 172.168.10.2>]
sent [IPCP ConfAck id=0x2 <addr 172.168.10.2>]
rcvd [IPCP ConfAck id=0x2 <addr 182.168.8.33> <ms-dns1 192.168.58.1> <ms-dns2 172.10.1.2>]
not replacing default route to eth0 [192.168.1.1]
local  IP address 182.168.8.33
remote IP address 172.168.10.2
primary   DNS address 192.168.58.1
secondary DNS address 172.10.1.2
Script /etc/ppp/ip-up started (pid 26799)
Script /etc/ppp/ip-up finished (pid 26799), status = 0x0

5.2.1.2.拨号失败信息

Using interface ppp0
Connect: ppp0 <--> /dev/pts/2
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]

root@msos:/home/sugao/mscore/extern/src/ppp# sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
sent [LCP ConfReq id=0x1 <mru 1492> <magic 0x5ac6f784>]
LCP: timeout sending Config-Requests
Connection terminated.
Modem hangup
Waiting for 1 child processes...
  script /usr/sbin/pppoe -p /var/run/pppoe.conf-eth0_pppoe.pid.pppoe -I eth0 -T 80 -U  -m 1412, pid 27249
pppoe: Timeout waiting for PADO packets
Script /usr/sbin/pppoe -p /var/run/pppoe.conf-eth0_pppoe.pid.pppoe -I eth0 -T 80 -U  -m 1412 finished (pid 27249), status = 0x1

5.2.1.3.结束拨号连接信息

Script /usr/sbin/pppoe -p /var/run/pppoe.conf-eth0_pppoe.pid.pppoe -I eth1 -T 80 -U  -m 1412 finished (pid 26788), status = 0x89
Modem hangup
Connect time 2.0 minutes.
Sent 0 bytes, received 0 bytes.
Script /etc/ppp/ip-down started (pid 26960)
Connection terminated.
Script /etc/ppp/ip-down finished (pid 26960), status = 0x0

pppd参考文档

6.断开脚本

rp-pppoe中设置主要使用pppoe-stop脚本,用于断开拨号连接,主要原理是根据生成的pidfile中的pid进行杀死进程,主要包括pppd和pppoe-connect进程。

阅读更多
换一批

没有更多推荐了,返回首页