linux是因特网时代的神话,在Linux系统中各种Internet的软件、工具应有尽有也就不足为奇了。但是对大多数用户来说,通过Modem拨号上网是联结Internet的唯一途径,在此笔者以Redhat 5.1为例,周详介绍一种拨号上网的方法,希望Linux的新手能够尽快通过Linux去畅游Internet,体会Linux强大的网络功能,获取更多 Linux的知识。
先假设您的电脑已安装好了Redhat 5.1或以上版本的linux,并且Modem已连接在电脑上。
第一步:准备Modem
需要确定Modem在电脑的哪个串口上。最简单的办法是启动Windows 95,在控制面板中察看Modem的属性;在linux下有一种简单的办法是:先确认Modem已连接在电脑上,打开Modem电源,MR、HS灯应该是亮的,然后在提示符下输入以下命令:
echo AT >/dev/ttyS0
假如Modem的TR灯亮了,表明Modem连结在COM1口,否则,再试 /dev/ttyS1、/dev/ttyS2、/dev/ttyS3。
第二步:准备核心
版本2.0.34的linux核心已内置了PPP功能,在此需要确认一下Linux的版本,假如是Redhat5.1就能够跳过这一步,因为Redhat5.1的内核版本即是2.0.34。否则就可能需要重新编译Linux内核以便支持PPP。
第三步:准备拨号脚本
在RedHat5.1中,已在/usr/doc/ppp-2.3.3/scripts目录下为我们提供了拨号脚本程式的样本,需要我们做的是将其拷贝到正确的目录并将其改为可执行文档,具体操作如下:
cp /usr/doc/ ppp-2.3.3/scripts/ppp-on /usr/sbin
cp /usr/doc/ ppp-2.3.3/scripts/ppp-off /usr/sbin
cp /usr/doc/ ppp-2.3.3/scripts/ppp-on-dialer /etc/ppp
cd /usr/sbin
chmod x ppp-on
chmod x ppp-off
cd /etc/ppp
chmod x ppp-on-dialer
然后根据您的ISP做相应的少许改变。以下是笔者所用的两个脚本ppp-on和ppp-on-dialer的内容:
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=96340 # ISP提供的上网电话号码
ACCOUNT=yuangq # 账号名称
PASSWORD=654321 # 登录密码,注意修改本文档权限以便保密
LOCAL_IP=0.0.0.0 #本地IP地址,0.0.0.0表示由ISP动态分配
REMOTE_IP=0.0.0.0 #远端IP地址,一般为0.0.0.0
NETMASK=255.255.255.0 # 子网掩码地址
#
# 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/ttyS1 115200
asyncmap 20A0000 escape FF kdebug 0 $LOCAL_IP:$REMOTE_IP
noipdefault netmask $NETMASK defaultroute connect $DIALER_SCRIPT &
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 '
BUSY
'
ABORT '
NO ANSWER
'
ABORT '
RINGING
RINGING
'
'
AT
'OK- c-OK' ATH0
TIMEOUT 30
OK ATDT$TELEPHONE
CONNECT '
sername:--sername: $ACCOUNT
assword: $PASSWORD
需要注意的是,在ppp-on脚本的最后一行用exec启动pppd的参数中,/dev/ttyS1代表Modem连结在COM2口上,115200表示 Modem的速率,能够根据实际情况进行修改;此外,假如ISP提供的拨号提示不是username,而是login的话,需要将ppp-on- dialer中的sername改为ogin(即把username和login去掉第一个字母)。
第四步:配置DNS
为了能够使用WWW浏览器、ftp、Telnet,还必须配置DNS,能够使用netconf命令进行配置,也能够直接修改/etc/resolv.conf文档,例如笔者的该文档内容如下:
search szonline.net
nameserver 202.96.154.15
其中第一行表示域名搜索后缀,第二行为ISP提供的DNS服务器的IP地址。
第五步:开始拨号上网
上述准备工作完成之后,以root权限登录,开启Modem,运行ppp-on,该脚本将负责拨号、送出登录信息并完成协议验证,当看到Modem上的数据指示灯停止闪烁并保持连接状态的话,ppp就已连接成功了。您能够用netstat -r查看路由表或pppstats检查ppp的状态,也能够通过Ping您的ISP,或直接启动Netscape浏览器来检查,假如一切正常的话,那么您的linux已连接到Internet了。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




