Ubuntu24.04搭建PPPoE Server并进行拨号测试
本文主要记录如何搭建PPPoE Server,并进行拨号连接,并不包含PPPoE协议的细节。
本文在VMWare虚拟机Ubuntu24.04上搭建PPPoE Server,然后Windows10虚拟机通过PPPoE拨号获取IP,并进行上网。
拓扑搭建
本文PPPoE Server拨号实验所用设备:
- 能上外网的PC Win11(物理网卡:192.168.31.117,虚拟网卡:192.168.100.1)
- Ubuntu24.04虚拟机:NAT模式网卡ens33用来上外网(192.168.100.128),仅主机模式网卡ens37(PPPoE拨号)
- Windows10虚拟机:仅主机模式网卡Ethernet0。
具体拓扑如下图:
下面是用来进行拨号的虚拟网络配置:
其中VMnet8对应的虚拟机网卡ens33,VMnet2对应的虚拟机中的网卡为ens37。
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虚拟机配置如下:
搭建PPPoE Server
- 安装PPPoE Server:
sudo apt install pppoe
。 - 配置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 *
- 配置端口转发:
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
- 启动PPPoE Server:
sudo pppoe-server -I ens37 -L 192.168.84.1 -R 192.168.84.2 -N 5
Windows10进行拨号
重新配置DNS服务器为192.168.31.1,然后ping baidu.com
验证网络连接:
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宿主机,因此初步判断有两个可能:
- Win11宿主机不对ICMPv4回显
- Win11宿主机防火墙不允许ICMPv4包入站
当前基本上可以确定是防火墙的问题,因此增加一条ICMPv4报文的入站规则。创建步骤如下:
延申
如果宿主机上有多余网口,那么也可以通过桥接模式与拨号服务器(Ubuntu24.04虚拟机)连接,然后PPPoE Server在虚拟机对应接口上进行拨号,然后其他PC就可以通过网线连接到该网口,然后采用PPPoE拨号上网。
遗留问题
- PPPoE协议内容:PPPOE_百度百科
- pppoe-server-options配置说明以及chap认证细节:挑战握手认证协议_百度百科
参考文章
- 原文作者:生如夏花
- 原文链接:https://blduan.top/post/%E5%B7%A5%E5%85%B7%E4%BD%BF%E7%94%A8/ubuntu24.04%E6%90%AD%E5%BB%BApppoe-server%E5%B9%B6%E8%BF%9B%E8%A1%8C%E6%8B%A8%E5%8F%B7%E6%B5%8B%E8%AF%95/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。