openwrt接入usb 4g网络

openwrt 稍加配置可以接入usb 4G网卡,进行上网。本节利用手机usb网络共享功能,进行配置操作
usb 网络共享、usb 4G网卡、pcie 4G网卡,其实本质上透过rndis驱动进行网络转发
openwrt版本19.07

openwrt rndis驱动配置,开启kmod-usb-net-rndis


 .config - OpenWrt Configuration
 > Kernel modules > USB Support ────────────────────────────────────────────────────────────────
  ┌────────────────────────────────────── USB Support ───────────────────────────────────────┐
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or empty submenus ----).  │  
  │  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes, <M> modularizes  │  
  │  features.  Press <Esc><Esc> to exit, <?> for Help, </> for Search.  Legend: [*]         │  
  │  built-in  [ ] excluded  <M> module  < > module capable                                  │  
  │ ┌────────^(-)──────────────────────────────────────────────────────────────────────────┐ │  
  │ │        <*> kmod-usb-net............... Kernel modules for USB-to-Ethernet convertors │ │  
  │ │        < >   kmod-usb-net-asix...... Kernel module for USB-to-Ethernet Asix convertor│ │  
  │ │        < >   kmod-usb-net-asix-ax88179                                               │ │  
  │ │        < >   kmod-usb-net-cdc-eem..................... Support for CDC EEM connection│ │  
  │ │        -*-   kmod-usb-net-cdc-ether.............. Support for cdc ethernet connection│ │  
  │ │        < >   kmod-usb-net-cdc-mbim..................... Kernel module for MBIM Device│ │  
  │ │        < >   kmod-usb-net-cdc-ncm..................... Support for CDC NCM connection│ │  
  │ │        < >   kmod-usb-net-cdc-subset...... Support for CDC Ethernet subset connection│ │  
  │ │        < >   kmod-usb-net-dm9601-ether........ Support for DM9601 ethernet connection│ │  
  │ │        < >   kmod-usb-net-hso.. Kernel module for Option USB High Speed Mobile Device│ │  
  │ │        < >   kmod-usb-net-huawei-cdc-ncm....... Support for Huawei CDC NCM connection│ │  
  │ │        < >   kmod-usb-net-ipheth..................... Apple iPhone USB Ethernet drive│ │  
  │ │        < >   kmod-usb-net-kalmia................... Samsung Kalmia based LTE USB mode│ │  
  │ │        < >   kmod-usb-net-kaweth.. Kernel module for USB-to-Ethernet Kaweth convertor│ │  
  │ │        < >   kmod-usb-net-mcs7830                                                    │ │  
  │ │        < >   kmod-usb-net-pegasus                                                    │ │  
  │ │        < >   kmod-usb-net-pl.................. Prolific PL-2301/2302/25A1 based cable│ │  
  │ │        < >   kmod-usb-net-qmi-wwan.................................... QMI WWAN drive│ │  
  │ │        <*>   kmod-usb-net-rndis......................... Support for RNDIS connection│ │  
  │ │        < >   kmod-usb-net-rtl8150                                                    │ │  
  │ └────────v(+)──────────────────────────────────────────────────────────────────────────┘ │  
  ├──────────────────────────────────────────────────────────────────────────────────────────┤  
  │                 <Select>    < Exit >    < Help >    < Save >    < Load >                 │  
  └──────────────────────────────────────────────────────────────────────────────────────────┘  

手机接入usb host,并开启usb网络共享功能,查看网络接口

root@OpenWrt:~# ifconfig -a
br-lan    Link encap:Ethernet  HWaddr 12:34:56:78:90:01
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fd03:43b7:d448::1/60 Scope:Global
          inet6 addr: fe80::1034:56ff:fe78:9001/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1261 errors:0 dropped:0 overruns:0 frame:0
          TX packets:432 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:104083 (101.6 KiB)  TX bytes:53131 (51.8 KiB)

eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:01
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1454 errors:0 dropped:0 overruns:0 frame:0
          TX packets:440 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:141662 (138.3 KiB)  TX bytes:55733 (54.4 KiB)
          Interrupt:5

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:96 errors:0 dropped:0 overruns:0 frame:0
          TX packets:96 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:6528 (6.3 KiB)  TX bytes:6528 (6.3 KiB)

usb0      Link encap:Ethernet  HWaddr 2A:F1:BF:AE:3C:5A
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 12:34:56:78:90:00
          inet6 addr: fe80::1034:56ff:fe78:9000/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:564 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:69320 (67.6 KiB)

usb0 ,即为手机网络端口。但此时用ifconfig 是无法查看到!
需要执行如下:

root@OpenWrt:~# udhcpc -i usb0
udhcpc: started, v1.31.1
udhcpc: sending discover
udhcpc: sending discover
udhcpc: sending select for 192.168.42.3
udhcpc: lease of 192.168.42.3 obtained, lease time 3600
udhcpc: ifconfig usb0 192.168.42.3 netmask 255.255.255.0 broadcast 192.168.42.255
udhcpc: setting default routers: 192.168.42.129

此时,用ifconfig可查看到usb0网络端口。
虽然usb 网络端口已经加载,但WLAN 和 LAN都是无法上网的,同时也是无法ping网络

root@OpenWrt:~# ping www.baidu.com
ping: bad address 'www.baidu.com'

进入luci,添加usb0物理网络接口,并将usb0,映射到wlan 和 lan后,才可以接通网络
配置之前,先看下/etc/config/network,和/etc/config/wireless 两个文件,以便修改后,进行对比
network:

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd03:43b7:d448::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device 'lan_eth0_dev'
        option name 'eth0'
        option macaddr '12:34:56:78:90:01'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '0'

wireless:

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11g'
        option path 'platform/10300000.wmac'
        option htmode 'HT20'
        option disabled '0'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'OpenWrt'
        option encryption 'none'

添加网络接口usb0
进入luci->网络->接口,选择usb0接口,命名为4g
在这里插入图片描述
在这里插入图片描述
保存应用后,网络可以ping

root@OpenWrt:~# ping www.baidu.com
PING www.baidu.com (180.101.49.11): 56 data bytes
64 bytes from 180.101.49.11: seq=0 ttl=51 time=15.264 ms
64 bytes from 180.101.49.11: seq=1 ttl=51 time=21.160 ms
64 bytes from 180.101.49.11: seq=2 ttl=51 time=21.360 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 15.264/19.261/21.360 ms

但无线还没有网络
进入luci->网络->无线,添加无线网络4g
在这里插入图片描述

保存并应用,,之后无线就可以进行上网了

此时,再查看network 和 wireless 配置文件
network:

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd03:43b7:d448::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device 'lan_eth0_dev'
        option name 'eth0'
        option macaddr '12:34:56:78:90:01'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '0'

config interface '4g'
        option ifname 'usb0'
        option proto 'dhcp'
        option type 'bridge'

wireless:

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11g'
        option path 'platform/10300000.wmac'
        option htmode 'HT20'
        option disabled '0'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt'
        option encryption 'none'
        option network 'lan 4g'

对比配置之前,
network 中,多了物理网络接口4g(usb0)
wireless中,无线的网络来源多了新增加的 4g.

如果将这部分配置,在编译openwrt的时候就加入进去,则无需再手动进行配置
修改源码文件,openwrt/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
在对应的板子配置下面(这里用的板子为mediatek,linkit-smart-7688)添加
ucidef_set_interface_wan “usb0”

	mediatek,linkit-smart-7688|\
	onion,omega2p|\
	onion,omega2|\
	ravpower,rp-wd009|\
	tama,w06|\
	tplink,re200-v2|\
	tplink,re220-v2|\
	tplink,re305-v1|\
	tplink,tl-mr3020-v3|\
	tplink,tl-wr802n-v4|\
	tplink,tl-wa801nd-v5|\
	widora,neo-16m|\
	widora,neo-32m)
		ucidef_add_switch "switch0"
		ucidef_add_switch_attr "switch0" "enable" "false"
		ucidef_set_interface_lan "eth0"

		# eric++
		ucidef_set_interface_wan "usb0"
		;;

编译完成,再次进入系统查看ifconfig,usb0网络已经自动加入☺

root@OpenWrt:/etc/config# ifconfig
br-lan    Link encap:Ethernet  HWaddr 12:34:56:78:90:01
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::1034:56ff:fe78:9001/64 Scope:Link
          inet6 addr: fd34:edd9:e34f::1/60 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3962 errors:0 dropped:4 overruns:0 frame:0
          TX packets:2775 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:557195 (544.1 KiB)  TX bytes:1618571 (1.5 MiB)

eth0      Link encap:Ethernet  HWaddr 12:34:56:78:90:01
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2394 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1530 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:323501 (315.9 KiB)  TX bytes:695464 (679.1 KiB)
          Interrupt:5

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:338 errors:0 dropped:0 overruns:0 frame:0
          TX packets:338 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:29303 (28.6 KiB)  TX bytes:29303 (28.6 KiB)

usb0      Link encap:Ethernet  HWaddr 12:34:56:78:90:00
          inet addr:192.168.42.149  Bcast:192.168.42.255  Mask:255.255.255.0
          inet6 addr: fe80::1034:56ff:fe78:9000/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1855 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2228 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1050610 (1.0 MiB)  TX bytes:459302 (448.5 KiB)

wlan0     Link encap:Ethernet  HWaddr 12:34:56:78:90:00
          inet6 addr: fe80::1034:56ff:fe78:9000/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1767 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2248 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:310018 (302.7 KiB)  TX bytes:1090399 (1.0 MiB)

查看network,已经多出了WLAN部分

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd34:edd9:e34f::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device 'lan_eth0_dev'
        option name 'eth0'
        option macaddr '12:34:56:78:90:01'

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

config device 'wan_usb0_dev'
        option name 'usb0'
        option macaddr '12:34:56:78:90:00'

config interface 'wan6'
        option ifname 'usb0'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '0'

此时无线也是可以上网的哦~~~~~,不明所以然…


以上操作只是保证能够正常上网,但是如若是4GPCIE网卡,比如用的是EC20等,还需要对内核进行配置,使能ttyUSB或者ttyACM。用于模块AT配置。

  • make kernel_menuconfig
  • Device Drivers > USB support > USB Modem (CDC ACM) support
 .config - Linux/mips 4.14.195 Kernel Configuration                           
 > Device Drivers > USB support ───────────────────────────────────────────── 
  ┌───────────────────────────── USB support ─────────────────────────────┐   
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or     │   
  │  empty submenus ----).  Highlighted letters are hotkeys.  Pressing    │   
  │  <Y> includes, <N> excludes, <M> modularizes features.  Press         │   
  │  <Esc><Esc> to exit, <?> for Help, </> for Search.  Legend: [*]       │   
  │ ┌────^(-)───────────────────────────────────────────────────────────┐ │   
  │ │    < >   SL811HS HCD support                                      │ │   
  │ │    < >   R8A66597 HCD support                                     │ │   
  │ │    [ ]   HCD test mode support                                    │ │   
  │ │          *** USB Device Class drivers ***                         │ │   
  │ │    <*>   USB Modem (CDC ACM) support                              │ │   
  │ │    < >   USB Printer support                                      │ │   
  │ │    < >   USB Wireless Device Management support                   │ │   
  │ │    < >   USB Test and Measurement Class support                   │ │   
  │ │          *** NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may │ │   
  │ │          *** also be needed; see USB_STORAGE Help for more info **│ │   
  │ │          *** USB Imaging devices ***                              │ │   
  │ │    < >   USB Mustek MDC800 Digital Camera support                 │ │   
  │ │    < >   USB/IP support                                           │ │   
  │ │    < >   Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...│ │   
  │ └────v(+)───────────────────────────────────────────────────────────┘ │   
  ├───────────────────────────────────────────────────────────────────────┤   
  │       <Select>    < Exit >    < Help >    < Save >    < Load >        │   
  └───────────────────────────────────────────────────────────────────────┘   
  • Device Drivers > USB support > USB Serial Converter support > USB driver for GSM and CDMA modems
 .config - Linux/mips 4.14.195 Kernel Configuration                           
 > Device Drivers > USB support > USB Serial Converter support ────────────── 
  ┌──────────────────── USB Serial Converter support ─────────────────────┐   
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or     │   
  │  empty submenus ----).  Highlighted letters are hotkeys.  Pressing    │   
  │  <Y> includes, <N> excludes, <M> modularizes features.  Press         │   
  │  <Esc><Esc> to exit, <?> for Help, </> for Search.  Legend: [*]       │   
  │ ┌────^(-)───────────────────────────────────────────────────────────┐ │   
  │ │    < >   USB Sierra Wireless Driver                               │ │   
  │ │    < >   USB Symbol Barcode driver (serial mode)                  │ │   
  │ │    < >   USB TI 3410/5052 Serial Driver                           │ │   
  │ │    < >   USB REINER SCT cyberJack pinpad/e-com chipcard reader    │ │   
  │ │    < >   USB Xircom / Entrega Single Port Serial Driver           │ │   
  │ │    <*>   USB driver for GSM and CDMA modems                       │ │   
  │ │    < >   USB ZyXEL omni.net LCD Plus Driver                       │ │   
  │ │    < >   USB Opticon Barcode driver (serial mode)                 │ │   
  │ │    < >   Xsens motion tracker serial interface driver             │ │   
  │ │    < >   USB-Wishbone adapter interface driver                    │ │   
  │ │    < >   USB Quatech SSU-100 Single Port Serial Driver            │ │   
  │ │    < >   USB Quatech Serial Driver for USB 2 devices              │ │   
  │ │    < >   USB Renesas uPD78F0730 Single Port Serial Driver         │ │   
  │ │    < >   USB Debugging Device                                     │ │   
  │ └───────────────────────────────────────────────────────────────────┘ │   
  ├───────────────────────────────────────────────────────────────────────┤   
  │       <Select>    < Exit >    < Help >    < Save >    < Load >        │   
  └───────────────────────────────────────────────────────────────────────┘   
  • Device Drivers > Network device support > USB Network Adapters > Host for RNDIS and ActiveSync devices
 .config - Linux/mips 4.14.195 Kernel Configuration                           
 > Device Drivers > Network device support > USB Network Adapters ─────────── 
  ┌──────────────────────── USB Network Adapters ─────────────────────────┐   
  │  Arrow keys navigate the menu.  <Enter> selects submenus ---> (or     │   
  │  empty submenus ----).  Highlighted letters are hotkeys.  Pressing    │   
  │  <Y> includes, <N> excludes, <M> modularizes features.  Press         │   
  │  <Esc><Esc> to exit, <?> for Help, </> for Search.  Legend: [*]       │   
  │ ┌────^(-)───────────────────────────────────────────────────────────┐ │   
  │ │    < >     SMSC LAN75XX based USB 2.0 gigabit ethernet devices    │ │   
  │ │    < >     SMSC LAN95XX based USB 2.0 10/100 ethernet devices     │ │   
  │ │    < >     GeneSys GL620USB-A based cables                        │ │   
  │ │    < >     NetChip 1080 based cables (Laplink, ...)               │ │   
  │ │    < >     Prolific PL-2301/2302/25A1/27A1 based cables           │ │   
  │ │    < >     MosChip MCS7830 based Ethernet adapters                │ │   
  │ │    <*>     Host for RNDIS and ActiveSync devices                  │ │   
  │ │    < >   Simple USB Network Links (CDC Ethernet subset)           │ │   
  │ │    < >   Sharp Zaurus (stock ROMs) and compatible                 │ │   
  │ │    < >   Conexant CX82310 USB ethernet port                       │ │   
  │ │    < >   Samsung Kalmia based LTE USB modem                       │ │   
  │ │    < >   QMI WWAN driver for Qualcomm MSM based 3G and LTE modems │ │   
  │ │    < >   Option USB High Speed Mobile Devices                     │ │   
  │ │    < >   Intellon PLC based usb adapter                           │ │   
  │ └────v(+)───────────────────────────────────────────────────────────┘ │   
  ├───────────────────────────────────────────────────────────────────────┤   
  │       <Select>    < Exit >    < Help >    < Save >    < Load >        │   
  └───────────────────────────────────────────────────────────────────────┘   
  • 此时可以看到设备下面模拟串口ttyACM
root@OpenWrt:/dev# ls tty*
tty      ttyACM0  ttyACM1  ttyS0    ttyS1    ttyS2

另外,还要根据4g模块手册,按需添加相应的USB厂商信息,以及零包处理等。。。


仅此记录

  • 1
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在OpenWrt设备上共享4G模块的网络,你需要确保4G模块已经正确安装并可以被OpenWrt识别。接下来,你可以按照以下步骤进行操作: 1. 通过USB连接将4G模块连接到OpenWrt设备。 2. 在OpenWrt设备上安装并配置USB驱动程序,以便能够正确识别4G模块。 3. 配置OpenWrt设备以使用4G模块的网络连接。这可以通过设置网络接口和DHCP服务器来实现。 以下是一些具体的步骤: 1. 安装USB驱动程序 你可以使用以下命令来安装USB驱动程序: ``` opkg update opkg install kmod-usb-net-cdc-ether ``` 2. 配置OpenWrt设备 首先,你需要使用以下命令查看4G模块是否已正确识别: ``` dmesg | grep ttyUSB ``` 如果一切正常,你应该能够看到类似于以下内容的输出: ``` [ 402.733333] option 1-1.4:1.0: GSM modem (1-port) converter detected [ 402.740156] usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB0 [ 402.747460] option 1-1.4:1.1: GSM modem (1-port) converter detected [ 402.754271] usb 1-1.4: GSM modem (1-port) converter now attached to ttyUSB1 ``` 接下来,你需要将4G模块的串口配置为网络接口。这可以通过以下命令来完成: ``` uci set network.wwan=interface uci set network.wwan.proto=dhcp uci set network.wwan.device=/dev/ttyUSB0 uci commit network ``` 接着,你需要为DHCP服务器配置一个新的接口,以便OpenWrt设备可以共享4G模块的网络连接: ``` uci set dhcp.lan.interface='lan wwan' uci commit dhcp ``` 最后,你需要重启网络服务以使更改生效: ``` /etc/init.d/network restart ``` 现在,你的OpenWrt设备应该已经可以使用4G模块的网络连接了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值