ubuntu linux ppp 拨号 GPRS

一 首先安装ppp, 用sudo apt-get install ppp

二 拨号上网, 一共有3种方式

1.使用命令 pppd call somescript 的方式

 

- 在 /etc/ppp目录下,建立3个文件:pap-secrets,chap-secrets,gprs-connect-chat

  和一个目录:peers

  在peers目录下建立一个文件gprs

这4个文件的内容如下:

------------------------------------------

pap-secrets和chap-secrets文件内容相同,两种不同的验证文件,一种基于PAP协议,另一种基于CHAP协议。

chap-secrets文件内容如下:

# Secrets for authentication using CHAP
# client server secret   IP addresses
####### redhat-config-network will overwrite this part!!! (begin) ##########
####### redhat-config-network will overwrite this part!!! (end) ############
cmnet * cmnet *

pap-secrets文件内容如下:

# Secrets for authentication using PAP
# client server secret   IP addresses
####### redhat-config-network will overwrite this part!!! (begin) ##########
####### redhat-config-network will overwrite this part!!! (end) ############
cmnet * cmnet *

有点地区的GPRS可能使用pap方式认证接入用户,所以在同一级目录下,创建pap-secets文件,内容与chap-secets类似有4项的内容:client,server,secret,ip,第2和第4项一般不限制就用*(星号)代表。反正要你在/etc/ppp/下放着这两个文件就好。

------------------------------------------

/etc/ppp/peers/gprs文件内容如下:

# Usage:   root>pppd call gprs
/dev/ttyS0   #改成自己的端口名
115200    #改成自己的串口波特率
nocrtscts #无流控 如果你的串口需要硬件流控 就改为crtscts
modem
lock
noauth
debug
nodetach
#hide-password
usepeerdns
noipdefault
defaultroute
asyncmap 0
user cmnet #设置接入的用户名,在chap-secrets或者pap-secets中使用
0.0.0.0:0.0.0.0  #本地和远端的ip都设为0使得接入的isp分配本地的ip地址
ipcp-accept-local  #要求peer也就是isp给自己分配动态的IP地址
#ipcp-accept-remote
#lcp-echo-failure  12
#lcp-echo-interval 3

#以上2项意思是,如果36秒之内,服务器没有给回echo-reply信号,Ubuntu就会认为网络已经出了问题,马上中断

holdoff 45  //拨号超时45秒
maxfail 6    //重拨次数6次
noccp  #不需要压缩控制协议,有可能对端不需要,根据自己的isp的情况
#novj
#novjccomp
#-mn
persist  #保证在连接断开的情况下不退出,并尝试重新打开连接
connect '/usr/sbin/chat -s -v -f /etc/ppp/gprs-connect-chat'
#pppd调用chat会话进程接入对端isp,启动对端的pppd,然后本地pppd与对端的pppd一起进行协
#商网络参数和chap/pap认证,成功后,再进行ncp层的ip的分配。

------------------------------------------

/etc/ppp/gprs-connect-chat文件内容如下:

#/etc/ppp/gprs-connect-chat
TIMEOUT 15
ABORT  '/nBUSY/r'  
ABORT  '/nNO ANSWER/r'  
ABORT  '/nRINGING/r/n/r/nRINGING/r'
#'' AT 
#'OK-+++/c-OK' ATH0
TIMEOUT 40
#''     /rAT
#OK     ATS0=0      #这些都是标准的at命令,建议查看随模块的at命令手册
#OK     ATE0V1
''    ATZ
OK    ATE1
#
OK      AT+CGDCONT=1,"IP","CMNET" #设置isp接入网关为中国移动的cmnet,如果你想获得更多访问资源的话
OK      'ATDT*99***1#'   #中国移动gprs的接入号码
CONNECT    ''

 

- 在建立了ppp0连接以后可以使用ctrl+c或者下面的脚本程序ppp-off断开ppp连接
#/etc/ppp/ppp-off
#!/bin/sh
######################################################################
#
# Determine the device to be terminated.
#
if [ "$1" = "" ]; then
DEVICE=ppp0
else
DEVICE=$1
fi
######################################################################
#
# If the ppp0 pid file is present then the program is running. Stop it.
if [ -r /var/run/$DEVICE.pid ]; then
        kill -INT `cat /var/run/$DEVICE.pid`
#
# If the kill did not work then there is no process running for this
# pid. It may also mean that the lock file will be left. You may wish
# to delete the lock file at the same time.
        if [ ! "$?" = "0" ]; then
                rm -f /var/run/$DEVICE.pid
                echo "ERROR: Removed stale pid file"
                exit 1
        fi
#
# Success. Let pppd clean up its own junk.
        echo "PPP link to $DEVICE terminated."
        exit 0
fi
#
# The ppp process is not running for ppp0
echo "ERROR: PPP link is not active on $DEVICE"
exit 1

 

- 做好上面的配置以后,输入pppd call gprs命令,注意如果你的gprs这个文件不在/etc/ppp/peers/目录下,在给出标注路径给pppd
- 使用gprs连接上internet

要用ping,你需要将eth0即网口给禁用掉,这样ping才会通过ppp0端口寻找路由连接外网。禁掉有线,用无线上网。

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0A:EB:91:3B:C4  
          UP BROADCAST 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:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:209 Base address:0x4000
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:1240 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1240 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2039094 (1.9 MiB)  TX bytes:2039094 (1.9 MiB)
ppp0      Link encap:Point-to-Point Protocol  
          inet addr:10.144.202.159  P-t-P:10.64.64.64  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:62 (62.0 b)  TX bytes:98 (98.0 b)
[root@localhost ~]# ifconfig eth0 down      
禁用以太网接口eth0,使得不和ppp0接口使用时候的路由冲突
[root@localhost ~]# ping 211.136.20.203
这时候只能ping纯的ip地址

将正确的dns加入到/etc/resolv.conf中后,可以ping域名

[root@localhost ~]# ping www.baidu.com

2.使用智能的ppp拨号软件wvdial

3.使用3个脚本的方式:即ppp-on,ppp-on-dialer,ppp-off

参考文档:linux-ppp-howto ( http://www.dcaccess.net/welcome/linux/PPP-HOWTO.html)

 

三 pppd断线重拨

http://blog.chinaunix.net/u3/111961/showart_2193905.html

http://blog.chinaunix.net/u3/111961/showart_2193876.html

 

 

 

参考文件:

http://blog.chinaunix.net/u3/111961/showart_2194656.html

http://hi.baidu.com/chunshi80/blog/item/84769cf058f9d518b17ec548.html

http://dev.firnow.com/course/6_system/linux/Linuxjs/20090823/170247.html

http://blog.csdn.net/bouillisy/archive/2005/07/27/436203.aspx

http://blog.csdn.net/dong_miao/archive/2009/11/05/4773009.aspx

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值