萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> Linux系統通過手機GPRS上網設置簡介

Linux系統通過手機GPRS上網設置簡介

class="152524">

Linux通過手機上網

1.安裝相關軟件
;sudo apt-get install wvdial

2.得到GPRS的IP地址
;(1)
;手機調整到usb lan模式,在手機打開一個網頁,讓它的GPRS連通
;(2)
;運行 sudo /sbin/ifconfig
;確認usb0存在
;(3)
;運行 sudo /sbin/ifconfig usb0 192.168.1.1
;配置電腦上的usb0的IP為192.168.1.1
;(4)
;運行 telnet 192.168.1.2
;telnet到手機,其中192.168.1.2為手機usb lan的IP,如下

$ telnet 192.168.1.2
;Trying 192.168.1.2...
;Connected to 192.168.1.2.
;Escape character is '^]'.
;;;;


;MontaVista(R) Linux(R) Consumer Electronics Edition 3.1
;Linux/armv5tel 2.4.20_mvlcee31-mainstone_pxa27x
;(none) login: root
;MontaVista(R) Linux(R) Consumer Electronics Edition 3.1

No directory /root!
;Logging in with home = "/".
;# ifconfig
;gprsv2;Link encap:Point-to-Point Protocol
;;;inet addr:10.9.139.175; P-t-P:10.112.112.112; Mask:255.255.255.255
;;;UP POINTOPOINT RUNNING NOARP 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:50
;;;RX bytes:8991 (8.7 Kb); TX bytes:5117 (4.9 Kb)

lo;;;;;Link encap:Local Loopback
;;;inet addr:127.0.0.1; Mask:255.0.0.0
;;;UP LOOPBACK RUNNING; MTU:16436; Metric:1
;;;RX packets:24 errors:0 dropped:0 overruns:0 frame:0
;;;TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
;;;collisions:0 txqueuelen:0
;;;RX bytes:1392 (1.3 Kb); TX bytes:1392 (1.3 Kb)

gprsv2;Link encap:Point-to-Point Protocol
;;;inet addr:10.10.88.48; P-t-P:10.112.112.112; Mask:255.255.255.255
;;;UP POINTOPOINT RUNNING NOARP 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:50
;;;RX bytes:1025 (1.0 Kb); TX bytes:1023 (1023.0 b)

# exit
;Connection closed by foreign host.
;$
;(5)
;由(4)得到gprsv2的IP為10.10.88.48,記錄下來

3.為pppd添加GPRS IP
;(1)
;運行 sudo gedit /etc/ppp/options
;在options文件的最後一行添加如下兩行內容
;novj
;:10.10.88.48
;其中10.10.88.48為2.(5)所得到的GPRS IP地址

4.配置/etc/wvdial.conf並連接上網
;(1)
;關掉手機的網頁,確認手機上的GPRS連接已經斷開
;(2)
;手機調整到usb modem模式
;(3)
;運行 wvdialconf
;檢測手機的modem連接是否正常,程序自動創建/etc/wvdial.conf文件,正確情況如下

$ wvdialconf
;Editing `/etc/wvdial.conf'.

Scanning your serial ports for a modem.

WvModem<*1>: Cannot set information for serial port.
;ttyS0<*1>: ATQ0 V1 E1 -- failed with 2400 baud, next try: 9600 baud
;ttyS0<*1>: ATQ0 V1 E1 -- failed with 9600 baud, next try: 115200 baud
;ttyS0<*1>: ATQ0 V1 E1 -- and failed too at 115200, giving up.
;Modem Port Scan<*1>: S1S2S3
;WvModem<*1>: Cannot get information for serial port.
;ttyACM0<*1>: ATQ0 V1 E1 -- OK
;ttyACM0<*1>: ATQ0 V1 E1 Z -- OK
;ttyACM0<*1>: ATQ0 V1 E1 S0=0 -- OK
;ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 -- OK
;ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 -- OK
;ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK
;ttyACM0<*1>: Modem Identifier: ATI -- ERROR
;ttyACM0<*1>: Speed 4800: AT -- OK
;ttyACM0<*1>: Speed 9600: AT -- OK
;ttyACM0<*1>: Speed 19200: AT -- OK
;ttyACM0<*1>: Speed 38400: AT -- OK
;ttyACM0<*1>: Speed 57600: AT -- OK
;ttyACM0<*1>: Speed 115200: AT -- OK
;ttyACM0<*1>: Speed 230400: AT -- OK
;ttyACM0<*1>: Speed 460800: AT -- OK
;ttyACM0<*1>: Max speed is 460800; that should be safe.
;ttyACM0<*1>: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 -- OK

Found an USB modem on /dev/ttyACM0.
;Modem configuration written to /etc/wvdial.conf.
;/etc/wvdial.conf<Warn>: Can't write '/etc/wvdial.conf.tmp8517': Permission denied
;/etc/wvdial.conf<Warn>: Can't write '/etc/wvdial.conf' ('/etc/wvdial.conf'): Bad file descriptor
;ttyACM0<Info>: Speed 460800; init "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
;$

(4)
;運行 sudo gedit /etc/wvdial.conf
;修改其內容,Baud保持4.(3)中程序自動創建的值,Username和Password的值到手機的網絡設置查看
;本例使用CMNET連接,文件內容如下

[Dialer Defaults]
;Init1 = ATZ
;Init2 = AT&FE0V1&C1S0=0
;Init3 = AT+cgdcont=1,"IP","CMNET","",0,0
;Modem Type = USB Modem
;ISDN = 0
;Phone = *99***2#
;New PPPD = yes
;Modem = /dev/ttyACM0
;Username = 172
;Password = 172
;Baud = 460800
;Idle Seconds = 3000
;Auto DNS = 1
;Stupid Mode = 1
;Dial Command = ATD
;Ask Password = 0
;FlowControl = NOFLOW

(5)
;禁用eth0等網絡聯連接
;另:如果是在Debian Gnome環境下,右上角的網絡連接工具,“啟用聯網一項反選

(6)
;運行 sudo wvdial
;讓Linux通過手機上網,正常情況如下

$ sudo wvdial
;--> WvDial: Internet dialer version 1.60
;--> Cannot get information for serial port.
;--> Initializing modem.
;--> Sending: ATZ
;ATZ
;OK
;--> Sending: AT&FE0V1&C1S0=0
;AT&FE0V1&C1S0=0
;OK
;--> Sending: AT+cgdcont=1,"IP","CMNET","",0,0
;OK
;--> Modem initialized.
;--> Idle Seconds = 3000, disabling automatic reconnect.
;--> Sending: ATD*99***2#
;--> Waiting for carrier.
;CONNECT
;--> Carrier detected.; Starting PPP immediately.
;--> Starting pppd at Mon May 18 21:16:57 2009
;--> Pid of pppd: 8931
;--> Using interface ppp0
;--> pppd: [10][18]1
;--> pppd: [10][18]1
;--> pppd: [10][18]1
;--> pppd: [10][18]1
;--> pppd: [10][18]1
;--> local; IP address 10.55.0.37
;--> pppd: [10][18]1
;--> remote IP address 10.10.88.48
;--> pppd: [10][18]1
;--> primaryDNS address 211.136.20.203
;--> pppd: [10][18]1
;--> secondary DNS address 211.136.17.107
;--> pppd: [10][18]1

收到local IP address說明網絡連接成功,終端裡按Ctrl+C終止網絡連接

(7)
;驗證上網效果

$ sudo /sbin/ifconfig
;eth0;;;Link encap:Ethernet; HWaddr 00:F0:CF:81:F7:00
;;;inet6 addr: 2001:da8:2004:2009:2f0:cfff:fe81:f700/64 Scope:Global
;;;inet6 addr: fe80::2f0:cfff:fe81:f700/64 Scope:Link
;;;UP BROADCAST RUNNING MULTICAST; MTU:1500; Metric:1
;;;RX packets:79280 errors:0 dropped:0 overruns:0 frame:0
;;;TX packets:9418 errors:0 dropped:0 overruns:0 carrier:0
;;;collisions:0 txqueuelen:1000
;;;RX bytes:14814054 (14.1 MiB); TX bytes:1465054 (1.3 MiB)
;;;Interrupt:16 Base address:0xc000

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:16436; Metric:1
;;;RX packets:875 errors:0 dropped:0 overruns:0 frame:0
;;;TX packets:875 errors:0 dropped:0 overruns:0 carrier:0
;;;collisions:0 txqueuelen:0
;;;RX bytes:132

copyright © 萬盛學電腦網 all rights reserved