2-Openwrt ipv6之-pppoev6客户端
pppoe拨号方式上网,ubunut服务器需要有pppoe-server也要有dhcpv6-server,路由器端需要ppp-client,也要odhcp6c指向pppoe-wan端口。
1. PPPOEv6客户端启动过程
pppoe拨号为wan上面的另一种方式,所以需要将uci里面的上网模式proto 改成pppoe
config interface 'wan'
option ipv6 '1'
option def_ifname 'eth1'
option ifname 'eth1'
option macaddr 'DC:4B:DD:1d:fa:49'
option web_proto 'pppoe'
option proto 'pppoe'
option pppoe_username 'WkhPTUVfRkE0OF81Rw=='
option username 'ZHOME_FA48_5G'
option pppoe_password 'MTIzNDU2Nzg='
option password '12345678'
option pppoe_peerdns '1'
option peerdns '1'
option pppoe_advance '0'
option sdial '0'
config interface 'wan6'
option ifname @wan
option proto 'dhcpv6'
类似上面的pppoe拨号的启动脚本也在./lib/netifd/proto/ppp.sh
脚本里面的ppp_generic_setup
函数
proto_run_command "$config" /usr/sbin/pppd \
nodetach ipparam "$config" \
ifname "$pppname" \
${localip:+$localip:} \
${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adap
${ipv6:++ipv6} \
${autoipv6:+set AUTOIPV6=1} \
${ip6table:+set IP6TABLE=$ip6table} \
${peerdns:+set PEERDNS=$peerdns} \
nodefaultroute \
usepeerdns \
$demand $persist maxfail $maxfail \
${holdoff:+holdoff "$holdoff"} \
${username:+user "$username" password "$password"} \
${connect:+connect "$connect"} \
${disconnect:+disconnect "$disconnect"} \
ip-up-script /lib/netifd/ppp-up \
ipv6-up-script /lib/netifd/ppp6-up \
ip-down-script /lib/netifd/ppp-down \
ipv6-down-script /lib/netifd/ppp-down \
${mtu:+mtu $mtu mru $mtu} \
"$@" $pppd_options
pppoe的uci在官网可以看到:
https://openwrt.org/docs/guide-user/network/wan/wan_interface_protocols
Name | Type | Required | Description | |
---|---|---|---|---|
device | file path | yes | Modem device node | |
username | string | no(?) | Username for PAP/CHAP authentication | |
password | string | no(?) | Password for PAP/CHAP authentication | |
connect | file path | no | Path to custom PPP connect script | |
disconnect | file path | no | Path to custom PPP disconnect script | |
keepalive | number | no | Number of unanswered echo requests before considering | the peer dead. The interval between echo requests is 5 seconds. |
peerdns | boolean | no | Use peer-assigned DNS server(s) | |
dns | list of ip addresses | no | Override peer-assigned DNS server(s) | |
ipv6 | [0,1,auto] | no auto | Enable IPv6 on the PPP link 0: IPv6 disabled 1: IPv6 enabled auto: | IPv6 enabled. DHCPv6 client enabled. |
pppd_options | string | no | Additional command line arguments to pass to the pppd daemon |
刚开始只会有ppp的进程:
root@zihome:/# ps | grep ppp
32025 root 1720 S /usr/sbin/pppd nodetach ipparam wan ifname pppoe-wan +ipv6 set PEERDNS=1 nodefaultroute usepeerdns maxfail 1 user ubuntu password pppoe ip-up-script /lib/netifd/
等到pppoe-wan起来之后,才会自动启动odhcp6c进程
root@zihome:/# ps | grep ppp
32025 root 1720 S /usr/sbin/pppd nodetach ipparam wan ifname pppoe-wan +ipv6 set PEERDNS=1 nodefaultroute usepeerdns maxfail 1 user ubuntu password pppoe ip-up-script /lib/netifd/
32067 root 844 S odhcp6c -s /lib/netifd/dhcpv6.script -P0 -t120 pppoe-wan
2. pppoe拨号过程
ubuntu上面启动pppoe-server,sudo pppoe-server -I eth0 -L 100.0.0.1 -R 100.0.0.100 -N 20
,服务器IP为100.0.0.1,起始地址为从100.0.0.100开始分配。
1.IPV4地址获取
这时候路由器设置成pppoe模式拨号,这时候路由器端的pppd进程会发送``PPP IPV6`消息去请求IP地址,请求成功之后,在ubuntu上面会出现一个ppp0的接口,路由器上面会生成一个pppoe-wan的接口。ubuntu的IP为100.0.0.1,路由器的IP为100.0.0.100
2.本地链路IPV6地址获取
因为pppoe-wan端口没有MAC地址,所以没办法自己根据EUI规则生成一个本地地址,当pppoe添加了ipv6的选项之后
- pppoe-server会发送
PPP IPV6CP
的REQUEST数据包,里面附带一个它要生成的本地链路IPV6地址,询问P-T-P的对方路由器我是否可以用这个地址,路由器会返回一个PPP IPV6CP
的ACK包,这时候pppoe-server的ppp0端口就会生成一个本地链路IPV6地址fe80::70b2:2149:2eea:8daf
- 同样的路由器也会发送
PPP IPV6CP
的REQUEST数据包,里面附带一个它要生成的本地链路IPV6地址,询问P-T-P的对方pppoe-server我是否可以用这个地址,pppoe-server会返回一个PPP IPV6CP
的ACK包,这时候路由器的pppoe-wan端口就会生成一个本地链路IPV6地址fe80::14ec:b7:dc40:32f6
ubuntu上面会出现一个ppp0的端口,路由器可以正常ping 100.0.0.100
linye@linye-ubuntu:~$ ifconfig ppp0
ppp0 Link encap:Point-to-Point Protocol
inet addr:100.0.0.1 P-t-P:100.0.0.100 Mask:255.255.255.255
inet6 addr: fe80::70b2:2149:2eea:8daf/10 Scope:Link
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1480 Metric:1
RX packets:139 errors:0 dropped:0 overruns:0 frame:0
TX packets:22 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:8730 (8.7 KB) TX bytes:1666 (1.6 KB
路由器上面会出现一个pppoe-wan的端口,路由器可以正常ping 100.0.0.1
root@zihome:/# ifconfig pppoe-wan
pppoe-wan Link encap:Point-to-Point Protocol
inet addr:100.0.0.100 P-t-P:100.0.0.1 Mask:255.255.255.255
inet6 addr: fe80::14ec:b7:dc40:32f6/10 Scope:Link
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1480 Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:220 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1666 (1.6 KiB) TX bytes:13939 (13.6 KiB)
PPP IPV6CP
请求成功之后会,两端都有各自的本地链路IPV6地址,后面就可以启动odhcp6c客户端去获取ipv6全球地址了。
3.全局IPV6地址获取
ipv6的dhcpv6服务器是要建立在ppp0/pppoe-wan端口的基础上,所以要在ppp0拨号成功后,在路由器odhcp6c客户端的DHCP请求超时之前,ubuntu要启动在ppp0端口上的dibbler服务器。
修改
sudo vim /etc/dibbler/server.conf里面的端口为ppp0
启动dibbler服务器
sudo /etc/init.d/dibbler-server start
后面就是走正常的dhcpv6协议了,odhcp6c进程会在pppoe-wan启动之后自动被拉起来,开始请求dhcpv6地址。
ping本地链路地址的时候使用ping6指定端口
ping6 -I ppp0 fe80::2214:7ff:fe11:2a21
3. IPV4和IPV6的pppoe链路单独分开
路由器支持ipv4和ipv6的pppoe在同一个会话pppoe-wan,也可以支持ipv4和ipv6在不同的会话,ipv4位于pppoe-wan,ipv6位于pppoe-wan2。
当在同一会话时,跟上面说到的配置一致
config interface 'wan'
option ipv6 '1'
option def_ifname 'eth1'
option ifname 'eth1'
option macaddr 'DC:4B:DD:1d:fa:49'
option web_proto 'pppoe'
option proto 'pppoe'
option pppoe_username 'WkhPTUVfRkE0OF81Rw=='
option username 'ZHOME_FA48_5G'
option pppoe_password 'MTIzNDU2Nzg='
option password '12345678'
option pppoe_peerdns '1'
option peerdns '1'
option pppoe_advance '0'
option sdial '0'
config interface 'wan6'
option ifname 'pppoe-wan'
option proto 'dhcpv6'
当在两个会话时,添加一个wan2,把wan的ipv6设置为0,wan6的ifname改成pppoe-wan2
config interface 'wan'
option ipv6 '0'
option def_ifname 'eth1'
option ifname 'eth1'
option macaddr 'DC:4B:DD:1d:fa:49'
option web_proto 'pppoe'
option proto 'pppoe'
option pppoe_username 'WkhPTUVfRkE0OF81Rw=='
option username 'ZHOME_FA48_5G'
option pppoe_password 'MTIzNDU2Nzg='
option password '12345678'
option pppoe_peerdns '1'
option peerdns '1'
option pppoe_advance '0'
option sdial '0'
config interface 'wan2'
option ipv6 '1'
option def_ifname 'eth1'
option ifname 'eth1'
option macaddr 'DC:4B:DD:1d:fa:49'
option web_proto 'pppoe'
option proto 'pppoe'
option pppoe_username 'WkhPTUVfRkE0OF81Rw=='
option username 'ZHOME_FA48_5G'
option pppoe_password 'MTIzNDU2Nzg='
option password '12345678'
option pppoe_peerdns '1'
option peerdns '1'
option pppoe_advance '0'
option sdial '0'
config interface 'wan6'
option ifname 'pppoe-wan2'
option proto 'dhcpv6'