一、Linux 上的 PPP

Linux 中已经包括了点对点协议PPP,其主体是 pppd ,如果你已经使用过 Windows95 或 NT 的拨号网络,那么你已经具备了 PPP 的基本经验了。在 Windows95 的 PPP 在同 ISP 连接后,视 ISP 情况不同,会自动为 Windows 客户机提供 IP 地址和 DNS 服务器地址,而 Linux 的 PPP 不会自动接收 DNS 地址,这是 Linux 与 Windows 的一点区别,所以,Linux 上的 PPP 在协议连接成功后,要多一步 DNS 的配置。

二、Kernel 的准备

你的 Linux 系统必须在 kernel 中配置支持 PPP 功能。如果你的 kernel 目前不支持 PPP,你需要重新生成一个支持 PPP 的 kernel。重新编译 kernel 的方法可看相关 Howto。

三、用辅助脚本配置 PPP 拨号网络

我一开始想运行 pppd 来连接拨号网络,但很快发现这是太麻烦了,因为选项太多。后来我发现,其实在 Linux 上已经提供了几个 PPP 拨号程序模版,只要对这些模板略作修改,就可轻松联上 PPP 了。根据我的经验,如果顺利的话,10分钟就能完成配置。

(1)拨号程序所在的目录

对于 RedHat 5.0,这几个拨号程序(Script)在 /usr/doc/ppp-2.2.0f/scripts 下,如果要使用这些脚本,需要把它们拷贝到正确的目录中,具体如下:

ppp-on: PPP 连接脚本 拷贝到 /usr/sbin

ppp-off: PPP 断开脚本 拷贝到 /usr/sbin

ppp-on-dialer: PPP 登录会话脚本 拷贝到 /etc/ppp

ppp-redialer: 可轮循多个电话号码的登陆脚本 拷贝到 /usr/sbin (本文不用)

对于 Slackware 的用户,这些脚本已经安装到正确的目录了,无需做什么。

假定你在你的系统上找不到上述文件,可直接在本文后面的附录中cut。

(2)创建自己的拨号程序

假定现在我们要用 PPP 连接 163 网,我们就可以利用上述脚本来作很简单的配置。虽然我们可以直接在这些模板上做修改,我还是建议为自己拷贝一份模板,在新的拷贝上作修改比较好。所以,我们先做如下拷贝:

cd /usr/sbin

cp ppp-on ppp.163

chmod +x ppp.163

cd /etc/ppp

cp ppp-on-dialer dialer.163

chmod +x dialer.163

此外,要保证 ppp-off 也是可执行的

(3)定制自己的拨号程序

首先编辑你的 ppp.163,其中多数内容都不必改动,只要修改以下几处:

TELEPHONE=163

ACCOUNT=

PASSWORD=

DIALER_SCRIPT=/etc/ppp/dialer.163

另外,在最后的 exec 启动 pppd 一行里,注意提供你的 Modem 所在的串口设备文件(通常是 COM1 /dev/cua0 或 /dev/ttyS0,COM2 /dev/cua1 或 /dev/ttyS1),并设置串口的通信速度(缺省是 38400,对于现在的高速 Modem,这个速度太低了,可设置成 57600以上)。完成后的 ppp.163 内容是:

#!/bin/sh

#

# Script to initiate a ppp connection. This is the first part of the

# pair of scripts. This is not a secure pair of scripts as the codes

# are visible with the ps command. However, it is simple.

#

# These are the parameters. Change as needed.

TELEPHONE=163 # 拨号号码

ACCOUNT=YourUserName # 用户名

PASSWORD=YourPassword # 口令,注意限制其他人读取本文件!

LOCAL_IP=0.0.0.0 # 本地IP地址,0.0.0.0 表示动态分配

REMOTE_IP=0.0.0.0 # 原端IP地址,一般是 0.0.0.0

NETMASK=255.255.255.0 # 子网掩码

export TELEPHONE ACCOUNT PASSWORD

#

# This is the location of the script which dials the phone and logs

# in. Please use the absolute file name as the $PATH variable is not

# used on the connect option. (To do so on a root account would be

# a security hole so don t ask.)

#

DIALER_SCRIPT=/etc/ppp/dialer.163 # 拨号登录脚本文件名

#

# Initiate the connection

#

# I put most of the common options on this command. Please, don t

# forget the lock option or some programs such as mgetty will not

# work. The asyncmap and escape will permit the PPP link to work with

# a telnet or rlogin connection. You are welcome to make any changes

# as desired. Don t use the defaultroute option if you currently

# have a default route to an ethernet gateway.

#

exec /usr/sbin/pppd debug lock modem crtscts /dev/ttycua0 57600 \

asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \

noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT

然后,检查一下你的登录会话程序 /etc/ppp/dialer.163,在我所在的 163 ISP,这个从模板拷贝过来的会话程序可直接使用,如果有以下情况,你需要对这个会话程序略作改动:

(1)如果拨号提示输入用户名的提示符不是 login:

(2)如果登录成功后还要用户再交互打入命令 ,才启动 ppp 协议

本文后面的附录三是一个根据上述要求略加修改后的登录脚本。

建议:假如你有多个 ISP 可连接,就创建多个拨号 PPP 连接脚本和相应的 PPP 登录脚本。

四、启动 PPP 和断开 PPP

启动你的 PPP 连接唯一要做的就是开启 Modem,运行刚才写好的 ppp.163。你的 ppp.163 脚本将自动拨号、送出登录信息、完成协议认证,等你看到你的 Modem 上的数据传输指示灯不再闪动并保持连接状态,PPP 连接就完成了,你可以打命令:

netstat -r

查看当前的路由表,如果 PPP 协议连接成功的话,路由表里就会有连接你的 ISP 的缺省路由。你的 PPP 已经配置成功了。

如果没有成功,注意看一下 /etc/ppp 下的 PPP 出错记录文件。

要断开 PPP 连接,运行 ppp-off。

五、DNS 的配置

PPP 连接成功后,如果要使用 WWW 浏览器、Ftp、Telnet 等服务,必须正确配置 DNS 域名解析。所以,一旦 PPP 连接完毕,应该在 /etc/resolv.conf 中加入一行:

nameserver

注意 nameserver 后面的是你的 ISP 的 DNS 服务器的 IP 地址,并且这一行说明必须放在其他的 nameserver 说明之前,否则,你的 Linux 系统不会访问你的 ISP 的 DNS 服务器。然后,你就能使用各项 Internet 服务了。

六、自动配置 DNS 解析

本节内容并不是配置 PPP 必需的,但能对 PPP 的使用提供一些方便。

由于你的 Linux 并不总是连在 Internet 上,所以在不连接 PPP 时,需要的 resolv.conf 是不同的。所以,我们希望有一种办法能根据不同的情况,在 Linux 系统上自动设置合适的 resolv.conf 。

在 /etc/ppp 下,有两个根据 PPP 连接状态自动运行的脚本,ip-up 和 ip-down,分别在 PPP 建立连接和断开连接时运行,如果用户希望在 PPP 连接或断开时执行某些命令,可以在 /etc/ppp 目录下建立脚本文件 ip-up.local 和 ip-up.local,在这两个文件中放入要执行的命令。当 PPP 建立连接后,ip-up 会调用 ip-up.local,执行用户命令;当 PPP 断开连接后,ip-down 会调用 ip-down.local ,执行用户命令。

所以我们可以利用这个机制实现 DNS 解析的自动配置,方法如下:

(1)在 /etc 下编辑分别适用于 PPP 连接状态和正常本地状态的 DNS 解析配置文件,我们假定这两个文件是 resolv.ppp 和 resolv.normal。

(2)在 /etc/ppp 下建立 ip-up.local,设置其执行权限,并在文件中加入:

cp /etc/resolv.ppp /etc/resolv.conf

(3)在 /etc/ppp 下建立 ip-down.local,设置其执行权限,并在文件中加入:

cp /etc/resolv.normal /etc/resolv.conf

这样设置后,每当 PPP 连接成功后,/etc/resolv.conf 的内容就是 resolv.ppp,而 PPP 断开后,/etc/resolv.conf 被恢复成 resolv.normal 的内容。

附录一:PPP 连接脚本模板 ppp-on

#!/bin/sh

#

# Script to initiate a ppp connection. This is the first part of the

# pair of scripts. This is not a secure pair of scripts as the codes

# are visible with the ps command. However, it is simple.

#

# These are the parameters. Change as needed.

TELEPHONE=555-1212 # The telephone number for the connection

ACCOUNT=george # The account name for logon

PASSWORD=gracie # The password for this account

LOCAL_IP=0.0.0.0 # Local IP address if known. Dynamic = 0.0.0.0

REMOTE_IP=0.0.0.0 # Remote IP address if desired. Normally 0.0.0.0

NETMASK=255.255.255.0 # The proper netmask if needed

#

# Export them so that they will be available at ppp-on-dialer time.

export TELEPHONE ACCOUNT PASSWORD

#

# This is the location of the script which dials the phone and logs

# in. Please use the absolute file name as the $PATH variable is not

# used on the connect option. (To do so on a root account would be

# a security hole so don t ask.)

#

DIALER_SCRIPT=/etc/ppp/ppp-on-dialer

#

# Initiate the connection

#

# I put most of the common options on this command. Please, don t

# forget the lock option or some programs such as mgetty will not

# work. The asyncmap and escape will permit the PPP link to work with

# a telnet or rlogin connection. You are welcome to make any changes

# as desired. Don t use the defaultroute option if you currently

# have a default route to an ethernet gateway.

#

exec /usr/sbin/pppd debug lock modem crtscts /dev/ttyS0 38400 \

asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP \

noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT

附录二:PPP 登录脚本模板 ppp-on-dialer

#!/bin/sh

#

# This is part 2 of the ppp-on script. It will perform the connection

# protocol for the desired connection.

#

exec chat -v \

TIMEOUT 3 \

ABORT \nBUSY\r \

ABORT \nNO ANSWER\r \

ABORT \nRINGING\r\n\r\nRINGING\r \

\rAT \

OK-+++\c-OK ATH0 \

TIMEOUT 30 \

OK ATDT$TELEPHONE \

CONNECT \

ogin:--ogin: $ACCOUNT \

assword: $PASSWORD

附录三:一个稍作修改的 PPP 登录脚本

#!/bin/sh

#

# This is part 2 of the ppp-on script. It will perform the connection

# protocol for the desired connection.

#

exec chat -v \

TIMEOUT 3 \

ABORT \nBUSY\r \

ABORT \nNO ANSWER\r \

ABORT \nRINGING\r\n\r\nRINGING\r \

\rAT \

OK-+++\c-OK ATH0 \

TIMEOUT 30 \

OK ATDT$TELEPHONE \

CONNECT \

sername:--sername: $ACCOUNT \

assword: $PASSWORD \

nnex: ppp

说明:(1)用户登录提示符从由 login: 改为 username:

(2)用户登录后,访问服务器出现提示符 annex: ,需要手工输入 ppp 命令

附录四:可轮询拨号的 PPP 连接脚本模板 ppp-redialer

#!/bin/sh

###################################################################

#

# These parameters control the attack dialing sequence.

#

# Maximum number of attempts to reach the telephone number(s)

MAX_ATTEMPTS=10

# Delay between each of the attempts. This is a parameter to sleep

# so use "15s" for 15 seconds, "1m" for 1 minute, etc.

SLEEP_DELAY=15s

###################################################################

#

# This is a list of telephone numbers. Add new numbers if you wish

# and see the function callall below for the dial process.

PHONE1=555-1212

PHONE2=411

###################################################################

#

# If you use the ppp-on script, then these are passed to this routine

# automatically. There is no need to define them here. If not, then

# you will need to set the values.

#

ACCOUNT=my_account_name

PASSWORD=my_password

###################################################################

#

# Function to initialize the modem and ensure that it is in command

# state. This may not be needed, but it doesn t hurt.

#

function initialize

{

chat -v TIMEOUT 3 AT OK-+++\c-OK

return

}

###################################################################

#

# Script to dial a telephone

#

function callnumber

{

chat -v \

ABORT \nBUSY\r \

ABORT \nNO ANSWER\r \

ABORT \nRINGING\r\n\r\nRINGING\r \

ATDT$1 \

CONNECT \

ogin:--ogin: $ACCOUNT \

assword: $PASSWORD

#

# If the connection was successful then end the whole script with a

# success.

#

if [ "$?" = "0" ]; then

exit 0

fi

return

}

###################################################################

#

# Script to dial any telephone number

#

function callall

{

# echo "dialing attempt number: $1" >/dev/console

callnumber $PHONE1

# callnumber $PHONE2

}

###################################################################

#

# Initialize the modem to ensure that it is in the command state

#

initialize

if [ ! "$?" = "0" ]; then

exit 1

fi

#

# Dial telephone numbers until one answers

#

attempt=0

while : ; do

attempt=`expr $attempt + 1`

callall $attempt

if [ "$attempt" = "$MAX_ATTEMPTS" ]; then

exit 1

fi

sleep "$SLEEP_DELAY"

done

附录五: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

linux拨号上网icp,如何用 Linux 拨号上网相关推荐

  1. 进入路由器linux系统时间长,如何用linux做路由器限速

    如何用linux做路由器限速 linux的开源和免费使得越来越多的厂家用它来做防火墙和路由器,如海蜘蛛,飞鱼星等,其实我们也可以用linux来打造一台高性能的路由器.下面就以redhat为例(其他版本 ...

  2. linux作为网络防火墙,如何用linux做防火墙

    1.4. 写这篇文章的动机 过去一年来在comp.os.linux 论坛上有一大堆人在求救, 寻求Firewall方面的 协助, 似乎也没有什麽人要回答.我猜是没人知道要怎麽回答吧! 所以我花了一点 ...

  3. 如何用 Linux 拨号上网

    一.Linux 上的 PPP Linux 中已经包括了点对点协议PPP,其主体是 pppd ,如果你已经使用过 Windows95 或 NT 的拨号网络,那么你已经具备了 PPP 的基本经验了.在 W ...

  4. Linux蓝牙拨号,linux debian 手机usb线和蓝牙拨号上网

    闲话少说,没有网络是很难过的,家里.单位都有网络,但偶尔没网的地方又想上网,就要充分利用手机的上网包月流量. 本人手机:n97mini(只要支持蓝牙就行,呵呵) 笔记本(laptop):华硕A2400 ...

  5. 联通小区宽带拨号上网指南(Windows和Linux)

    Windows下: 据说联通小区宽带拨号上网是光缆支撑的网络,通过网线上网的,为了方便管理网络连接,写了两个bat,便于管理网络: 拨号上网.bat: netsh interface set inte ...

  6. NUC980开发板Linux系统EC20模块 移植 串口 PPP拨号

    NUC980开发板Linux系统EC20模块 移植 串口 PPP拨号 1. EC20模块连接 2. Linux内核配置 3. 交叉编译PPP 4. 拨号脚本 5. 进行拨号 1. EC20模块连接 在 ...

  7. linux 3g拨号 option.c 脚本,嵌入式Linux系统实现3G网卡拨号

    嵌入式Linux系统实现3G网卡拨号 http://blog.chinaunix.net/uid-9525959-id-3998519.htmlhttp://hi.baidu.com/backtrac ...

  8. Linux操作系统下iptables+nat实现ADSL共享上网!

    Linux操作系统下iptables+nat实现ADSL共享上网! ADSL作为一种较为成熟的宽带接入技术,凭着传输速度快.安装使用方便,无需太多的投入,以及节省费用等优点被现在大部分家庭和中小企业所 ...

  9. 不是linux内核的国产系统,国产操作系统都是山寨Windows的?为何用Linux内核?

    原标题:国产操作系统都是山寨Windows的?为何用Linux内核? 近年来,国产操作系统不断更新迭代,优化完善,性能更加稳定,软硬件兼容性更强,也得到了越来越多用户的关注,常用软件越来越多.支持多种 ...

最新文章

  1. IDEA Java解析GeoJson.json文件
  2. 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  3. UA MATH567 高维统计II 随机向量5 亚高斯随机向量
  4. linux2.6驱动学习笔记之字符驱动
  5. struts2默认配置文件 struts-default.xml
  6. 做数据分析还在死磕Excel?用这个简单工具,摆脱复杂函数和公式
  7. python做一个小游戏_利用python做个小游戏
  8. 洛谷P2886牛继电器
  9. Java数据结构和算法 - 堆
  10. CentOS6.5安装python3.7
  11. 对外汉语语料库有哪些_汉语国际教育之语料库分享
  12. java完成登录页面+连接数据库
  13. F1C100S自制开发板调试过程
  14. 分类---逻辑回归(二分类)
  15. ubuntu 12.10 安装 QQ2012
  16. 1025 反转链表 (25 分)
  17. MySQL 提问的技巧
  18. 简述计算机构位移的目的,简述应变片的选用原则
  19. MacBook 整个配置过程,供新入手MacBook的同学
  20. 腾讯翻译自然语言处理实习经验贴

热门文章

  1. mysql函数大全最小,MySQL函数一览_MySQL函数全部汇总
  2. python的web技术宅
  3. 惠而浦扫地机器人充不进电_【今日关注】惠而浦扫地机器人怎么样?体验2个月之肺腑之言? | 智能扫地机器人评测...
  4. java的技术定义_java基础知识——Java的定义,特点和技术平台
  5. 循迹传感器(TCRT5000)的介绍以及使用(STM32)
  6. 生产力提升! 自己动手自定义Visual Studio 2019的 类创建模板,制作简易版Vsix安装包
  7. Microsoft Blazor——快速开发与SQL Forms开源平台Platz.SqlForms
  8. 10天内构建良好的REST API的指南
  9. TeamCity+Rancher+Docker实现.Net Core项目DevOps(目前成本最小的DevOps实践)
  10. 逐步创建ASP.NET Core 2.2应用程序