树莓派使用4G模块(华为ME909s-821)亲身尝试的可行方法(上)

大部分树莓派用户使用raspbian系统和ubuntu mate系统,所以我只在这两个系统上尝试使用4G模块,模块使用Mini PCI-E转USB开发板,接入到树莓派上,配置网络方法具体如下:

本篇介绍raspbian系统,ubuntu mate系统将在下一篇介绍

4G模块能直接被系统识别,无需安装驱动,可以通过lsusb和ifconfig命令查看状况:

pi@pi-desktop:~$ lsusb
Bus 001 Device 007: ID 12d1:15c1 Huawei Technologies Co., Ltd. 
Bus 001 Device 006: ID 0a05:7211 Unknown Manufacturer hub
Bus 001 Device 005: ID 413c:2107 Dell Computer Corp. 
Bus 001 Device 004: ID 413c:301a Dell Computer Corp. 
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub


pi@pi-desktop:~$ ifconfig
enxb827ebdc8c6f Link encap:Ethernet  HWaddr b8:27:eb:dc:8c:6f  
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ca29:cc82:f9d1:dd9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:44427 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1460 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2462495 (2.4 MB)  TX bytes:134180 (134.1 KB)


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:475 errors:0 dropped:0 overruns:0 frame:0
          TX packets:475 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:33987 (33.9 KB)  TX bytes:33987 (33.9 KB)


usb0      Link encap:Ethernet  HWaddr 02:1e:10:1f:00:00  
          inet addr:10.27.145.51  Bcast:10.27.145.55  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:63 errors:0 dropped:0 overruns:0 frame:0
          TX packets:89 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:13037 (13.0 KB)  TX bytes:12466 (12.4 KB)



wlan0     Link encap:Ethernet  HWaddr b8:27:eb:89:d9:3a  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:242 errors:0 dropped:242 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 

          RX bytes:85717 (85.7 KB)  TX bytes:0 (0.0 B)


在raspbian系统下使用wvdial来拨号连接4G网络

安装wvdial:

sudo apt-get install wvdial

配置连接信息:

sudo vi /etc/wvdial.conf
如下配置:
[Dialer hw1]
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0
Init3 = AT+CGDCONT=1,"IP","3gnet"
Modem Type = Analog Modem
Baud = 9600  # 波特率常见的是9600  115200  460800
New PPPD = yes
Modem = /dev/ttyUSB0
ISDN = 0
Phone = *99#
Password = guest
Username = guest

Auto DNS = on

拨号上网:

sudo wvdial hw1

需要等待一会儿

此时可以通过ifconfig看到多出了个ppp0的网卡设备,并且已经获得IP地址

但是还是无法ping通外网,查看路由表信息如下:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0            0.0.0.0         0.0.0.0                   U      0         0        0 eth0
10.64.64.64     0.0.0.0         255.255.255.255    UH    0         0        0 ppp0

192.168.1.0     0.0.0.0         255.255.255.0        U      202      0        0 eth0

可以看出访问未知目标时,使用的是eth0的网卡,此处我们将其修改为使用ppp0来访问未知目标:
删除eth0的第一条路由信息:
sudo route del –net 0.0.0.0 eth0
新增一条ppp0的路由信息:
sudo route add –net 0.0.0.0 ppp0


修改后路由信息为:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0            0.0.0.0         0.0.0.0                 U      0       0         0 ppp0
10.64.64.64     0.0.0.0         255.255.255.255  UH    0       0         0 ppp0

192.168.1.0     0.0.0.0         255.255.255.0      U      202    0         0 eth0


可以尝试ping内网和外网:
pi@raspberrypi:~ $ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.522 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.470 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.402 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.449 ms

pi@raspberrypi:~ $ ping www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125: icmp_seq=1 ttl=54 time=23.3 ms
64 bytes from 61.135.169.125: icmp_seq=2 ttl=54 time=27.0 ms
64 bytes from 61.135.169.125: icmp_seq=3 ttl=54 time=13.5 ms

64 bytes from 61.135.169.125: icmp_seq=4 ttl=54 time=23.1 ms


  • 2
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 14
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大头菜馅馒头

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值