您的位置:

OpenWrt WAN 口设置

一、WAN 口设置

在 OpenWrt 中,WAN 口是指连接至 Internet 的接口,它通常是一个物理接口(例如一个 Ethernet 接口或一个 USB 接口)。为了让 OpenWrt 能够连接至 Internet,需要设置 WAN 口。

首先,在“网络”选项卡下,点击“接口”。在这个界面中,可以看到已经配置好的 WAN 和 LAN 接口。如果需要编辑 WAN 接口,则需要点击相应的“编辑”按钮。

config interface 'wan'
    option ifname 'eth0'
    option proto 'dhcp'

这个配置文件会将 WAN 接口命名为 eth0,并启用 DHCP 协议获取 IP 地址。

如果想要使用一个静态 IP 地址,则需要将 proto 配置为 static,并加入 IP 地址、子网掩码和网关信息。

config interface 'wan'
    option ifname 'eth0'
    option proto 'static'
    option ipaddr '192.168.1.100'
    option netmask '255.255.255.0'
    option gateway '192.168.1.1'

二、 PPPoE 连接

除了 DHCP 和静态 IP 地址之外,PPPoE 连接是连接至 Internet 的另一种流行的方式。

在“网络”选项卡下,点击“接口”,如上面所述。然后,点击“添加新接口”,在出现的窗口中选择“PPPoE 客户端”。

在配置文件中,需要设置 WAN 接口的用户名、密码和服务提供商的名称。

config interface 'wan'
    option ifname 'eth0'
    option proto 'pppoe'
    option username 'myusername'
    option password 'mypassword'
    option service 'myservice'

三、 3G/4G 上网

对于没有固定接入点的应用场景,可以考虑使用 3G/4G 上网。

在“网络”选项卡下,点击“接口”,如上面所述。然后,点击“添加新接口”,在出现的窗口中选择“3G/4G”。

根据使用模块进行相应设置,例如 Quectel EC20。在这个配置文件中,需要设置 APN 以及拨号号码。

config interface 'wan'
    option ifname 'wwan0'
    option proto '3g'
    option apn 'myapn'
    option dialnumber '*99#'

四、 双 WAN 口负载均衡

在某些情况下,可能需要使用多个物理 WAN 口连接至不同的服务提供商或多个不同的 Internet 连接。此时,可以使用 OpenWrt 的负载均衡功能。

在“网络”选项卡下,点击“接口”,如上面所述。然后,需要设置路由规则和负载均衡相关的配置信息。

config route
    option interface 'wan1'
    option target '0.0.0.0'
    option netmask '0.0.0.0'
    option gateway '192.168.1.1'

config route
    option interface 'wan2'
    option target '0.0.0.0'
    option netmask '0.0.0.0'
    option gateway '192.168.1.2'

config interface 'wanb'
    option ifname 'eth1'
    option proto 'dhcp'
    option metric '10'
    option disabled '0'

config interface 'wanc'
    option ifname 'eth2'
    option proto 'dhcp'
    option metric '20'
    option disabled '0'

config rule 'wan_lb'
    option mark '0x1'
    option sticky '1'
    option wan_wanb '10'
    option wan_wanc '10'

config rule
    option mark '0x2'
    option wan_wanb '20'
    option wan_wanc '20'

这个配置文件假设两个 WAN 口连接至分别为 192.168.1.1 和 192.168.1.2 的两个服务提供商。在这个配置文件中,第一个 WAN 口(wanb)的 metric 为 10,第二个 WAN 口(wanc)的 metric 为 20。OpenWrt 系统通过使用标记(mark)和规则(rule)来实现负载均衡。