本文主要记录如何搭建PPPoE Server,并进行拨号连接,并不包含PPPoE协议的细节。

本文在VMWare虚拟机Ubuntu24.04上搭建PPPoE Server,然后Windows10虚拟机通过PPPoE拨号获取IP,并进行上网。

拓扑搭建

本文PPPoE Server拨号实验所用设备:

  1. 能上外网的PC Win11(物理网卡:192.168.31.117,虚拟网卡:192.168.100.1)
  2. Ubuntu24.04虚拟机:NAT模式网卡ens33用来上外网(192.168.100.128),仅主机模式网卡ens37(PPPoE拨号)
  3. Windows10虚拟机:仅主机模式网卡Ethernet0。

具体拓扑如下图:

VMWare之PPPoE拓扑搭建

下面是用来进行拨号的虚拟网络配置:

VMnet2之PPPoE拨号 其中VMnet8对应的虚拟机网卡ens33,VMnet2对应的虚拟机中的网卡为ens37。

Ubuntu24.04虚拟机配置: Ubuntu24.04配置VMnet2网络

blduan@ubuntu24:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.128  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::20c:29ff:fe74:4fda  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:74:4f:da  txqueuelen 1000  (Ethernet)
        RX packets 8316  bytes 1334191 (1.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7494  bytes 875930 (875.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::20c:29ff:fe74:4fe4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:74:4f:e4  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 44  bytes 10892 (10.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 132  bytes 12279 (12.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 132  bytes 12279 (12.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

blduan@ubuntu24:~$ sudo cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        ens33:
            dhcp4: true
            optional: true
        ens37:
            dhcp4: true
            optional: true
    version: 2

Windows10虚拟机配置如下:

Windows配置VMnet2网络

搭建PPPoE Server

  1. 安装PPPoE Server:sudo apt install pppoe
  2. 配置PPPoE Server:(如果不存在pppoe-server-options则新建)
blduan@ubuntu24:~$ sudo cat /etc/ppp/pppoe-server-options
auth
require-chap
logfile /var/log/pppd.log
+ipv6

blduan@ubuntu24:~$ sudo cat /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
123456 * 123456 *
  1. 配置端口转发:
blduan@ubuntu24:~$ sudo iptables -t nat -A POSTROUTING -s 192.168.84.0/24 -o ens33 -j MASQUERADE
blduan@ubuntu24:~$ sudo iptables -t nat -S
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-N DOCKER
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -s 192.168.84.0/24 -o ens33 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
  1. 启动PPPoE Server:sudo pppoe-server -I ens37 -L 192.168.84.1 -R 192.168.84.2 -N 5

Windows10进行拨号

PPPoE拨号: Windows10PPPoE拨号

Windows10拨号结果: Windows拨号结果

重新配置DNS服务器为192.168.31.1,然后ping baidu.com验证网络连接: PPPoE配置DNS并ping验证网络连通性

Ubuntu24.04响应拨号

新增了一个ppp0接口,用于建立和Windows之间的连接

blduan@ubuntu24:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.128  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::20c:29ff:fe74:4fda  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:74:4f:da  txqueuelen 1000  (Ethernet)
        RX packets 12621  bytes 1717259 (1.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11501  bytes 1417043 (1.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::20c:29ff:fe74:4fe4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:74:4f:e4  txqueuelen 1000  (Ethernet)
        RX packets 322  bytes 33544 (33.5 KB)
        RX errors 0  dropped 132  overruns 0  frame 0
        TX packets 227  bytes 44714 (44.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 132  bytes 12279 (12.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 132  bytes 12279 (12.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1480
        inet 192.168.84.1  netmask 255.255.255.255  destination 192.168.84.5
        inet6 fe80::403a:cc9b:6ace:db0f  prefixlen 128  scopeid 0x20<link>
        ppp  txqueuelen 3  (Point-to-Point Protocol)
        RX packets 41  bytes 3618 (3.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 38  bytes 7369 (7.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
blduan@ubuntu24:~$ ps -aux | grep ppp
root        2166  0.0  0.0   2724  1152 ?        S    16:25   0:00 pppoe-server -I ens37 -L 192.168.84.1 -R 192.168.84.2 -N 5
root        2290  0.0  0.0  14768  6016 ?        Ss   16:39   0:00 pppd pty /usr/sbin/pppoe -n -I ens37 -e 1:00:0c:29:72:32:e3 -S '' file /etc/ppp/pppoe-server-options 192.168.84.1:192.168.84.2 nodetach noaccomp nopcomp default-asyncmap mru 1492 mtu 1492

问题解决

Ubuntu24.04虚拟机ping不通Win10宿主机IP,但可以ping通外网

根据拓扑排查到Ubuntu24.04虚拟机可以ping通虚拟DHCP服务器(192.168.100.2)和baidu.com,但是无法ping通Win11宿主机,因此初步判断有两个可能:

  1. Win11宿主机不对ICMPv4回显
  2. Win11宿主机防火墙不允许ICMPv4包入站

Ubuntu24.04虚拟机ping结果: Ubuntu24.04ping结果

查看配置发现ICMPv4回显: ICMPv4回显配置

当前基本上可以确定是防火墙的问题,因此增加一条ICMPv4报文的入站规则。创建步骤如下: 创建ICMPv4入站规则1 创建ICMPv4入站规则2 创建ICMPv4入站规则3

接下来在进行ping测试: ping测试结果

延申

如果宿主机上有多余网口,那么也可以通过桥接模式与拨号服务器(Ubuntu24.04虚拟机)连接,然后PPPoE Server在虚拟机对应接口上进行拨号,然后其他PC就可以通过网线连接到该网口,然后采用PPPoE拨号上网。

遗留问题

  1. PPPoE协议内容:PPPOE_百度百科
  2. pppoe-server-options配置说明以及chap认证细节:挑战握手认证协议_百度百科

参考文章

VMware虚拟机 之 NAT模式详解_vmware nat模式-CSDN博客