樹莓派使用4G模組(華為ME909s-821)親身嘗試的可行方法(上)
大部分樹莓派使用者使用raspbian系統和ubuntu mate系統,所以我只在這兩個系統上嘗試使用4G模組,模組使用Mini PCI-E轉USB開發板,接入到樹莓派上,配置網路方法具體如下:
本篇介紹raspbian系統,ubuntu mate系統將在下一篇介紹
4G模組能直接被系統識別,無需安裝驅動,可以通過lsusb和ifconfig命令檢視狀況:
[email protected]:~$ 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
[email protected]:~$ 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內網和外網:
[email protected]:~ $ 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
[email protected]:~ $ 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