Linux使用adsl计时制分享(转)

Linux使用adsl计时制分享(转)[@more@]前言∶

最近台湾网路环境的蓬勃发展,许多宽频上网的方案更是让大家争相申请,其中 ADSL 也是许多网路族的最爱,以 Hinet 所推出的 ADSL 为例,有分固定制和计时制两种,其中最大的差别在于固定制有固定的 IP 位址,所以价格较贵,而计时制则采用动态分配 IP 的方式,价格较为便宜。一般来说,如果小型的公司机构或是个人 SOHO 族会申请固定制,以提供一些伺服器的功能,如 Web、FTP……等等,而一般的民众则会选择申请计时制的。
一般说来,现在拥有超过两部电脑的家庭越来越多了,或者是学生们一起租外面的公寓,每个人有一部电脑也不是甚么稀奇的事,这时候大家就会希望以最少的花费让所有的电脑都能上网,但以 Hinet 的 ADSL 计时制为例,最多也只能同时提供两部电脑同时拨接,如何能利用其中一部电脑来提供网路分享的功能,也变成网路上非常的热门的话题,而 Linux 优异的网路特性,当然能够为大家提供理想的网路共享环境。
由于计时制的 ADSL 有较多的人申请,所以这篇文章会教大家如何配合 Linux 来让 ADSL 计时制达到最大的效益。

安装前准备∶

硬体∶
一般说来,要以 Linux 拿来做路由的 PC 等级并不需要很高,486 或 Pentium 100 等级的电脑就绰绰有余了,重点是在网路卡,因为他们负责所有的网路交通,所以挑选两张较好的网卡是网路顺畅的关键。

软体∶
Linux 的作业系统∶
在这篇文章中将以 OpenLinux 的 eServer 2.3 及 eDesktop 2.4 为例,所使用的 packet filter 工具为 ipchains 套件(内建),以避免因 Linux Distributions 的版本不同而产生的问题。
pppd 拨接软体∶
要使用 ADSL 计时制的拨接软体,首先要先确定你的系统中有安装 pppd 才能安装,而且版本必需为 2.3.10 或之后的版本,在 OpenLinux 的 eServer 2.3 及 eDesktop 2.4 中皆有。
rp-pppoe ADSL 拨接软体∶
ADSL 计时制是采 PPPoE (Point-to-Point Over Ethernet) 的通讯协定,所以我们必须要找一套在 Linux 上执行的拨接软体,本文所采用的软体为 rp-pppoe,目前最新的版本为 3.2 版,你可以至 http://www.roaringpenguin.com/pppoe/ 查询相关的资料跋略氐蛋福?疚乃?略氐牡蛋阜独??tarBall 的原始档 rp-pppoe-3.2.tar.gz。

在进行安装之前,请先确定你的两张网卡皆驱动正常,且先确定哪张网卡对内,哪张网卡对外,本文将以 eth0 对内,且 ip 设为私有 ip (192.168.1.254),eth1 对外,将 ip 设为 dhcp 的方式取得,但预设开机时不启动,你可以使用 ifconfig 的指令检查如下就表示正确了。

[root@linux /root]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:00:E8:11:E2:F1
inet addr:192.168.1.254 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric: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:100
Interrupt:5 Base address:0x300

eth1 Link encap:Ethernet HWaddr 00:00:E8:11:E2:F2
BROADCAST MULTICAST MTU:1500 Metric: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:100
Interrupt:10 Base address:0x320

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:3924 Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0

开始安装∶

将你于 http://www.roaringpenguin.com/pppoe/ 所取得的 rp-pppoe-3.2.tar.gz 以 tar 指令解开。

[root@linux /root]# tar zxvf rp-pppoe-3.2.tar.gz

解开后会产生一个名为 rp-pppoe-3.2 的目录,你可以先阅读里面的 README 档,里面有简介一些使用及安装方式,本文介绍自行编译的方式,所以先将工作目录切换至 rp-pppoe-3.2/src/ 下。

[root@linux /root]# cd rp-pppoe-3.2/src/

接着依序输入下列指令,就可以完成安装。

[root@linux src]# ./configure
[root@linux src]# make
[root@linux src]# make install

设定∶

安装完成之后,接着我们来设定拨接 ADSL 的相关资料,输入下面的指令开始设定∶

[root@linux /root]# adsl-setup
Welcome to the Roaring Penguin ADSL 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

>>> Enter your PPPoE user name (default bxxxnxnx@shinewave.com):84xxxxxx@hinet.net

在这里输入 ISP 给你的帐号,如 84xxxxxx@hinet.net

INTERFACE

>>> Enter the Ethernet interface connected to the ADSL modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethn, where 'n' is a number.
(default eth1):eth1

输入要用来拨接 ADSL 的界面,如本文例为 eth1

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 problems with demand-activated links.
>>> Enter the demand value (default no):no

这里是设定 ADSL 是否自动断线,如果你希望 ADSL 一直保持连线状态则输入 no,如果你希望一段时间没有使用则自动断线的话,则输入你希望的秒数



DNS

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:168.95.1.1

输入你的 DNS Server 的 ip,如 Hinet 所提供的 168.95.1.1



Please enter the IP address of your ISP's secondary DNS server.
If you just press enter, I will assume there is only one DNS server.
>>> Enter the secondary DNS server address here:168.95.192.1

输入你次要的 DNS Server 的 ip,如 Hinet 所提供的 168.95.192.1



PASSWORD

>>> Please enter your PPPoE password:********
>>> Please re-enter your PPPoE password:********

输入 ISP 提供给你拨接 ADSL 的密码,并多输入一次以确认密码正确



FIREWALLING

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

这个选项是设定 firewall,共有 0、1、2 三种设定,0 是没有设定任何有关 firewall 的选项,只有提供拨接至 Internet 的功能,1 是为你提供一些基本的 firewall 功能,较适合当你的 Linux 机器是独立的 Server 时选择,2 是由程式帮你设定 firewall的功能,把 Linux 设成 Gateway 的角色,让内部机器可以连外;这里我们选择 0,没有 firewall 的设定来示范,这样我们可以使用 ipchains 来设定自己的 firewall 的功能

** Summary of what you entered **

Ethernet Interface: eth1
User name: 84xxxxxx@hinet.net
Activate-on-demand: No
Primary DNS: 168.95.1.1
Secondary DNS: 168.95.192.1
Firewalling: NONE

>>> Accept these settings and adjust configuration files (y/n)?y

上表是将我们刚刚设定值的列表,在你确认所有的设定都正确无误之后,就按 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 'adsl-start' to bring up your ADSL link and 'adsl-stop' to bring
it down. Type 'adsl-status' to see the link status.

到这里,ADSL 的拨接程式的设定完成了


设定完成之后,我们可以先来测试看看,当然你要将 eth1 接上 ISP 所提供的ADSL Router

拨接 ADSL 启动连线∶ [root@linux /root]# adsl-start

查看 ADSL 的连线状态∶ [root@linux /root]# adsl-status

结束 ADSL 的连线∶ [root@linux /root]# adsl-stop

在完成了 ADSL 拨接程式的安装及测试之后,我们要设定让这一部 Linux 的机器能在开机时就能自动拨接上 Internet 且断线后还能自动恢复连线,还有要加上 NAT 的功能让所有的电脑都能共享频宽。

首先在开机时就要让 ADSL 的拨接程式就自动启动,让程式开机时就自动启动的方式最简单的就是在 /etc/rc.d/rc.local 这个档案的最后加上一行你所要执行的程式的指令,如下所示∶
/usr/sbin/adsl-start

而有鉴于 ADSL 计时制的连线品质并不是很稳定,偶尔还会给你断线一下,所以我在 /etc/crontab 档案的最后加上一行下面的设定。
*/5 * * * * root /usr/sbin/adsl-start 2>/dev/null
这一行的设定表示,每5分钟执行一次 adsl-start 来启动 ADSL,而 adsl-start 这个程式本身会侦测现在 ADSL 的连线是否正常,如果连线正常,则会传回一个错误讯息表示已经是连线状态了,不给予执行,所以我使用 “2>/dev/null” 将这个错误讯息导出至 /dev/null 这个无底洞装置,否则你每5分钟就会收到一封 cron 程式寄给你的信 ( cron 程式执行时若有错误讯息,会以 mail 的方式通知管理者),如果连线中断的话,除非是对方机房的问题,否则最多不超过5分钟又可以恢复正常的连线罗!

接着我们要来使这一部 Linux 的机器有 NAT 的功能,首先要将 IPFORWARDING 的功能打开,因为我们有装两张网卡,要让这两张网卡的所接触到的网段能透过这一部 Linux 的机器来达到沟通转换的功能,所以我们在 /etc/sysconfig/network 这个档案中加上一行∶
IPFORWARDING=yes
然后我们要使我们内部的网段(192.168.1)的封包,能够藉由这一部 Linux 的机器伪装出去,因为 192.168.1 的网段是属于私有 ip,外界的 route 如果遇到这一类的封包会将之抛弃,所以我们必需利用我们所拨接 ADSL 所得到的公有ip,将我们的私有ip 重新包装再转送出去,所以我们在 /etc/rc.d/rc.local 这个档案中再加上一行
ipchains -A forward -j MASQ -s 192.168.1.0/24
这一行的意思是在 forward 这个 chian 中增加一条规则,只要封包的来源 ip 是192.168.1.0/24的网段的,就将之伪装后再送出。
最后,因为伪装出去的封包,在使用某些通讯协定上会造成一些问题,如 ftp 是最常见的,好在现在大部份的问题都已经有方法可以排除,我们使用外挂模组的方式将这些问题解决,这些解决伪装封包的问题的模组大多位在 /lib/modules/2.2.14/ipv4/ 的目录下,并以 ip_masq_*.o 的方式命名,所以我们可以在 /etc/modules/default 这个档案中加上模组的名称,以让其开机时就可以载入。
ip_masq_autofw
ip_masq_cuseeme
ip_masq_ftp
ip_masq_irc
ip_masq_mfw
ip_masq_portfw
ip_masq_quake
ip_masq_raudio
ip_masq_user
ip_masq_vdolive
到这里为止,你的这一部 Linux 的电脑在重开机之后就是一部可以提供宽频共享的机器了,

接下来我们来看看网路方面的架构,在这部 Linux 的机器上有两张网卡,一张当然要接上 ISP 公司所提供的 ADSL Router,本文中是 eth1 这张网卡,而另外一张 eth0 则是提供 Gateway 的功能,让大家可以透过它来上网,所以你必须准备一个 HUB 来串接所有的内部网路∶


网路硬体的架构完成之后,最后只要设定 Client 端就好了,以本文为例,Client端可以使用的 ip 从 192.168.1.1~192.168.1.253,这么多的 ip 你可以好好规划,而每一部内部的电脑当然要把 Gateway 指向 192.168.1.254,此外 DNS 可以直接使用 ISP 公司所提供的,如 Hinet 所提供的 168.95.1.1 及 168.95.192.1,当然你也可以架设 DHCP Server 来自动帮所有的 Client 设定所有的 ip 资讯,设定完成后,就可以大家一起享受宽频上网罗!还蛮划算的呢!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10617731/viewspace-950127/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10617731/viewspace-950127/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值