# 7.2.设置网络

设置有线或无线连接是 FreeBSD 用户的常见任务。本节将介绍如何识别有线和无线网络适配器以及如何配置它们。

在开始配置之前，必须了解以下网络数据：

* 网络是否启用了 DHCP
* 如果网络没有 DHCP，使用的静态 IP
* 子网掩码
* 默认网关的 IP 地址

> **技巧**
>
> 网络连接可能在安装时通过 [bsdinstall(8)](https://man.freebsd.org/cgi/man.cgi?query=bsdinstall\&sektion=8\&format=html) 配置。

## 7.2.1. 识别网络适配器

FreeBSD 支持多种有线和无线网络适配器。请检查所使用的 [FreeBSD 版本的硬件兼容性列表](https://www.freebsd.org/releases/)，以查看网络适配器是否受支持。

要获取系统中使用的网络适配器，可以执行以下命令：

```sh
% pciconf -lv | grep -A1 -B3 network
```

输出应类似于以下内容：

```sh
em0@pci0:0:25:0:        class=0x020000 rev=0x03 hdr=0x00 vendor=0x8086 device=0x10f5 subvendor=0x17aa subdevice=0x20ee
    vendor     = 'Intel Corporation' ①
    device     = '82567LM Gigabit Network Connection' ②
    class      = network
    subclass   = ethernet
--
iwn0@pci0:3:0:0:        class=0x028000 rev=0x00 hdr=0x00 vendor=0x8086 device=0x4237 subvendor=0x8086 subdevice=0x1211
    vendor     = 'Intel Corporation' ①
    device     = 'PRO/Wireless 5100 AGN [Shiloh] Network Connection' ②
    class      = network
```

在 `@` 符号之前的文本是控制设备的驱动程序名称。在本例中，分别是 [em(4)](https://man.freebsd.org/cgi/man.cgi?query=em\&sektion=4\&format=html) 和 [iwn(4)](https://man.freebsd.org/cgi/man.cgi?query=iwn\&sektion=4\&format=html)。

* ① 显示供应商的名称
* ② 显示设备的名称

> **注意**
>
> 只有在 FreeBSD 未正确检测到网卡时，才需要加载网卡模块。
>
> ```
> # kldload if_alc
> ```
>
> 若要在启动时作为模块加载驱动程序，请在 /boot/loader.conf 中加入以下行：\ <br>
>
> ```
> if_alc_load="YES"
> ```


---

# 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-7-zhang-wang-luo/7.2.-she-zhi-wang-luo.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.
