pppoe in ubuntu 18.04
在18.04中,ubuntu引入了netplan,netplan只支持networkd和NetworkManager渲染,不直接支持pppoe的设置
- 方案一: 删除netplan,使用ifupdown + ppppoeconf,回归到Ubuntu 16.04之前的状态
- 方案二: networkd + networkd-dispatcher + ppp
1. Install networkd, networkd-dispatcher, pppoe
sudo apt install networkd networkd-dispatcher pppoe
We won’t install pppoeconf
, because it depends on ifupdown
2. Configure netplan to use networkd as render
/etc/netplan/enp3s0.yaml
----------------------------------------------------------
network:
version: 2
renderer: networkd
ethernets:
enp4s0:
dhcp4: yes
dhcp6: yes
3. Configure pppoe
Edit to add username and interface /etc/ppp/peers/dsl-provider
/etc/ppp/peers/dsl-provider
--------------------------------------------------------
# lines in file you need to notice
user *****
pty "/usr/sbin/pppoe -I enp4s0 -T 80 -m 1452"
# replace the local route
defaultroute
replacedefaultroute
Edit to add password in /etc/ppp/pap-secrets
and /etc/ppp/chap-secrets
/etc/ppp/pap-secrets, /etc/ppp/chap-secrets
--------------------------------------------------------
<username> * <password>
Now, you can pon dsl-provider to connect or poff dsl-provider to disconnect
4. 使用networkd-dispatcher实现开机启动和网络重启时自动连接
networkd-dispatcher能够在网络状态改变时执行相应的脚本
/etc/networkd-dispatcher/routable.d/00-ppp
--------------------------------------------------------
#!/bin/bash
# log file
readonly LOG_FILE="/home/fancy/log/pppoe.log"
mkdir -p $(dirname $LOG_FILE) && touch $LOG_FILE
chown fancy $LOG_FILE
exec 1>>$LOG_FILE
exec 2>&1
date +"%m/%d/%Y %H:%M:%S $IFACE $STATE"
# record enp4s0 ip address to server
[ $IFACE = "enp4s0" ] \
&& echo "post-enp4s0:" \
&& bash /home/fancy/scripts/01_route_in_tju.sh \
&& bash /home/fancy/scripts/00_record_ip_to_server.sh
# if event from enp4s0, and the ppp0 daemon not exists, then start pppoe connection
# note /var/run/ppp0.pid is not reliable
pid=`pgrep -f /usr/sbin/pppd`
[ $? -ne 0 ] && [ $IFACE = "enp4s0" ] && echo "start pppoe" && pon dsl-provider
# if ppp0 connected, do something
[ $IFACE = "ppp0" ] && echo "ppp0 connected"
make it executable
sudo chmod u+x /etc/networkd-dispatcher/routable.d/00-ppp