论坛: UNIX系统 标题: LinuxADSL家庭组网实现详解 复制本贴地址    
作者: fair [fair]    论坛用户   登录
http://www.chinaunix.net 作者:天外闲云  发表于:2004-07-27 11:33:55

  家里的台式机,装有windows 2000 professional一直做server,本本使用linux做client,后来觉得本本上运行linux太慢,而且也不能在上面随随便便做实验,所以想要把台式机也装上linux,这样一来自然就涉及到了linux下adsl上网和组网的问题,经过几天的实验,总算是成功,因此把整个过程写下来,一来备案,而来希望能对网友们有点帮助。

[size=24:5ef37b98d0]1.概述[/size:5ef37b98d0]
机器配置:
主板芯片: Intel i815e 芯片组
    CPU: Intel Tulatin celeron 1.3G
    RAM: PC-133 SDRAM 256MB*2
    显卡: TNT2 model 64 32MB
          网卡: D-link DFX-530TX-Rev.c (自购,两机联机用)
Tenda FAST Ethernet 100Base-TX (装ADSL时电信配的)
    ADSL: 不知名,电信配
    做server的台式机和做client的本本都安装上了Fedora Core 1和Windows 2000 Professional。

[size=24:5ef37b98d0]
2.准备工作[/size:5ef37b98d0]
 
    主要是获得DNS,IP,MAC,软件和一些基本的准备工作。

[size=18:5ef37b98d0]2.1网络准备[/size:5ef37b98d0]
   
    最好先在server中windows下配置好局域网,使得client中linux能够通过windows server访问internet,同时也确定网卡和ADSL modem,省得做无用功;之所以要在client中使用linux来联结,一来可以为一会儿在linux下配置网卡熟悉一下,二来windows网卡配置很容易,linux下通了,把IP,GATEWAY等抄到windows下无需特别设置一般也通了。

    设置很简单在windows中将联结client机器的网卡设置好静态ip,子网掩码即可。然后在linux客户端中设置好网卡的静态ip和子网掩码,网关设为server中的静态ip,dns为server中的静态ip和你的isp提供的dns即可。
   
我的设置如下:
[code:1:5ef37b98d0]server:ip=210.31.34.2
netmask=255.255.240.0
client: ip=210.31.34.3
netmask=255.255.240.0
gateway=210.31.34.2
dns=210.31.34.2,isp's dns[/code:1:5ef37b98d0]
   
    然后在server上联上网,测试一下linux下是否能够浏览网络,一般来说上面的设置正确client就可以访问internet了,但是也有可能部分防火墙会导致client无法访问网络,可以关掉防火墙试试,如果确定是防火墙的问题,请自行查阅防火墙的相关资料。
    client能够访问internet之后,就可以把当前sever的IP设置记录下来,以备linux下使用,在windows console(开始->运行->cmd)中运行如下命令:

[code:1:5ef37b98d0]ipconfig /all >c:\ nic.txt[/code:1:5ef37b98d0]

    将产生的nic.txt文件拷贝到linux能够访问的分区中,以便将来在linux中查看。这一步的目的实际上是要记录下,server上两块网卡的IP和MAC,在linux下可能需要它们来确定哪块网卡是联结ADSL modem哪块网卡是联结client的(linux下网卡的名字和windows下可不一样,除非你对网卡硬件十分熟悉,否则千万不要略过这一步),当然还可以用这个方法查出你的ISP的DNS,前提是他提供的是静态DNS。

现在server中windows下的工作已经做完了,请将它重启到linux,client不用动他。

[size=18:5ef37b98d0]2.2需要的软件[/size:5ef37b98d0]
   
    * C 开发工具 (automake, autoconf, gcc, glibc...),Fedora Core 1下最简单的方法就是在软件管理包里面把开发栏下的开发工具全选上.
    * 内核源码,一般来说都会安装的,如果没有,请将Fedora Core 1的第三张盘放进光驱,用root执行如下命令:

[code:1:5ef37b98d0]rpm -ivh /mnt/cdrom/Fedora/RPMS/kernel-source-2.4.22-1.2115.nptl.i386.rpm[/code:1:5ef37b98d0]

    * pppoe客户端,可以在http://www.roaringpenguin.com/penguin/open_source_rp-pppoe.php网页下载到最新版.(如果你想说你不懂英语,那么在这里下载:http://www.roaringpenguin.com/penguin/pppoe/rp-pppoe-3.5.tar.gz)
    * 最新版的PPPD(ftp://cs.anu.edu.au/pub/software/ppp / ) ,一般来说应该是安装了的,如果没有,建议从上面下载,是tarball,需要自己编译安装。


[size=24:5ef37b98d0]3 网卡配置[/size:5ef37b98d0]
    先配置好局域网,然后再配置adsl使用的网卡。

[size=18:5ef37b98d0]3.1准备工作[/size:5ef37b98d0]
    首先得确定你的两块网卡在linux下的设备名,哪块是eth0,哪块是eth1,这时就要用到先前在windows下导出的nic.txt文件了,执行如下命令:
   
[code:1:5ef37b98d0]ifconfig[/code:1:5ef37b98d0]

    这时候会显示你的机器上的网络信息,比如:
[code:1:5ef37b98d0]eth0      Link encap:Ethernet  HWaddr 00:40:05:40:C5:57
          inet addr:210.31.34.2  Bcast:210.31.47.255  Mask:255.255.240.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:3075 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3759 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1244598 (1.1 Mb)  TX bytes:1009199 (985.5 Kb)
          Interrupt:12 Base address:0xc000[/code:1:5ef37b98d0]
   
    其中的HWaddr 00:40:05:40:C5:57就是设备eth0的MAC,将它和nic.txt中的MAC对比,就可以确定eth0,eth1分别接的是哪个网络。如果你的网卡没有设置为启动时激活,那么你可能需要运行如下命令:

[code:1:5ef37b98d0]ifup eth0
ifup eth1[/code:1:5ef37b98d0]

    来启动网卡,这个命令似乎是Redhat才有的,其他的发行版不知道怎么启动,还望各位告知。


    通过对比发现,我的eth0接的是局域网,eth1接的ADSL modem。

[size=18:5ef37b98d0]3.2局域网配置 [/size:5ef37b98d0]   
   
    现在配置eth0,执行如下命令

[code:1:5ef37b98d0]vi /etc/sysconfig/network-scripts/ifcfg-eth0[/code:1:5ef37b98d0]

    修改其BOOTPROTO为static,ONBOOT为yes;并配置好IPADDR,NETMASK,NETWORK,这些配置按照windows中的配置即可,也就是说把nic.txt中的相关数据抄过来就可以了。

    我的ifcfg-eth0如下:

[code:1:5ef37b98d0]# VIA Technologies|VT6105 [Rhine-III]
DEVICE=eth0
BOOTPROTO=static
BROADCAST=210.31.47.255
HWADDR=00:40:05:40:C5:57
IPADDR=210.31.34.2
NETMASK=255.255.240.0
NETWORK=210.31.32.0
ONBOOT=yes
TYPE=Ethernet[/code:1:5ef37b98d0]
    请根据自己的情况做相应修改。


[size=18:5ef37b98d0]3.3 eth1的配置[/size:5ef37b98d0]

    现在我们来配置eth1,根据rp-pppoe的说明档,eth1不能设置为启动时激活,不能给它分配IP。因此修改如下:

[code:1:5ef37b98d0]vi /etc/sysconfig/network-scripts/ifcfg-eth1[/code:1:5ef37b98d0]

    修改其中的BOOTPROTO为dhcp,ONBOOT=no

    我的ifcfg-eth1如下:

[code:1:5ef37b98d0]# Linksys|Network Everywhere Fast Ethernet 10/100 model NC100
DEVICE=eth1
BOOTPROTO=dhcp
HWADDR=00:00:E8:11:26:C5
ONBOOT=no
TYPE=Ethernet
DHCP_HOSTNAME=Cloud.Crop[/code:1:5ef37b98d0]
    你可以根据自己的情况做相应的修改。


[size=18:5ef37b98d0]3.4局域网连通测试[/size:5ef37b98d0]

    接下来,我们先测试一下局域网是否通了,在server和client上以root运行如下命令:

[code:1:5ef37b98d0]service network restart[/code:1:5ef37b98d0]

    之后,双机就应该可以互相ping通了,如果不行,请再仔细检查一下上面的设置,网络不通的原因很多,但是如果你已经按我说的在server windows,client linux的情况下组网成功,那么至少硬件没问题,软件原因导致的网络不通就不在本文讨论范围之内了。



[size=24:5ef37b98d0]4.开始安装[/size:5ef37b98d0]

首先要确定你的adsl modem可用,这就是为什么要先在windows下拨号上网,再进入linux的原因,要是你的设备原本就不能正常工作,你在linux下怎么弄,也上不了网的。

整个安装过程大概分为下面几步
1、配置内核
2、编译rp-pppoe客户端和pppd
3、配置pppd

[size=18:5ef37b98d0]4.1配置内核[/size:5ef37b98d0]

要想使用linux下的pppoe拨号服务,我们需要内核里有PPP支持。如果你已经在内核中配置了PPP,请跳过这一段,如果你不确定,可以使用如下命令查看

      [code:1:5ef37b98d0]grep CONFIG_PPP /usr/src/linux/.config[/code:1:5ef37b98d0]

如果在反馈的信息中有

CONFIG_PPP=y  或者 CONFIG_PPP=m

那么你的内核是支持PPP。否则的,你可能要编译一下内核了。

实际上,如果你使用的是比较新的发行版比如Redhat linux 9以上,那么内核应该是编译了PPP支持的。

NOTE:我觉得应该有更好的方法来检查是否有PPP支持,因为某些版本的linux可能不带.config文件,如果lsmod又看不见编译进内核的,不知道各位有什么好的方法?

[size=18:5ef37b98d0]4.2编译rp-pppoe客户端和pppd[/size:5ef37b98d0]

先安装pppd

[code:1:5ef37b98d0]tar -zxf ppp-2.4.1-15.tar.gz

cd ppp-2.4.1-15
./configure && make && make install[/code:1:5ef37b98d0]

NOTE:可能你的机器上已经安装了pppd,你可以用rpm -qa | grep ppp来查看是否有ppp-2.xxx-xx的信息。如果有就不用再安装了。

现在安装rp-pppoe客户端

[code:1:5ef37b98d0]tar -zxf rp-pppoe-3.5.tar.gz
cd rp-pppoe-3.5
./configure && make && make install[/code:1:5ef37b98d0]

NOTE:rp-pppoe客户端提供了快速安装的功能,./go这个是字符界面的,./go-gui这个是gui界面的,非常容易使用,不多说。

[size=18:5ef37b98d0]4.3配置rp-pppoe客户端[/size:5ef37b98d0]


配置方法分为手动和自动,强烈推荐使用自动配置的方式,即以root运行adsl-setup,如果无法连接再手动检查各个配置文件。

[code:1:5ef37b98d0]adsl-setup[/code:1:5ef37b98d0]

然后按着提示上的做就行了,这部分在本版精华已经讲得颇为详细了,本不想多说,但是总是有些人以自己“不懂英文“为名在下面JJYY,所以也在这里顺带提提。

[code:1:5ef37b98d0][root@Cloud root]# adsl-setup
 
Welcome to the ADSL client setup.  First, I will run some checks on
your system to make sure the PPPoE client is installed properly...
                                                                               
                                                                               
LOGIN NAME
                                                                               
Enter your Login Name (default root): 
输入你的ISP给你的帐号名
                                                                               
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 ethX, where 'X' is a number.
(default eth0): eth1
输入你的连接ADSL modem的网卡的设备名,我的是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):
通常来说用default no就可以了,一直在线,如果填yes,那么在你设置的闲置时间内没有网络数据传输,那么rp-pppoe会自动把连接断掉。国内大部分都是包月,所以这个功能应该用不上。                                                                               
DNS
 
Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic 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: 202.98.198.168
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: 202.98.192.68

填入你的ISP的静态DNS server,nic.txt中应该保存了,如果你的ISP提供的是动态DNS地址,就填入server(小写)。
 
PASSWORD
 
Please enter your Password:
Please re-enter your Password:

输入密码
 
USERCTRL
 
Please enter 'yes' (two letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes):

是否允许普通用户打开,关闭adsl连接。默认yes 
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): 2
选择防火墙,我选的2 

Start this connection at boot time
 
Do you want to start this connection at boot time?
Please enter no or yes (default no):
是否在启动的时候就拨号连接,默认no 
** Summary of what you entered **
 
Ethernet Interface: eth1
User name:          *****
Activate-on-demand: No
Primary DNS:        202.98.198.168
Secondary DNS:      202.98.192.68
Firewalling:        MASQUERADE
User Control:      yes
Accept these settings and adjust configuration files (y/n)? y
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/resolv.conf
  (But first backing it up to /etc/resolv.conf.bak)
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
  (But first backing it up to /etc/ppp/chap-secrets.bak)
  (But first backing it up to /etc/ppp/pap-secrets.bak)
 
这是你输入信息的一个摘要,如果要修改的话可以对adjusting字段后面的那些文件做修改,或者 
 
Congratulations, it should be all set up!
 
Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.

ifup ppp0 打开连接,ifdown ppp0关闭连接,adsl-status,查阅相关信息。
[/code:1:5ef37b98d0]
通常来说我们常用的是adsl-start,adsl-status,adsl-stop。

如果你的adsl不能连接上,请参看rp-pppoe解包后的根目录下的doc/HOW-TO-CONNECT,另外rp-pppoe的安装请看其根目录下的README

[size=18:5ef37b98d0]5 adsl连接共享设置[/size:5ef37b98d0]

    这一步,弄得我很头晕,因为自己的网络知识实在是有限得很,在网上搜的资料,一部分说要添加静态路由,一部分用squid,看了半天不明所以,后来在cu的一篇文章中找到了可用的方法,不保证其他的机器上能行。

    原文 http://bbs.chinaunix.net/forum/viewtopic.php?t=164907&highlight=linux
    我输入的命令是:

[code:1:5ef37b98d0]echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -F
/sbin/iptables -t nat -A POSTROUTING -s 210.31.34.0/28 -j MASQUERADE
/sbin/iptables -A FORWARD -s 210.31.34.0/28 -j ACCEPT[/code:1:5ef37b98d0]

    然后在客户机上不管是linux还是windows就可以访问internet了。

   



地主 发表时间: 04-08-07 23:19

回复: gsxl1021 [gsxl1021]   论坛用户   登录
这么麻烦?我就用squid,然后加了一条规则就OK了

B1层 发表时间: 04-08-08 09:24

回复: TecZm [teczm]   版主   登录
楼上说的是,地主不用这么复杂吧

B2层 发表时间: 04-08-08 14:09

论坛: UNIX系统

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号