新浪微博: @wandering


我的3G上网卡是华为 E1750,操作系统是openSUSE 11.2,之前只能在虚拟机运行的Windows里上3G,感觉这样实在不方便,于是想到了直接在Linux里连接3G网络。

主要参考了2篇文档,尤其向第一篇作者yel617致谢,分别是:

<<华为E1750在DM6446上的移植>>
<>



闲话少说,直接写方法。



1. software
================

http://www.draisberghof.de/usb_modeswitch/

usb-modeswitch
usb-modeswitch-data
libusb




2. install
==============

安装软件

root# tar jxvf usb-modeswitch-1.1.3.tar.bz2
root# cd usb-modeswitch-1.1.3/
root# make install

root# tar jxvf usb-modeswitch-data-20100707.tar.bz2
root# cd usb-modeswitch-data-20100707/
root# make install

then upgrade libusb to the lastest version.

root# cp /usr/share/doc/packages/ppp/scripts/pon /usr/local/sbin
root# cp /usr/share/doc/packages/ppp/scripts/poff /usr/local/sbin
root# chmod ug+x /usr/local/sbin/pon /usr/local/sbin/poff


接下来,接上3G上网卡,可以看到 lsusb 输出的结果多了"USB Modem"字样。

root# lsusb
...
Bus 002 Device 010: ID 12d1:1001 Huawei Technologies Co., Ltd. E620 USB Modem
...




3. configure
================

建立3个PPP配置文件。

root# cat /etc/ppp/peers/wcdma
nodetach
lock
/dev/gsmmodem
115200
user "card"
password "card"
crtscts
show-password
usepeerdns
noauth
noipdefault
novj
novjccomp
noccp
defaultroute
ipcp-accept-local
ipcp-accept-remote
connect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-connect'
disconnect '/usr/sbin/chat -s -v -f /etc/ppp/peers/wcdma-chat-disconnect'


root# cat /etc/ppp/peers/wcdma-chat-connect
ABORT 'NO CARRIER'
ABORT 'ERROR'
ABORT 'NO DIALTONE'
ABORT 'BUSY'
ABORT 'NO ANSWER'
'' \rAT
OK \rATZ
OK \rAT+CGDCONT=1,"IP","3gnet",,0,0
OK-AT-OK ATDT*99#
CONNECT \d\c


root# cat /etc/ppp/peers/wcdma-chat-disconnect
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
'' "\K"
'' "+++ATH"
SAY "\nGoodbay\n"




4. connect
==============

拔号连接

root# pppd call wcdma &
......
Serial connection established.
Using interface ppp0
Connect: ppp0 <--> /dev/gsmmodem
CHAP authentication succeeded
CHAP authentication succeeded
Could not determine remote IP address: defaulting to 10.64.64.64
not replacing default route to eth0 [10.217.15.1]
local  IP address 172.27.25.133
remote IP address 10.64.64.64
primary   DNS address 202.106.195.68
secondary DNS address 202.106.46.151
Script /etc/ppp/ip-up finished (pid 10543), status = 0x0


手工添加DNS

root# echo "nameserver 202.106.46.151" >> /etc/resolv.conf


手工指定默认网关

root# route add default gw 172.27.25.133


测试网络是否可用

root# ping -c 5 www.sina.com.cn
PING libra.sina.com.cn (202.108.33.80) 56(84) bytes of data.
64 bytes from 202.108.33.80: icmp_seq=1 ttl=56 time=39.6 ms
64 bytes from 202.108.33.80: icmp_seq=2 ttl=56 time=48.3 ms
64 bytes from 202.108.33.80: icmp_seq=3 ttl=56 time=46.8 ms
64 bytes from 202.108.33.80: icmp_seq=4 ttl=56 time=44.6 ms
64 bytes from 202.108.33.80: icmp_seq=5 ttl=56 time=44.1 ms

--- libra.sina.com.cn ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 39.670/44.739/48.330/2.957 ms




5. disconnect
==================

root# poff