Chinaunix首页 | 论坛 | 博客
  • 博客访问: 641758
  • 博文数量: 227
  • 博客积分: 8017
  • 博客等级: 中将
  • 技术积分: 2069
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-08 22:50
文章分类

全部博文(227)

文章存档

2011年(10)

2010年(55)

2009年(28)

2008年(134)

我的朋友

分类: LINUX

2009-12-15 16:26:08

pppd程序调用chat会话进程接入isp,然后本地pppd与对端的pppd一起进行协商网络参数和chap/pap认证,成功后再进行ncp层的ip的分配。
1. 为chat建立配置文件: femacs /etc/ppp/chat-gprs-connect
TIMEOUT 5
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'
ABORT '\nRINGING\r\n\r\nRINGING\r'
'' AT

TIMEOUT 60
SAY "Press CTRL-C to break the connection process.\n"
OK AT+CGREG=1
OK AT+CGATT=1
OK 'AT+CGDCONT=1,"IP","CMNET"'
OK AT+CGQMIN=1,0,0,0,0,31
OK AT+CGACT=1,1
OK ATDT*99***1#

TIMEOUT 60
SAY "Waiting for connect...\n"
CONNECT ''
SAY "Connect Success!\n"


2. 为pppd建立配置文件: femacs /etc/ppp/peers/gprs
/dev/ttyS0
115200
crtscts  ##流控
nodetach ##在前台运行,如果要在后台运行则去掉该项
noauth  
usepeerdns ##使用DNS,否则还得自己去改/etc/resolv.conf文件
noipdefault
ipcp-accept-local
ipcp-accept-remote
defaultroute
user itlanger ##必须有,因为不像windows下可以不需要用户名
connect '/usr/sbin/chat -s -v -f /etc/ppp/chat-gprs-connect'
debug ##输出调试, /var/log/messages中


3. 建立chap-secrets文件: femacs /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client    server    secret            IP addresses
itlanger    *    passwd-123

4. 建立pap-secrets: femacs /etc/ppp/pap-secrets
itlanger    *    passwd-123


5. 拨号: sudo pppd call gprs
这里一步可以先关闭eth0: sudo ifconfig eth0, 然后再拨号。
root@udesktop:~# pppd call gprs
timeout set to 5 seconds
abort on (\nBUSY\r)
abort on (\nERROR\r)
abort on (\nNO ANSWER\r)
abort on (\nNO CARRIER\r)
abort on (\nNO DIALTONE\r)
abort on (\nRINGING\r\n\r\nRINGING\r)
send (AT^M)
timeout set to 60 seconds
Press CTRL-C to break the connection process.
expect (OK)

^M
NO CARRIERNO CARRIER^M
 -- failed
Failed (
)O CARRIER

Script /usr/sbin/chat -s -v -f /etc/ppp/chat-gprs-connect finished (pid 12187), status = 0x7
Connect script failed
root@udesktop:~# pppd call gprs
timeout set to 5 seconds
abort on (\nBUSY\r)
abort on (\nERROR\r)
abort on (\nNO ANSWER\r)
abort on (\nNO CARRIER\r)
abort on (\nNO DIALTONE\r)
abort on (\nRINGING\r\n\r\nRINGING\r)
send (AT^M)
timeout set to 60 seconds
Press CTRL-C to break the connection process.
expect (OK)
AT
AT^M^M
OKOK
 -- got it

send (AT+CGREG=1^M)
expect (OK)

^M
AT+CGREG=1
AT+CGREG=1^M^M
OKOK
 -- got it

send (AT+CGATT=1^M)
expect (OK)

^M
AT+CGATT=1
AT+CGATT=1^M^M
OKOK
 -- got it

send (AT+CGDCONT=1,"IP","CMNET"^M)
expect (OK)

^M
AT+CGDCONT=1,"IP","CMNET"
AT+CGDCONT=1,"IP","CMNET"^M^M
OKOK
 -- got it

send (AT+CGQMIN=1,0,0,0,0,31^M)
expect (OK)

^M
AT+CGQMIN=1,0,0,0,0,31
AT+CGQMIN=1,0,0,0,0,31^M^M
OKOK
 -- got it

send (AT+CGACT=1,1^M)
expect (OK)

^M
AT+CGACT=1,1
AT+CGACT=1,1^M^M
OKOK
 -- got it

send (ATDT*99***1#^M)
timeout set to 60 seconds
Waiting for connect...
expect (CONNECT)

^M
ATDT*99***1#
ATDT*99***1#^M^M
CONNECTCONNECT
 -- got it

send (^M)
Connect Success!

Script /usr/sbin/chat -s -v -f /etc/ppp/chat-gprs-connect finished (pid 12190), status = 0x0
Serial connection established.
using channel 15
Using interface ppp0
Connect: ppp0 <--> /dev/ttyS0
sent [LCP ConfReq id=0x1 ]
rcvd [LCP ConfNak id=0x1 ]
sent [LCP ConfReq id=0x2 ]
rcvd [LCP ConfAck id=0x2 ]
rcvd [LCP ConfReq id=0x3 ]
sent [LCP ConfAck id=0x3 ]
rcvd [CHAP Challenge id=0x1 <6c3add0c80f015a65bed1386fd31d9ad66bc651c>, name = ""]
sent [CHAP Response id=0x1 <1ae01bc4ac25cc43df372b91498a29e3>, name = "itlanger"]
rcvd [CHAP Success id=0x1 ""]
CHAP authentication succeeded
CHAP authentication succeeded
sent [CCP ConfReq id=0x1 ]
sent [IPCP ConfReq id=0x1 ]
rcvd [LCP ProtRej id=0x4 80 fd 01 01 00 0f 1a 04]
Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
rcvd [IPCP ConfReq id=0x1 ]
sent [IPCP ConfAck id=0x1 ]
rcvd [IPCP ConfRej id=0x1 ]
sent [IPCP ConfReq id=0x2 ]
rcvd [IPCP ConfNak id=0x2 ]
sent [IPCP ConfReq id=0x3 ]
rcvd [IPCP ConfAck id=0x3 ]
local  IP address 10.24.228.224
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 started (pid 12196)
Script /etc/ppp/ip-up finished (pid 12196), status = 0x0


6.测试: ping
itlanger@udesktop:~$ ping
PING (202.108.22.43) 56(84) bytes of data.
64 bytes from xd-22-43-a8.bta.net.cn (202.108.22.43): icmp_seq=1 ttl=50 time=1523 ms
64 bytes from xd-22-43-a8.bta.net.cn (202.108.22.43): icmp_seq=2 ttl=50 time=1444 ms
64 bytes from xd-22-43-a8.bta.net.cn (202.108.22.43): icmp_seq=3 ttl=50 time=891 ms
64 bytes from xd-22-43-a8.bta.net.cn (202.108.22.43): icmp_seq=4 ttl=50 time=1551 ms
64 bytes from xd-22-43-a8.bta.net.cn (202.108.22.43): icmp_seq=5 ttl=50 time=995 ms
^C
--- ping statistics ---
6 packets transmitted, 5 received, 16% packet loss, time 8875ms
rtt min/avg/max/mdev = 891.870/1281.506/1551.916/279.838 ms, pipe 2


7. 关闭连接: CTRL-C
或者: sudo killall -9 ppp0


参考文章:
1. http://blog.csdn.net/bouillisy/archive/2005/07/27/436203.aspx
2. http://blog.chinaunix.net/u3/90973/showart_1998886.html
阅读(1842) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-12-16 17:35:26

好!

chinaunix网友2009-12-16 17:35:26

好!