当前位置:   article > 正文

15 --> OpenWrt 实现双 4G 通道拨号上网、实现负载均衡和主备_openwrt 4g network

openwrt 4g network

第一步 配置 4G 模块参数配置

  • 配置 4G 模块的 interface 接口,并修改电口缺省配置,文件路径如下:
vim target/linux/ramips/base-files/etc/board.d/02_network
  • 1
  • 修改配置文件内容
ramips_setup_interfaces()
{
        local board="$1"

        case $board in
        ixe,u7621-06-256m-16m|\
        ixe,u7621-06-512m-64m)
               ucidef_add_switch "switch0" \
                        "1:lan" "3:lan" "4:wan" "6@eth0"
               ucidef_set_interface_wan "wwan1" "wwan2"   # 增加 4G 模块 interface 
               ;;
        *)
                RT3X5X=`cat /proc/cpuinfo | egrep "(RT3.5|RT5350)"`
                if [ -n "${RT3X5X}" ]; then
                        ramips_setup_rt3x5x_vlans
                else
                        ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
                fi
                ;;
        esac
}       
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 配置防火墙,允许4G模块作为wan口上网;
config zone
        option name             lan
        list   network          'lan'
        option input            ACCEPT
        option output           ACCEPT
        option forward          ACCEPT

config zone
        option name             wan
        list   network          'wan'
        list   network          'wwan1'  # 增加 4G interface
        list   network          'wwan2'  # 增加 4G interface
        list   network          'wan6'
        option input            REJECT
        option output           ACCEPT
        option forward          REJECT
        option masq             1
        option mtu_fix          1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

第2种方法.增加 4G wwan 接口的方法

openWRT系统中,有很多参数都可以通过如下文件,通过uci 命令配置相关参数,此文件是系统初始化后
调用uic-default缺省补充配置内容。

$ cat target/linux/ramips/base-files/etc/uci-defaults/50_set_network_firewall
  • 1

配置内容如下

#!/bin/sh

#
# sd cloud config network & firewall
#

#配置interface 4G | 5G 参数
uci set network.wwan1=interface
uci set network.wwan1.proto=dhcp
uci set network.wwan1.ifname=usb0

uci set network.wwan2=interface
uci set network.wwan2.ifname=usb1
uci set network.wwan2.proto=dhcp
uci set network.wwan2.defaultroute=0		#增加 defaultroute 设置
uci commit network

# 配置防火墙内容
uci set firewall.@zone[1].network=wan
uci add_list firewall.@zone[1].network=wwan1
uci add_list firewall.@zone[1].network=wwan2
uci add_list firewall.@zone[1].network=wan6
uci commit firewall
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

第二步 在镜像打包前、修改 mwan3 配置文件

  • mwan3 配置文件路径
robot@ubuntu:~/OpenWrt/mtk7621-19.07/package/feeds/packages/mwan3/files/etc/config$ vim mwan3
  • 1
  • 配置接口内容如下:
config globals 'globals'
        option mmx_mask '0x3F00'
        option rtmon_interval '5'

config interface 'wan'
        option enabled '1'
        list track_ip '8.8.4.4'
        list track_ip '8.8.8.8'
        list track_ip '114.114.114.114'
        list track_ip '114.114.115.115'
        option family 'ipv4'
        option reliability '1'
        option count '1'
        option timeout '2'
        option failure_latency '1000'
        option recovery_latency '500'
        option failure_loss '20'
        option recovery_loss '5'
        option interval '5'
        option down '3'
        option up '8'

config interface 'wwan1'
        option enabled '1'
        list track_ip '8.8.4.4'
        list track_ip '8.8.8.8'
        list track_ip '114.114.114.114'
        list track_ip '114.114.115.115'
        option family 'ipv4'
        option reliability '2'
        option count '1'
        option timeout '2'
        option failure_latency '1000'
        option recovery_latency '500'
        option failure_loss '20'
        option recovery_loss '5'
        option interval '5'
        option down '3'
        option up '8'

config interface 'wwan2'
        option enabled '1'
        list track_ip '8.8.4.4'
        list track_ip '8.8.8.8'
        list track_ip '114.114.114.114'
        list track_ip '114.114.115.115'
        option family 'ipv4'
        option reliability '1'
        option count '1'
        option timeout '2'
        option failure_latency '1000'
        option recovery_latency '500'
        option failure_loss '20'
        option recovery_loss '5'
        option interval '5'
        option down '3'
        option up '8'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 配置规则
config member 'wan_m1_w3'
        option interface 'wan'
        option metric '10'
        option weight '30'

config member 'wan_m2_w3'
        option interface 'wan'
        option metric '20'
        option weight '30'

config member 'wwan1_m1_w3'
        option interface 'wwan1'
        option metric '10'
        option weight '30'

config member 'wwan1_m2_w3'
        option interface 'wwan1'
        option metric '20'
        option weight '30'

config member 'wwan2_m1_w3'
        option interface 'wwan2'
        option metric '10'
        option weight '30'

config member 'wwan2_m2_w3'
        option interface 'wwan2'
        option metric '20'
        option weight '30'

config policy 'wan_only'
        list use_member 'wan_m1_w3'

config policy 'wwan1_only'
        list use_member 'wwan1_m1_w3'

config policy 'wwan2_only'
        list use_member 'wwan2_m1_w2'

config policy 'balanced'
        list use_member 'wan_m1_w3'
        list use_member 'wwan1_m1_w3'
        list use_member 'wwan2_m1_w2'

config policy 'wan_pri_wwan_sec'
        list use_member 'wan_m1_w3'
        list use_member 'wwan1_m2_w3'
        list use_member 'wwan2_m2_w3'

config policy 'wwan1_pri_wwan2_sec'
        list use_member 'wwan1_m1_w3'
        list use_member 'wwan2_m2_w3'

config policy 'wwan2_pri_wwan1_sec'
        list use_member 'wwan2_m1_w3'
        list use_member 'wwan1_m2_w3'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 配置负载分流策略
config rule 'https'
        option sticky '1'
        option dest_port '443'
        option proto 'tcp'
        option use_policy 'balanced'

config rule 'default_rule_v4'
        option dest_ip '0.0.0.0/0'
        option use_policy 'balanced'
        option family 'ipv4'

config rule 'default_rule_v6'
        option dest_ip '::/0'
        option use_policy 'balanced'
        option family 'ipv6'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

第三步 验证

推荐阅读:
https://www.cnblogs.com/nicephil/p/10168065.html

参考链接:
https://openwrt.org/docs/guide-developer/uci-defaults
https://openwrt.org/docs/guide-developer/networking/network.interfaces

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号