使用树莓派建立一个带有移动网络连接功能的路由器
树莓派 OpenWRT

> 
> 在你的网络路由器上使用 OpenWRT 获得更多控制功能。
> 
> 
> 


![](/data/attachment/album/202204/15/123813xtpegv7e5xvj7c7a.jpg "Mesh networking connected dots")


树莓派是一种小型单板电脑，尽管只有信用卡大小，但是能做许多事情。实际上，这个小电脑几乎可以成为你想让它成为的任何东西，只要你打开想象力。


树莓派爱好者已经做了许多不同的项目，从简单的程序到复杂的自动化项目和解决方案，如气象站，甚至智能家居设备。这篇文章将展示怎样使用 OpenWRT 项目将你的树莓派变成带有 LTE 移动网络连接功能的路由器。


### 关于 OpenWRT 和 LTE


[OpenWRT](https://openwrt.org/) 是一个利用 Linux 内核为嵌入式设备开发的开源项目，它已经存在超过 15 年了，拥有一个庞大而活跃的社区。


有许多使用 OpenWRT 的方法，但是它的主要目的还是用在路由器上。它提供了包管理功能和一个完全可写的文件系统，并且因为它的的开源属性，你可以查看和修改代码，并贡献到开源生态。如果你想对你的路由器获得更多的控制，这就是你想要的系统。


<ruby> 长期演进技术 <rt>  Long-term evolution </rt></ruby>（LTE）是一个基于 GSM/EGDE 和 UMTS/HSPA 技术的无线宽带通信标准。我使用的 LTE 调制解调器是一个 USB 设备，可以为树莓派电脑增加 3G 或 4G（LTE）蜂窝连接。


![Teltonika TRM240 modem](/data/attachment/album/202204/15/123837qmzh759hi2z6ouew.png "Teltonika TRM240 modem")


### 安装前的准备


对这个项目来说，你需要：


* 一个带有电源线的树莓派
* 一台运行　Linux　的电脑
* 一张至少 16GB 的 SD 储存卡
* 以太网线
* LTE 调制解调器（我使用的是 Teltonika [TRM240](https://teltonika-networks.com/product/trm240/)）
* 一张移动网络的 SIM 卡


### 安装 OpenWRT


首先，下载最新的 [兼容树莓派的 OpenWRT 的发布版本](https://downloads.openwrt.org/releases/19.07.7/targets/brcm2708/bcm2710/)。在 OpenWRT 官网，你可以看到 4 个镜像：两个 **ext4** 文件系统的和两个 **squashfs** 文件系统的。我使用 **ext4** 文件系统。你可以下载 **factory** 或者 **sysupgrade** 镜像，这两个都运行良好。


![OpenWRT image files](/data/attachment/album/202204/15/123837luqias8lnu8nuqa1.png "OpenWRT image files")


下载了镜像后，你按照 [以下的说明](https://opensource.com/article/17/3/how-write-sd-cards-raspberry-pi) 需要解压并安装它到 SD 卡上。这将会花些时间安装固件，需要些耐心。一旦安装完成，在你的 SD 卡上将会有两个分区。一个是用来放 bootloader ，另一个是 OpenWRT 系统。


### 启动系统


要启动你的新系统，插入 SD 卡到树莓派，用以太网线把树莓派和你的路由器（或者交换机）相连，然后点亮。


如果你有使用树莓派的经验，你可能习惯于通过终端使用 SSH 访问过它，或者通过显示器和键盘连接到树莓派。OpenWRT 工作有一点点不同。你与这个系统交互是通过网页浏览器，所以你必须能够通过网络来访问你的树莓派。


缺省状态下，树莓派使用的 IP 地址是：192.168.1.1。用来配置树莓派的计算机必须和树莓派在同一个子网中。如果你的网络没有使用 192.168.1.x 地址，或者你不能确定，在 GNOME 打开 “<ruby> 设置 <rt>  Settings </rt></ruby>” ，导航到网络设置，选择 “<ruby> 手动 <rt>  Manual </rt></ruby>” ，然后键入以下的 IP 地址和子网掩码：


* IP 地址：192.168.1.15
* 网络掩码：255.255.255.0


![IP addresses](/data/attachment/album/202204/15/123837fj0d5jqjrldld566.png "IP addresses")


在你的电脑上打开浏览器然后导航到 192.168.1.1 。这将打开一个验证网页，你可以登录到你的树莓派。


![OpenWRT login page](/data/attachment/album/202204/15/123838hj2af0wjfrd3fqdf.png "OpenWRT login page")


首次登录不需要密码，所以直接点击 “<ruby> 登录 <rt>  Login </rt></ruby>” 按钮继续。


### 设置网络连接


树莓派只有一个以太网口，而普通路由器有两个：一个是 WAN（有线区域网络）口，另一个是 LAN （本地区域网络）。


你有两个选择：


1. 使用你的以太网口接入互联网
2. 使用 WIFI 接入互联网


#### 使用以太网连接


你决定使用以太网，导航到 “<ruby> 网络 <rt>  Network </rt></ruby> → <ruby> 接口 <rt>  Interfaces </rt></ruby>”。在这个设置页面，按下与 “LAN” 接口对应的蓝色 “<ruby> 编辑 <rt>  Edit </rt></ruby>” 按钮。


![LAN interface](/data/attachment/album/202204/15/123838t51ez044nuu5benq.png "LAN interface")


应该会出现一个弹窗，在这个窗口中，你需要键入与你将要连接树莓派的路由器子网匹配的 IP 地址。如果需要的话，修改子网掩码，并输入树莓派将要连接的路由器的 IP 地址。


![Enter IP in the LAN interface](/data/attachment/album/202204/15/123838plnoy7zyyiemnne1.png "Enter IP in the LAN interface")


保存设置，然后通过以太网将你的树莓派连接到路由器。你现在可以用这个新的 IP 地址访问树莓派。


当你在把树莓派投入生产环境使用之前，确保为你的 OpenWRT 设置一个密码！


#### 使用 WiFi 连接


如果你想通过 WiFi 将树莓派连接到互联网，导航到 “<ruby> 网络 <rt>  Network </rt></ruby> → <ruby> 无线 <rt>  Wireless </rt></ruby>” 。在 “<ruby> 无线 <rt>  Wireless </rt></ruby>” 菜单里，按下蓝色的 “<ruby> 扫描 <rt>  Scan </rt></ruby>” 按钮查找你的家庭网络。


![Scan the network](/data/attachment/album/202204/15/123839lxuz8tgubdblgzxd.png "Scan the network")


在弹出的窗口中，找到你的 WiFi 网络然后连接它。不要忘记 “<ruby> 保存并应用 <rt>  Save and Apply </rt></ruby>” 设置。


在这 “<ruby> 网络 <rt>  Network </rt> → <ruby>  接口  <rt>   Interfaces  </rt> </ruby> ” 部分，你应该看到了一个新的接口。</ruby>


![New interface](/data/attachment/album/202204/15/123839b5yzqhfv6leb55zy.png "New interface")


当你在把树莓派投入生产环境使用之前，确保为你的 OpenWRT 设置一个密码！


### 安装必要的软件包


默认状态下，路由器并没有安装许多软件包。OpenWRT 提供了一个包管理器，带有一系列你需要安装的。导航到 “<ruby> 系统 <rt>  System </rt></ruby> → <ruby> 软件 <rt>  Software </rt></ruby>” 然后通过按下标有 “<ruby> 更新列表… <rt>  Update lists... </rt></ruby>” 的按钮来更新你的包管理器。


![Updating packages](/data/attachment/album/202204/15/123839anspzfff8smmxxxf.png "Updating packages")


你将会看到许多软件包；你需要安装以下这些：


* `usb-modeswitch`
* `kmod-mii`
* `kmod-usb-net`
* `kmod-usb-wdm`
* `kmod-usb-serial`
* `kmod-usb-serial-option`
* `kmod-usb-serial-wwan`（如果没有安装的话）


另外，[下载这个调制解调器管理软件包](https://downloads.openwrt.org/releases/packages-21.02/aarch64_cortex-a53/luci/luci-proto-modemmanager_git-21.007.43644-ab7e45c_all.ipk)，然后在弹出的窗口中按下标有 “<ruby> 上传软件包… <rt>  Upload Package... </rt></ruby>” 的按钮来安装它。重启树莓派让安装包生效。


### 设置移动网络接口


所有这些软件包被安装完之后，你可以设置移动网络接口。在连接调制解调器到树莓派之前，请阅读 [调制解调器的说明书](https://wiki.teltonika-networks.com/view/TRM240_SIM_Card)，对其进行设置。然后连接你的移动调制解调器到树莓派，然后等待一会直到调制解调器启动。


导航到 “<ruby> 网络 <rt>  Network </rt></ruby> → <ruby> 接口 <rt>  Interfaces </rt></ruby>”。在页面底部，按下 “<ruby> 添加一个新接口… <rt>  Add new interface... </rt></ruby>” 按钮。在弹出的窗口中，给你的接口起一个名字（比如 “mobile”），然后从下拉列表中选择 “ModemManager” 。


![Add a new mobile interface](/data/attachment/album/202204/15/123840gs5udo2dsobbmbmb.png "Add a new mobile interface")


按下一个标有 “<ruby> 创建接口 <rt>  Create Interface </rt></ruby>” 的按钮。你应该看到一个新的弹出窗口。这是设置接口的一个主窗口。在这个窗口中，选择你的调制解调器，然后键入像<ruby> 接入点名称 <rt>  Access Point Name </rt></ruby>（APN）或是 PIN 码之类的信息。


![Configuring the interface](/data/attachment/album/202204/15/123840y4xifbjzj8fqzjbu.png "Configuring the interface")


**注意：** 如果在列表中没有调制解调器设备出现，尝试重启树莓派或者安装 `kmod-usb-net-qmi-wwan` 软件包 。


当你已经配置完你的接口，按下 “<ruby> 保存 <rt>  Save </rt></ruby>” 然后 “<ruby> 保存并应用 <rt>  Save and Apply </rt></ruby>”。给系统一些生效的时间。如果一切正常，你应该看到像这样的一些东西。


![Configured interface](/data/attachment/album/202204/15/123840rbwocykiaobocai4.png "Configured interface")


如果你想通过接口查看你的网络连接，你可以使用 SSH 连接到你的树莓派 shell。在终端里，键入：



```
ssh root@192.168.1.1

```

缺省 IP 地址是 192.168.1.1：如果你修改了它，就用修改后的 IP 地址连接。当连接后，在终端里执行命令：



```
ping -I ppp0 google.com

```

如果一切正常运行，那么你应该从 Google 的服务器接收到 ping 回包 。


![Terminal interface](/data/attachment/album/202204/15/123840apwjwktttpq4i5qa.png "Terminal interface")


`ppp0` 是你创建的移动网络接口的默认接口名称。你可以通过使用 `ifconfig` 命令检查你的接口。它只显示活动的接口。


### 设置防火墙


要让移动网接口运行，你需要为移动网络接口和本地网络接口配置防火墙，以便引导流量到正确的接口。


导航到 “<ruby> 网络 <rt>  Network </rt></ruby> → <ruby> 防火墙 <rt>  Firewall </rt></ruby>”。在页面的底部，你应该看到一个叫做 “<ruby> 区域 <rt>  Zones </rt></ruby>” 的部分。


![Firewall zones](/data/attachment/album/202204/15/123841kac5yawr9rf11reb.png "Firewall zones")


设置防火墙最简单的方法就是调整 “wan” 区域。在 “<ruby> 已覆盖的网络 <rt>  Covered networks </rt></ruby>” 选项里按下 “<ruby> 编辑 <rt>  Edit </rt></ruby>” 按钮，选择你的移动网络接口，然后 “<ruby> 保存并应用 <rt>  Save and Apply </rt></ruby>” 你的设置。如果你不想用 WiFi 连接你的树莓派，你可以从 “<ruby> 已覆盖的网络 <rt>  Covered networks </rt></ruby>” 里删除 “wwan” 接口，或者关闭 WiFi 连接。


![Firewall zone settings](/data/attachment/album/202204/15/123841lhoy4nyw6phag6ge.png "Firewall zone settings")


如果你想为每个接口设置一个独立区域，只需创建一个新区域然后分配必要的接口即可。举个例子，你可能想有一个覆盖移动网络接口的区域，并且通过它来转发 LAN 接口流量。按下 “<ruby> 添加 <rt>  Name </rt></ruby>” 按钮，然后给你的区域 “<ruby> 命名 <rt>  Name </rt></ruby>”， 检查 “伪装” 复选框，选中 “<ruby> 已覆盖的网络 <rt>  Covered networks </rt></ruby>” ，并选择哪些区域可以转发其流量。


![Firewall zone settings](/data/attachment/album/202204/15/123841j1ghr2e92ebaheee.png "Firewall zone settings")


然后 “<ruby> 保存并应用 <rt>  Save and Apply </rt></ruby>” 这些修改。现在你有一个新的区域。


### 设置一个接入点


最后一步是为你的设备接入互联网设置一个网络接入点。要设置一个接入点，导航到 “<ruby> 网络 <rt>  Network </rt></ruby> → <ruby> 无线 <rt>  Wireless </rt></ruby>” 。你将会看到一个 WiFi 设备接口，一个名为 OpenWRT 的禁用的接入点，以及一个用于通过 WiFi 连接互联网的连接（如果你之前没有禁用或删除它）。在这个禁用的接口上，按下 “<ruby> 编辑 <rt>  Edit </rt></ruby>” 按钮，然后 “<ruby> 启用 <rt>  Enable </rt></ruby>” 该接口。


![Enabling wireless network](/data/attachment/album/202204/15/123842m99yjgw1j39j9dhr.png "Enabling wireless network")


如果你想，你可以通过编辑 “ESSID” 选项来修改接口名称。你也可以选择它要关联的网络。默认情况下，它会与 LAN 接口关联。


![Configuring the interface](/data/attachment/album/202204/15/123842iaiqxd88asqcyh9y.png "Configuring the interface")


要为这个接口添加密码，选择 “<ruby> 无线安全 <rt>  Wireless Security </rt></ruby>” 选项，选择 “WPA2-PSK” 加密方式然后在 “<ruby> 密钥 <rt>  Key </rt></ruby>” 选项字段键入接口的密码。


![Setting a password](/data/attachment/album/202204/15/123842snb29bh5cj12nnob.png "Setting a password")


然后 “<ruby> 保存并应用 <rt>  Save and Apply </rt></ruby>” 设置。如果设置正确的话，当用你的设备扫描可用接入点的话，你应该可以看到你分配了名称的新接入点。


### 额外的软件包


如果你愿意，你可以通过网页界面为你的路由器下载额外的软件包。只需到 “<ruby> 系统 <rt>  System </rt></ruby> → <ruby> 软件 <rt>  Software </rt></ruby>” 然后安装你想从列表或者互联网上下载的软件包并上传它。如果你在列表中没有看到任何软件包，请按下 “<ruby> 更新列表… <rt>  Update lists... </rt></ruby>” 按钮。


你也可以添加其他拥有适合与 OpenWRT 一起使用的软件包的仓库。软件包和它们的网页界面是分开安装的。软件包名称是以 “luci-” 开始的是网也界面软件包。


![Packages with luci- prefix](/data/attachment/album/202204/15/123842kjdhl54hh9rlqbae.png "Packages with luci- prefix")


### 试试看


这就是我的树莓派路由设置的过程。


![Raspberry Pi router](/data/attachment/album/202204/15/123843a89zopodddooo2h8.jpg "Raspberry Pi router")


从树莓派建立一个路由器不是很困难。缺点是树莓派只有一个以太网接口。你可以用一个 USB-to-Ethernet 适配器来增加更多的网口。不要忘记在接口的网站上设置网口。


OpenWRT 支持大量的移动调制解调器，你可以用管理调制解调器的通用工具 modemmanager 为它们设置移动网络接口。


你有没有把你的树莓派当作路由器使用？请在评论中告诉我们情况。




---


via: <https://opensource.com/article/21/3/router-raspberry-pi>


作者：[Lukas Janėnas](https://opensource.com/users/lukasjan) 选题：[lujun9972](https://github.com/lujun9972) 译者：[hwlife](https://github.com/hwlilfe) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
The Raspberry Pi is a small, single-board computer that, despite being the size of a credit card, is capable of doing a lot of things. In reality, this little computer can be almost anything you want to be. You just need to open up your imagination.

Raspberry Pi enthusiasts have made many different projects, from simple programs to complex automation projects and solutions like weather stations or even smart-home devices. This article will show how to turn your Raspberry Pi into a router with LTE mobile connectivity using the OpenWRT project.

## About OpenWRT and LTE

[OpenWRT](https://openwrt.org/) is an open source project that uses Linux to target embedded devices. It's been around for more than 15 years and has a large and active community.

There are many ways to use OpenWRT, but its main purpose is in routers. It provides a fully writable filesystem with package management, and because it is open source, you can see and modify the code and contribute to the ecosystem. If you would like to have more control over your router, this is the system you want to use.

Long-term evolution (LTE) is a standard for wireless broadband communication based on the GSM/EDGE and UMTS/HSPA technologies. The LTE modem I'm using is a USB device that can add 3G or 4G (LTE) cellular connectivity to a Raspberry Pi computer.

![Teltonika TRM240 modem Teltonika TRM240 modem](https://opensource.com/sites/default/files/uploads/lte_modem.png)

(Lukas Janenas, CC BY-SA 4.0)

## Prerequisites

For this project, you will need:

- A Raspberry Pi with a power cable
- A computer, preferably running Linux
- A microSD card with at least 16GB
- An Ethernet cable
- An LTE modem (I am using a Teltonika
[TRM240](https://teltonika-networks.com/product/trm240/)) - A SIM card for mobile connectivity

## Install OpenWRT

To get started, download the latest [Raspberry Pi-compatible release of OpenWRT](https://downloads.openwrt.org/releases/19.07.7/targets/brcm2708/bcm2710/). On the OpenWRT site, you see four images: two with **ext4** and two with **squashfs** filesystems. I use the **ext4** filesystem. You can download either the **factory** or **sysupgrade** image; both work great.

![OpenWRT image files OpenWRT image files](https://opensource.com/sites/default/files/uploads/imagefiles.png)

(Lukas Janenas, CC BY-SA 4.0)


Once you download the image, you need to extract it and install it on the SD card by [following these instructions](https://opensource.com/article/17/3/how-write-sd-cards-raspberry-pi). It can take some time to install the firmware, so be patient. Once it's finished, there will be two partitions on your microSD card. One is used for the bootloader and the other one for the OpenWRT system.

## Boot up the system

To boot up your new system, insert the microSD card into the Raspberry Pi, connect the Pi to your router (or a switch) with an Ethernet cable, and power it on.

If you're experienced with the Raspberry Pi, you may be used to accessing it through a terminal over SSH, or just by connecting it to a monitor and keyboard. OpenWRT works a little differently. You interact with this software through a web browser, so you must be able to access your Pi over your network.

By default, the Raspberry Pi uses this IP address: 192.168.1.1. The computer you use to configure the Pi must be on the same subnet as the Pi. If your network doesn't use 192.168.1.x addresses, or if you're unsure, open **Settings** in GNOME, navigate to network settings, select **Manual**, and enter the following IP address and Netmask:

**IP address:**192.168.1.15**Netmask:**255.255.255.0

![IP addresses IP addresses](https://opensource.com/sites/default/files/uploads/ipaddresses.png)

(Lukas Janenas, CC BY-SA 4.0)

Open a web browser on your computer and navigate to 192.168.1.1. This opens an authentication page so you can log in to your Pi.

![OpenWRT login page OpenWRT login page](https://opensource.com/sites/default/files/uploads/openwrt-login.png)

(Lukas Janenas, CC BY-SA 4.0)

No password is required yet, so just click the **Login** button to continue.

## Configure network connection

The Raspberry Pi has only one Ethernet port, while normal routers have a couple of them: one for WAN (wired area network) and the other for LAN (local area network). You have two options:

- Use your Ethernet port for network connectivity
- Use WiFi for network connectivity

**To use Ethernet:**

Should you decide to use Ethernet, navigate to **Network → Interfaces**. On the configuration page, press the blue **Edit** button that is associated with the **LAN** interface.

![LAN interface LAN interface](https://opensource.com/sites/default/files/uploads/lan-interface.png)

(Lukas Janenas, CC BY-SA 4.0)

A pop-up window should appear. In that window, you need to enter the IP address to match the subnet of the router to which you will connect the Raspberry Pi. Change the Netmask, if needed, and enter the IP address of the router the Raspberry Pi will connect to.

![Enter IP in the LAN interface Enter IP in the LAN interface](https://opensource.com/sites/default/files/uploads/lan-interface-ip.png)

(Lukas Janenas, CC BY-SA 4.0)

Save this configuration and connect your Pi to the router over Ethernet. You can now reach the Raspberry Pi with this new IP address.

Be sure to set a password for your OpenWRT router before you put it into production use!

**To use WiFi**

If you would like to connect the Raspberry Pi to the internet through WiFi, navigate to **Network → Wireless**. In the **Wireless** menu, press the blue **Scan** button to locate your home network.

![Scan the network Scan the network](https://opensource.com/sites/default/files/uploads/scannetwork.png)

(Lukas Janenas, CC BY-SA 4.0)

In the pop-up window, find your WiFi network and connect to it. Don't forget to **Save and Apply** the configuration.

In the **Network → Interfaces** section, you should see a new interface.

![New interface New interface](https://opensource.com/sites/default/files/uploads/newinterface.png)

(Lukas Janenas, CC BY-SA 4.0)

Be sure to set a password for your OpenWRT router before you put it into production use!

## Install the necessary packages

By default, the router doesn't have a lot of packages. OpenWRT offers a package manager with a selection of packages you need to install. Navigate to **System → Software** and update your package manager by pressing the button labeled "**Update lists…**".

![Updating packages Updating packages](https://opensource.com/sites/default/files/uploads/updatesoftwarelist.png)

(Lukas Janenas, CC BY-SA 4.0)

You will see a lot of packages; you need to install these:

- usb-modeswitch
- kmod-mii
- kmod-usb-net
- kmod-usb-wdm
- kmod-usb-serial
- kmod-usb-serial-option
- kmod-usb-serial-wwan (if it's not installed)

Additionally, [download this modemmanager package](https://downloads.openwrt.org/releases/packages-21.02/aarch64_cortex-a53/luci/luci-proto-modemmanager_git-21.007.43644-ab7e45c_all.ipk) and install it by pressing the button labeled **Upload Package…** in the pop-up window. Reboot the Raspberry Pi for the packages to take effect.

## Set up the mobile interface

After all those packages are installed, you can set up the mobile interface. Before connecting the modem to the Raspberry Pi read, the [modem instructions](https://wiki.teltonika-networks.com/view/TRM240_SIM_Card) to set it up. Then connect your mobile modem to the Raspberry Pi and wait a little until the modem boots up.

Navigate to **Network → Interface**. At the bottom of the page, press the **Add new interface…** button. In the pop-up window, give your interface a name (e.g., **mobile**) and select **ModemManager** from the drop-down list.

![Add a new mobile interface Add a new mobile interface](https://opensource.com/sites/default/files/uploads/addnewinterface.png)

(Lukas Janenas, CC BY-SA 4.0)

Press the button labeled **Create Interface**. You should see a new pop-up window. This is the main window for configuring the interface. In this window, select your modem and enter any other information like an Access Point Name (APN) or a PIN.

![Configuring the interface Configuring the interface](https://opensource.com/sites/default/files/uploads/configureinterface.png)

(Lukas Janenas, CC BY-SA 4.0)

**Note:** If no modem devices appear in the list, try rebooting your Raspberry Pi or installing the kmod-usb-net-qmi-wwan package.

When you are done configuring your interface, press **Save** and then **Save and Apply**. Give some time for the system to take effect. If everything went well, you should see something like this.

![Configured interface Configured interface](https://opensource.com/sites/default/files/uploads/configuredinterface.png)

(Lukas Janenas, CC BY-SA 4.0)

If you want to check your internet connection over this interface, you can use ssh to connect to your Raspberry Pi shell. In the terminal, enter:

`ssh root@192.168.1.1`


The default IP address is 192.168.1.1; if you changed it, then use that IP address to connect. When connected, execute this command in the terminal:

`ping -I ppp0 google.com`


If everything is working, then you should receive pings back from Google's servers.

![Terminal interface Terminal interface](https://opensource.com/sites/default/files/uploads/terminal.png)

(Lukas Janenas, CC BY-SA 4.0)

**ppp0** is the default interface name for the mobile interface you created. You can check your interfaces using **ifconfig**. It shows active interfaces only.

## Set up the firewall

To get the mobile interface working, you need to configure a firewall for the **mobile** interface and the **lan** interface to direct traffic to the correct interface.

Navigate to **Network → Firewall**. At the bottom of the page, you should see a section called **Zones**.

![Firewall zones Firewall zones](https://opensource.com/sites/default/files/uploads/firewallzones.png)

(Lukas Janenas, CC BY-SA 4.0)

The simplest way to configure the firewall is to adjust the **wan** zone. Press the **Edit** button and in the **Covered networks** option, select your **mobile** interface, and **Save and Apply** your configuration. If you don't want to use WiFi to connect to the internet, you can remove **wwan** from the **Covered networks** or disable the WiFi connection.

![Firewall zone settings Firewall zone settings](https://opensource.com/sites/default/files/uploads/firewallzonesettings.png)

(Lukas Janenas, CC BY-SA 4.0)

If you want to set up individual zones for each interface, just create a new zone and assign the necessary interfaces. For example, you may want to have a mobile zone that covers the mobile interface and is used to forward LAN interface traffic through it. Press the **Add** button, then **Name** your zone, check the **Masquerading** check box, select **Covered Networks**, and choose which zones can forward their traffic.

![Firewall zone settings Firewall zone settings](https://opensource.com/sites/default/files/uploads/firewallzonepriv.png)

(Lukas Janenas, CC BY-SA 4.0)

Then **Save and Apply** the changes. Now you have a new zone.

## Set up an Access Point

The last step is to configure a network with an Access Point for your devices to connect to the internet. To set up an Access Point, navigate to **Network → Wireless**. You will see a WiFi device interface, a disabled Access Point named **OpenWRT**, and a connection that is used to connect to the internet over WiFi (if you didn't disable or delete it earlier). On the **Disable** interface, press the **Edit** button, then **Enable** the interface.

![Enabling wireless network Enabling wireless network](https://opensource.com/sites/default/files/uploads/enablewirelessnetwork.png)

(Lukas Janenas, CC BY-SA 4.0)

If you want, you can change the interface name by editing the **ESSID** option. You can also select which network it will be associated with. By default, it with be associated with the **lan** interface.

![Configuring the interface Configuring the interface](https://opensource.com/sites/default/files/uploads/interfaceconfig.png)

(Lukas Janenas, CC BY-SA 4.0)

To add a password for this interface, select the **Wireless Security** tab. In the tab, select the encryption **WPA2-PSK** and enter the password for the interface in the **Key** option field.

![Setting a password Setting a password](https://opensource.com/sites/default/files/uploads/interfacepassword.png)

(Lukas Janenas, CC BY-SA 4.0)

Then **Save and Apply** the configuration. If the configuration was set correctly, when scanning available Access Points with your device, you should see a new Access Point with the name you assigned.

## Additional packages

If you want, you can download additional packages for your router through the web interface. Just go to **System → Software** and install the package you want from the list or download it from the internet and upload it. If you don't see any packages in the list, press the **Update lists…** button.

You can also add other repositories that have packages that are good to use with OpenWRT. Packages and their web interfaces are installed separately. The packages that start with the prefix **luci-** are web interface packages.

![Packages with luci- prefix Packages with luci- prefix](https://opensource.com/sites/default/files/uploads/luci-packages.png)

(Lukas Janenas, CC BY-SA 4.0)

## Give it a try

This is what my Raspberry Pi router setup looks like.

![Raspberry Pi router Raspberry Pi router](https://opensource.com/sites/default/files/uploads/raspberrypirouter.jpg)

(Lukas Janenas, CC BY-SA 4.0)

It not difficult to build a router from a Raspberry Pi. The downside is that a Raspberry Pi has only one Ethernet port. You can add more ports with a USB-to-Ethernet adapter. Don't forget to configure the port on the interface's website.

OpenWRT supports a large number of mobile modems, and you can configure the mobile interface for any of them with the modemmanager, which is a universal tool to manage modems.

Have you used your Raspberry Pi as a router? Let us know how it went in the comments.

## 4 Comments