手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>操作系统>Linux>列表

如何用 Linux 拨号上网

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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
###################################################################
#

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!