LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1304|回复: 2

slackware作网关,代理家庭用户上网

[复制链接]
发表于 2005-5-25 10:58:41 | 显示全部楼层 |阅读模式
转载请注明            
作者:babo              
出处:www.slack.cn
因为这里的字体颜色不太好设置,我就没有再设置。
如果有兄弟要查看原文可以到下面链接看
原文出处

使用环境
现在ADSL比较普及了。有时候家里有多台机器要上网,但只有一条线路。我们该怎么办?其实如果你有多余的机器,完全可以装一个slackware负责代理全家上网。
下面是我家里的一个简单的结构示意图


由slackware网关这台机器负责全家的上网。我这台机器是用一台不用的P3 800做成的。
机器有两块网卡,一个连接ADSL,另一个连接集线器负责和家里其他机器连接。
家里的其它机器都将网关设置为slackware这台机器上网卡0的ip地址。
slackware这台机器设置为开机自动拨号,只要开机后就自动代理家里用户上网了。

作为网关机器的硬件要求
CPU:没有什么太多要求,有个奔腾100足够
硬盘:有4G足够
网卡:需要两块

安装slackware 10.1
参照文章:http://www.slack.cn/modules/wordpress/index.php?p=16

设置IP地址
首先在双网卡的这台机器上设置IP地址
直接修改/etc/rc.d/rc.inet1.conf就可以了。具体修改内容见下

  1. # /etc/rc.d/rc.inet1.conf
  2. #
  3. # This file contains the configuration settings for network interfaces.
  4. # If USE_DHCP[interface] is set to “yes”, this overrides any other settings.
  5. # If you don’t have an interface, leave the settings null ("").

  6. # Config information for eth0:
  7. IPADDR[0]="192.168.0.254″
  8. NETMASK[0]="255.255.255.0″
  9. USE_DHCP[0]="”
  10. DHCP_HOSTNAME[0]="”

  11. # Config information for eth1:
  12. IPADDR[1]="”
  13. NETMASK[1]="”
  14. USE_DHCP[1]="”
  15. DHCP_HOSTNAME[1]="”

  16. # Config information for eth2:
  17. IPADDR[2]="”
  18. NETMASK[2]="”
  19. USE_DHCP[2]="”
  20. DHCP_HOSTNAME[2]="”

  21. # Config information for eth3:
  22. IPADDR[3]="”
  23. NETMASK[3]="”
  24. USE_DHCP[3]="”
  25. DHCP_HOSTNAME[3]="”

  26. # Default gateway IP address:
  27. GATEWAY="192.168.0.254″
  28. 下面内容省略
复制代码

上面内容中用红色标出的内容为修改内容。
前两个红字标示的网卡eth0的ip和子网掩码
最后一个红字标示的是默认网关

设置ADSL拨号
用adsl-setup设置ADSL拨号

  1. Welcome to the Roaring Penguin ADSL client setup.  First, I will run
  2. some checks on your system to make sure the PPPoE client is installed
  3. properly…

  4. Looks good!  Now, please enter some information:

  5. USER NAME

  6. >>> Enter your PPPoE user name (default bxxxnxnx@sympatico.ca): adslusername

  7. INTERFACE

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

  12. Do you want the link to come up on demand, or stay up continuously?
  13. If you want it to come up on demand, enter the idle time in seconds
  14. after which the link should be dropped.  If you want the link to
  15. stay up permanently, enter ‘no’ (two letters, lower-case.)
  16. NOTE: Demand-activated links do not interact well with dynamic IP
  17. addresses.  You may have some problems with demand-activated links.
  18. >>> Enter the demand value (default no):输入回车

  19. DNS

  20. Please enter the IP address of your ISP’s primary DNS server.
  21. If your ISP claims that ‘the server will provide DNS addresses’,
  22. enter ’server’ (all lower-case) here.
  23. If you just press enter, I will assume you know what you are
  24. doing and not modify your DNS setup.
  25. >>> Enter the DNS information here: server

  26. PASSWORD

  27. >>> Please enter your PPPoE password:输入密码
  28. >>> Please re-enter your PPPoE password:输入密码

  29. FIREWALLING

  30. Please choose the firewall rules to use.  Note that these rules are
  31. very basic.  You are strongly encouraged to use a more sophisticated
  32. firewall setup; however, these will provide basic security.  If you
  33. are running any servers on your machine, you must choose ‘NONE’ and
  34. set up firewalling yourself.  Otherwise, the firewall rules will deny
  35. access to all standard servers like Web, e-mail, ftp, etc.  If you
  36. are using SSH, the rules will block outgoing SSH connections which
  37. allocate a privileged source port.

  38. The firewall choices are:
  39. 0 - NONE: This script will not set any firewall rules.  You are responsible
  40.           for ensuring the security of your machine.  You are STRONGLY
  41.           recommended to use some kind of firewall rules.
  42. 1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
  43. 2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
  44.                 for a LAN
  45. >>> Choose a type of firewall (0-2): 0

  46. ** Summary of what you entered **

  47. Ethernet Interface: eth1
  48. User name:          adslusername
  49. Activate-on-demand: No
  50. DNS addresses:      Supplied by ISP’s server
  51. Firewalling:        NONE

  52. >>> Accept these settings and adjust configuration files (y/n)? y
  53. Adjusting /etc/ppp/pppoe.conf
  54. Adjusting /etc/ppp/pap-secrets and /etc/ppp/chap-secrets
  55.   (But first backing it up to /etc/ppp/pap-secrets-bak)
  56.   (But first backing it up to /etc/ppp/chap-secrets-bak)

  57. Congratulations, it should be all set up!

  58. Type ‘adsl-start’ to bring up your ADSL link and ‘adsl-stop’ to bring
  59. it down.  Type ‘adsl-status’ to see the link status.
复制代码

上面内容用蓝色标出的,代表这里程序会停下来,等待你输入内容
红色标出的,代表这里是你要自己输入的内容

检测ADSL拨号设置,使用adsl-start命令拨号。如果返回…connect!代表成功。

设置开机自动拨号
在/etc/rc.d/rc.local里面添加如下内容


adsl-start
设置iptables
在/etc/rc.d/rc.local里面添加如下内容

  1. #设置nat转换
  2. iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

  3. #设置内网机器可以使用FTP
  4. modprobe ip_conntrack
  5. modprobe ip_conntrack_ftp
  6. modprobe ip_nat_ftp
复制代码

通过上面的设置后,只要重新起动机器就可以正常实现网关功能了

客户机设置
ip地址设置为和网关上eth0在一个网段就可以。例如192.168.0.1到192.168.0.253
子网掩码设置为255.255.255.0
网关设置为192.168.0.254

DNS设置为202.106.0.20。如果自己有合适的DNS也可以设置
发表于 2005-5-25 11:44:16 | 显示全部楼层
我一直以为iptable和ipchain只能作防火墙
原来也可作ip转发

可否介绍一下详细使用
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-25 12:14:05 | 显示全部楼层
我其实对iptables也是知道些皮毛而已。
iptables的功能还是很强大的,可以作nat和端口转发。
你可以看看iptables的手册。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表