风之狂 发表于 2007-2-7 15:22:12

在Debian Linux下使用ADSL

首先我多谢本论坛的写了关于如何用ADSL文章的各位作者,没有你们我也不能在这里写下这篇文章。多谢了。
本文以Debian Linux 2.6.18 为实验平台,其它平台的Linux安装可以参照,具体有不同的地方
(主要是拔号的命令不同)
1、安装前的准备工作
1.1确保PC的网卡正常工作
使用命令
#ifconfig eth0
查看网卡状态
1.2编辑/etc/network/interfaces(以下是本作者的配置,有需要的请个别调整,也可以直接复制)
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface (Loop回环地址)
auto lo
iface lo inet loopback
# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp
# 启动系统激活设备.
auto eth0
# 网卡eth0设置为Static类型.
iface eth0 inet static
# 指定IP地址.子网掩码.广播.网关.
address 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
#不要设置网关,这个很重要,读者请注意!
#在系统中不要设置默认路由(网关),让ADSL拨号后自动获得
#gateway
1.3确保已安装ppp软件包
如果存在文件 /usr/sbin/pppd,则说明已经安装了pppd;
如果未安装,从Debian第一张安装光盘上的上安装ppp_2.*.*rel-4_i386.deb这个软件包
也可以从http://ftp.tw.debian.org/debian/pool/main/p/ppp/上下载最新的,具体的文件请自己上网下载。
2、安装rp-pppoe客户端口软件
2.1下载rp-pppoe软件包
有需要的请到http://ftp.tw.debian.org/debian/pool/main/r/rp-pppoe/上下载,里面的.deb包软件名是pppoe_3.8-*.*_i386.deb,请读者注意,源码包软件名rp-pppoe_3.8-*.*tar.gz,请其他格式版本的到相应的网站下载,自己编译也可以。
2.2安装rp-pppoe软件包
以下需要root的权限
2.2.1 .deb格式安装
#dpkg -i pppoe_3.*-*.*_i386.deb
2.2.2 源码包格式安装
2.2.2.1QUICKSTART(快速安装)
----------
If you're lucky, the "quickstart" method will work.After unpacking
the archive, become root and type:
        ./go
This should configure, compile and install the software and set up your
DSL connection.You'll have to answer a few questions along the way.
If you want the GUI wrapper, type:
        ./go-gui
If ./go and ./go-gui didn't work, read the rest of this README.
2.2.2.2Compiling(编译安装)
---------
Compile and install pppd if you don't already have it.Then:
1) Unpack:
        $ tar xzvf rp-pppoe-xxx.tar.gz
2) Change to source directory:
        $ cd src
3) Configure:
        $ ./configure
4) Compile:
        $ make
4) Install (this step must be done as root)
        # make install
5) Now read doc/HOW-TO-CONNECT
2.3配置rp-pppoe客户端口
# /usr/local/sbin/pppoe-setup
Welcome to the Roaring Penguin PPPoE client setup.First, I will run
some checks on your system to make sure the PPPoE client is installed
properly...
Looks good!Now, please enter some information:
USER NAME
#输入ADSL帐号的用户名
>>> Enter your PPPoE user name (default [email protected]): **********(用户名)
INTERFACE
#ADSL相连的网卡的名字
>>> Enter the Ethernet interface connected to the DSL modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethn, where 'n' is a number.
(default eth0): eth0
#demand value不用输入
Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped.If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses.You may have some pr使用pppoe拨号oblems with demand-activated links.
>>> Enter the demand value (default no):
DNS
#DNS服务器的IP,两个
Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
>>> Enter the DNS information here:server
这一行,请各位用‘server’,让PC自动配置IP

PASSWORD
#密码
>>> Please enter your PPPoE password:
>>> Please re-enter your PPPoE password:
FIREWALLING
#防火墙,设为0
Please choose the firewall rules to use.Note that these rules are
very basic.You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security.If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself.Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc.If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.
The firewall choices are:
0 - NONE: This script will not set any firewall rules.You are responsible
          for ensuring the security of your machine.You are STRONGLY
          recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
                for a LAN
>>> Choose a type of firewall (0-2): 0
** Summary of what you entered **
Ethernet Interface: eth0
User name:          abcdefg(用户名)
Activate-on-demand: No
Primary DNS:      *.*.*.*
Secondary DNS:      *.*.*.*
Firewalling:      NONE
#信息正确,输入 y ,完成配置,否则,输入 n 重新输入
>>> Accept these settings and adjust configuration files (y/n)? y
Adjusting /etc/ppp/pppoe.conf
Adjusting /etc/resolv.conf
(But first backing it up to /etc/resolv.conf-bak)
Adjusting /etc/ppp/pap-secrets and /etc/ppp/chap-secrets
(But first backing it up to /etc/ppp/pap-secrets-bak)
(But first backing it up to /etc/ppp/chap-secrets-bak)
Congratulations, it should be all set up!
Type 'pppoe-start' to bring up your PPPoE link and 'pppoe-stop' to bring
it down.Type 'pppoe-status' to see the link status.
3、登录ADSL
3.1使用pppoe拨号
启动ADSL
#pppoe-start
#.Connected!(连接上)
停止ADSL
#pppoe-stop
ADSL状态
#pppoe-status
3.2测试网络
检查是否存在ppp0端口和其信息
# ifconfig -a
eth0      Link encap:EthernetHWaddr 00:80:48:01:00:DA
          inet addr:192.168.0.1Bcast:192.168.0.255Mask:255.255.255.0
          inet6 addr: fe80::280:48ff:fe01:da/64 Scope:Link
          UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
          RX packets:215259 errors:0 dropped:0 overruns:0 frame:0
          TX packets:230149 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:100254479 (95.6 MiB)TX bytes:86978178 (82.9 MiB)
          Interrupt:185 Base address:0xb400
lo      Link encap:Local Loopback
          inet addr:127.0.0.1Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNINGMTU:16436Metric:1
          RX packets:195732 errors:0 dropped:0 overruns:0 frame:0
          TX packets:195732 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:82843977 (79.0 MiB)TX bytes:82843977 (79.0 MiB)
ppp0      Link encap:Point-to-Point Protocol
          inet addr:59.34.147.239P-t-P:59.34.147.1Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICASTMTU:1492Metric:1
          RX packets:3808 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3913 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:3
          RX bytes:2164406 (2.0 MiB)TX bytes:586302 (572.5 KiB)
sit0      Link encap:IPv6-in-IPv4
          NOARPMTU:1480Metric: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:0
          RX bytes:0 (0.0 b)TX bytes:0 (0.0 b)
查看路由表信息
netstat -nr
Kernel IP routing table
Destination   Gateway         Genmask         Flags   MSS Windowirtt Iface
59.34.147.1   0.0.0.0         255.255.255.255 UH      0 0          0 ppp0
192.168.0.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         0.0.0.0         0.0.0.0         U         0 0          0 ppp0
如果没有默认路由,可以手动增加:
#route add default gw 上面获得的IP地址
如果解析出新浪的IP,说明已经从拨号中正确获得了DNS服务器
#nslookup www.sina.com.cn
最后,使用命令ping某个域名或IP,如果有响应,表示已经大功告成。
声明:本文参照多个作者的文章,有些是从网上搜索的,具体的名字我也查不到,如果有什么侵权的,请发e-mail:[email protected]
本文可以自由传播,具体请参照《GNU GENERAL PUBLIC LICENSE》。

loveccy 发表于 2007-2-7 18:38:44

楼主写得不错啊!辛苦了!

不过我想说,我用的是 Debian Sarge ,ppp 版本是 2.4.3-20050321 。别的发行版不知道,反正 Sarge 里的 ppp 本身就能连 ADSL 了,不装 pppoe 也行。而且就算给网卡设置了一个网关也没关系。

比如我的 /etc/network/interfaces 里有:
auto eth0
iface eth0 inet static
      address 192.168.1.100
      netmask 255.255.255.0
      network 192.168.1.0
      broadcast 192.168.1.255
      gateway 192.168.1.1
最后一行给 eth0 设了网关。

装了 ppp ,不用装 pppoe 。只要把 /usr/share/doc/ppp/examples/peers-pppoe 拷贝到 /etc/ppp/peers/ 目录下边,改一下它的内容,把 ``user "myusername@realm"‘’ 这行换成自己的用户名,在文件最后加上 ``replacedefaultroute‘’ 这么一行。然后再在 /etc/ppp/pap-secrets 文件里边最后加上一行类似这样的 ``myusername@realm * password‘’ ,分别是用记名和密码。这就行了。

上网只要用命令 ``pon peers-pppoe‘’ ,断开用 ``poff’‘ 就行了。只有 dip 组里的用户才能拨号上网。上网密码存在 pap-secrets 文件里边,这个文件的权限是只有 root 用户才能读,其它人都看不见,这应该够安全了。

加上了 ``replacedefaultroute‘’ 这个选项就可以自动替换默认路由了。验证:
$ /sbin/route
Kernel IP routing table
Destination   Gateway         Genmask         Flags Metric Ref    Use Iface
localnet      *               255.255.255.0   U   0      0      0 eth0
default         192.168.1.1   0.0.0.0         UG    0      0      0 eth0
$ pon peers-pppoe
Plugin rp-pppoe.so loaded.
$ /sbin/route
Kernel IP routing table
Destination   Gateway         Genmask         Flags Metric Ref    Use Iface
60.4.192.1      *               255.255.255.255 UH    0      0      0 ppp0
localnet      *               255.255.255.0   U   0      0      0 eth0
default         60.4.192.1      0.0.0.0         UG    0      0      0 ppp0
$ poff
$ /sbin/route
Kernel IP routing table
Destination   Gateway         Genmask         Flags Metric Ref    Use Iface
localnet      *               255.255.255.0   U   0      0      0 eth0
default         192.168.1.1   0.0.0.0         UG    0      0      0 eth0

其实还有好多别的选项可以加到配置文件里去,这些东西都能在 man pppd 里边找到,还有 /usr/share/doc/ppp/ 目录下边的文档。

pppoe 软件包提供的就是一个更方便一点的用户界面。不是必需的。──别的发行版不知道,Sarge 是这样的。

风之狂 发表于 2007-2-8 09:17:08

谢谢,二楼,他的方法是最方便的,我的有很多是多余的工作。
顺便体下,
安照二楼的,你们写个脚本会方便点上网,

#!/bin/bash   #这里可改到你们每个人相应的shell
pon peers-pppoe

有点笨小林 发表于 2007-2-10 16:03:15

我直接利用网络配置新建XDSL连接.然后输入帐号密码就连上了... :mrgreen:
页: [1]
查看完整版本: 在Debian Linux下使用ADSL