linux下用wvdial实现gprs拨号上网


1. 安装wvdial

sudo apt-get install wvdial

2. 在/etc/wvdial.conf中写入wvdial的配置信息: femacs /etc/wvdial.conf

Init1 = ATZ

Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0

Init3 = AT+CGDCONT=1,"IP","CMNET"  ##important! 否则无法使用DNS

Modem Type = Analog Modem

Baud = 115200  ##根据你的gprs modem来设定

New PPPD = yes

Modem = /dev/ttyS0 ##你所连接的串口

ISDN = 0

Phone = *99***1#  ##中国移动的拨号号码

Password = ***    ##其实没什么用

Username = itlanger

这一步,可以首先运行wvdial,这时会出现找不到modem,然后修改/etc/wvdial.conf, 增加

Baud = 115200  ##根据你的gprs modem来设定

Modem = /dev/ttyS0 ##你所连接的串口

然后再次运行wvdial, 再手动加入一下内容到/etc/wvdial.conf:

Init3 = AT+CGDCONT=1,"IP","CMNET"

Phone = *99***1#  ##中国移动的拨号号码

Password = ***    ##其实没什么用

Username = itlanger

这里Init3 = AT+CGDCONT=1,"IP","CMNET" 一定要加,否则wvdial拨号时会出现:

warning, can't find address for `www.suse.de`

--> warning, address lookup does not work

--> Nameserver (DNS) failure, the connection may not work.

导致只能ping通IP,不能ping通域名

3. 配置ppp参数: femacs /etc/ppp/options

noipdefault

ipcp-accept-local

ipcp-accept-remote

defaultroute

noauth

crtscts

debug

4.拨号上网: sudo wvdial

--> WvDial: Internet dialer version 1.60

--> Initializing modem.

--> Sending: ATZ

ATZ

OK

--> Sending: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0

ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0

OK

--> Sending: AT+CGDCONT=1,"IP","CMNET"

AT+CGDCONT=1,"IP","CMNET"

OK

--> Modem initialized.

--> Sending: ATDT*99***1#

--> Waiting for carrier.

ATDT*99***1#

CONNECT

~[7f]}#@!}!}#} }9}"}&} }*} } }'}"}(}"}%}&K_{}$}#}%B#}%<e~

--> Carrier detected.  Waiting for prompt.

~[7f]}#@!}!}#} }9}"}&} }*} } }'}"}(}"}%}&K_{}$}#}%B#}%<e~

--> PPP negotiation detected.

--> Starting pppd at Tue Dec 15 11:19:14 2009

--> Pid of pppd: 6666

--> Using interface ppp0

--> Authentication (CHAP) started

--> Authentication (CHAP) successful

--> local  IP address 10.24.229.233

--> remote IP address 192.168.254.254

--> primary   DNS address 211.137.160.5

--> secondary DNS address 211.136.17.107

--> Script /etc/ppp/ip-up run successful

--> Default route Ok.

--> Nameserver (DNS) Ok.

--> Connected... Press Ctrl-C to disconnect

4. 断开以太网连接:

sudo ifconfig eth0 down

sudo route add default gw 10.24.229.233 ##这里是ppp0的IP

5. 测试网络:

ping 60.28.166.84

ping www.chinaunix.net

如果ping不通域名,可以cat /etc/resolv.conf

然后写入拨号获得的DNS
 

相关内容