# 30.4.使用以太网 PPP（PPPoE）

本节介绍如何设置基于以太网的 PPP（PPPoE）连接。

以下是一个可用的 **ppp.conf** 示例：

```ini
default:
  set log Phase tun command # 如有需要，可添加更详细的日志项
  set ifaddr 10.0.0.1/0 10.0.0.2/0

name_of_service_provider:
  set device PPPoE:xl1 # 将 xl1 替换为你的以太网设备
  set authname YOURLOGINNAME
  set authkey YOURPASSWORD
  set dial
  set login
  add default HISADDR
```

以 `root` 身份运行：

```sh
# ppp -ddial name_of_service_provider
```

在 **/etc/rc.conf** 中添加以下内容：

```ini
ppp_enable="YES"
ppp_mode="ddial"
ppp_nat="YES"	# 如果希望为本地网络启用 NAT，否则设为 NO
ppp_profile="name_of_service_provider"
```

## 30.4.1. 使用 PPPoE 服务标签

有时需要使用服务标签才能建立连接。服务标签用于区分连接到同一网络的不同 PPPoE 服务器。

服务标签信息通常会在 ISP 提供的文档中列出。

在万不得已的情况下，可以尝试安装 [net/rr-pppoe](https://cgit.freebsd.org/ports/tree/net/rr-pppoe/) 软件包或 Ports。不过请注意，这可能会将调制解调器重置为无效状态，因此在执行前请三思。更安全的做法是直接安装调制解调器随附的软件。然后进入程序的 **System** 菜单。配置文件名通常会列在其中，一般为 *ISP*。

该配置文件名（即服务标签）将作为 PPPoE 设置中 `set device` 的 provider 部分写入 **ppp.conf**。具体格式如下（详见 [ppp(8)](https://man.freebsd.org/cgi/man.cgi?query=ppp\&sektion=8\&format=html)）：

```sh
set device PPPoE:xl1:ISP
```

不要忘记将 *xl1* 替换为以太网设备的实际名称。

也不要忘记将 *ISP* 替换为实际的服务标签名。

更多信息可参考 Renaud Waldura 所著的 [Cheaper Broadband with FreeBSD on DSL](http://renaud.waldura.com/doc/freebsd/pppoe/)。

## 30.4.2. 搭配 3Com® HomeConnect™ ADSL Modem Dual Link 使用 PPPoE

该调制解调器不符合 [RFC 2516](http://www.faqs.org/rfcs/rfc2516.html) 所定义的 PPPoE 规范。

为了让 FreeBSD 能够与此设备通信，必须设置一个 sysctl 变量。可在开机时通过修改 **/etc/sysctl.conf** 实现自动设置：

```ini
net.graph.nonstandard_pppoe=1
```

或者可立即通过以下命令设置：

```sh
# sysctl net.graph.nonstandard_pppoe=1
```

不幸的是，由于这是系统范围的设置，因此无法同时与正常的 PPPoE 客户端或服务器以及 3Com® HomeConnect™ ADSL 调制解调器通信。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://handbook.bsdcn.org/di-30-zhang-ppp/30.4.-shi-yong-yi-tai-wang-ppppppoe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
