转帖

如何用 Linux 拨号上网

一、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

本文来自: U88() 详细出处参考:

linux ppp用户管理,linux下ppp拨号上网相关推荐

  1. linux mint 用户管理,Linux Mint 新工具:将网站转变为独立的应用

    Linux Mint 目前正在积极推进 20.1 版本,日前官方博客介绍了新版本将会带来的一项有意思的新特性:WebApp 管理器. 简单来讲,这一特性可以把网站转变成独立的应用,这与基于 Debia ...

  2. Linux 基础 - 用户管理

    Linux 基础 - 用户管理 Linux 用户管理 查看当前用户 ID:id 查看当前所属组:groups 查看当前登录用户:who 查看当前登录用户详细信息:w 调查用户:finger 新增用户: ...

  3. linux下3G拨号上网

    Linux下3G拨号上网 开发板型号 :FL2440 内核版本:linux-3.0 3G上网卡:ZTE MF626 SIM卡:中国移动 1. usb_modeswitch移植 usb_modeswit ...

  4. Linux(3) 用户管理

    Linux(3) 用户管理 学习视频:https://www.bilibili.com/video/BV1Sv411r7vd?p=19&spm_id_from=pageDriver 一.开机. ...

  5. Linux 之用户管理与文件权限

    Linux 之用户管理与文件权限 一. 1.查看系统版本    uname       uname -a      uname -r      uname -m 2.特点 :              ...

  6. Linux入门到精通:第 1 关——创建/删除新用户(第二章:Linux之用户管理)

    第 1 关--创建/删除新用户 任务描述 相关知识 Linux创建用户命令 案例演示 Linux删除用户命令 案例演示 编程要求 评测说明 任务描述 恭喜你已经完成了Linux入门的实训,接下来让我们 ...

  7. 运维基本功(五):Linux文件管理-用户管理

    本文是在课程课件基础上修改的学习笔记 课程原地址:https://www.bilibili.com/video/BV1nW411L7xm 如有侵删 运维基本功(一):Linux系统安装 运维基本功(二 ...

  8. edu-【Linux 与 Python编程2021】Linux知识训练,Linux之用户管理,Linux文件/目录管理

    python实训 python学习 – 菜鸟教程+B站视频 文章目录 linux知识训练-硬件与软件安装 第1关:linux知识训练-硬件与软件安装 linux知识训练-账户进程与权限 第1关:lin ...

  9. Linux文件管理-用户管理-磁盘管理

    文件管理 文件系统应该具备的五个基本功能: 1. 用户能够用文件名对存储介质上的信息进行访问,文件系统负责完成对文件的按名存取. 2. 用户能创建一个新文件或删除一个文件,并能对指定的文件进行打开.关 ...

最新文章

  1. IDEA 常用设置
  2. mac Hbuilder 无法打开的解决方案
  3. 青少年蓝桥杯_2020_steam考试_中级组_第四题
  4. Git之深入解析如何使用Git调试项目源码中的问题
  5. 不可摸数http://acm.hdu.edu.cn/showproblem.php?pid=1999
  6. PythonOpenCV--Rtrees随机森林
  7. 扔掉伟哥!男性壮阳食品荟萃
  8. 2018美团CodeM编程大赛 Round A Problem 2 下棋 【贪心】
  9. 预告 | 4月22日,CVPR 2021论文分享会详细介绍,学术新星云集!
  10. javascript Date对象 之 获取时间
  11. memcached php 测试,php一致性hash性能测试(flexihash/memcache/memcached)
  12. 数据分析 超市条码_阜康市超市存包柜人脸识别 - 阜康办公、文教
  13. 邮件服务器加密方式,盈世Coremail邮件系统四种安全加密方式揭秘
  14. 新系统软件著作权申请流程及注意事项
  15. 【Linux】Centos设置Python的软链接
  16. 如何快速删除CSV、Excel、Markdown表格的重复行?
  17. 2.1 分布式文件系统HDFS-使用
  18. Python编写数字转换成中文大写
  19. OpensAS2搭建+AS2证书制作+SSL证书导入(EDI)
  20. PhotoShop CC 2017软件工具面板使用---移动工具

热门文章

  1. ISE使用,Xilinx学习
  2. 人工智能学习:python实现迭代加深的深度优先搜索
  3. 程序员吐槽:四年被三家公司裁员补偿,网友:去BAT转转?
  4. 【智能制造】当数据智能遇上工业制造
  5. 上海矽昌通信技术有限公司自研路由芯片
  6. AMM终极笔记——五大类无常损失解决方案
  7. TCP/IP高频考点之一个数据包的流浪日记
  8. 高职网络系统管理国赛--网络赛题1路由选路解析
  9. 吴章金: 实例解析 Linux C 语言程序之变量类型
  10. leetcode阶段总结——拓扑排序