服务器环境:Centos 7.5 64位
1. 安装ppp和xl2tp
1 2 3 |
yum -y install ppp wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/x/xl2tpd-1.3.8-3.el7.x86_64.rpm rpm -ivh xl2tpd-1.3.8-3.el7.x86_64.rpm |
2. 配置xl2tpd.conf
文件地址: /etc/xl2tpd/xl2tpd.conf
备份原有的配置文件并删除,然后编辑:
1 2 3 4 5 6 7 |
vi /etc/xl2tpd/xl2tpd.conf [lac ifreevpn] //ifreevpn为vpn名称 name = VPN用户名 lns = VPN服务器地址 pppoptfile = /etc/ppp/peers/ifreevpn.l2tpd //拨号时使用的配置文件 ppp debug = no |
3. 编辑拨号配置文件:
文件路径:/etc/ppp/peers/ifreevpn.l2tpd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
vi /etc/ppp/peers/ifreevpn.l2tpd remotename ifreevpn user "VPN用户名" password "VPN密码" unit 0 mtu 1400 nodeflate nobsdcomp noauth persist nopcomp noaccomp maxfail 5 debug |
4. 启动xl2tpd(不代表启动连接VPN)
1 |
xl2tpd -c "/etc/xl2tpd/xl2tpd.conf" |
5. 开始拨号
1 |
echo 'c ifreevpn' > /var/run/xl2tpd/l2tp-control |
6. 添加默认路由指向拨号接口
1 2 3 4 5 6 7 8 9 10 11 12 |
ip route replace default dev ppp0 route -n //查看路由是否指向ppp0 [root@localhost xl2tpd]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 ppp0 0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 enp0s3 10.8.0.0 192.168.1.1 255.255.255.0 UG 0 0 0 enp0s3 192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3 100.1.1.1 192.168.3.1 255.255.255.255 UGH 0 0 0 enp0s3 100.1.1.1 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0 |
7. 断开连接
1 |
echo 'd ifreevpn' > /var/run/xl2tpd/l2tp-control |