[ 永远的UNIX::UNIX技术资料的宝库 ]

首页 > 应用专题 > Proxy > 正文

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

作者:babo slack.cn (2005-06-03 11:20:08)

 

使用环境
现在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就可以了。具体修改内容见下

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

# Config information for eth0:
IPADDR[0]="192.168.0.254″
NETMASK[0]="255.255.255.0″
USE_DHCP[0]="”
DHCP_HOSTNAME[0]="”

# Config information for eth1:
IPADDR[1]="”
NETMASK[1]="”
USE_DHCP[1]="”
DHCP_HOSTNAME[1]="”

# Config information for eth2:
IPADDR[2]="”
NETMASK[2]="”
USE_DHCP[2]="”
DHCP_HOSTNAME[2]="”

# Config information for eth3:
IPADDR[3]="”
NETMASK[3]="”
USE_DHCP[3]="”
DHCP_HOSTNAME[3]="”

# Default gateway IP address:
GATEWAY="192.168.0.254″
下面内容省略

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

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

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@sympatico.ca): adslusername

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 eth0): 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):输入回车

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

PASSWORD

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

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

** Summary of what you entered **

Ethernet Interface: eth1
User name:          adslusername
Activate-on-demand: No
DNS addresses:      Supplied by ISP’s server
Firewalling:        NONE

>>> Accept these settings and adjust configuration files (y/n)? y
Adjusting /etc/ppp/pppoe.conf
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拨号设置,使用adsl-start命令拨号。如果返回…connect!代表成功。

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

adsl-start
设置iptables
在/etc/rc.d/rc.local里面添加如下内容
#设置nat转换
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

#设置内网机器可以使用FTP
modprobe ip_conntrack
modprobe ip_conntrack_ftp
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也可以设置


(http://www.fanqiang.com)

原文链接:http://www.slack.cn/modules/wordpress/index.php?p=18

 相关文章
如何在Linux下配置socks5代理 2001-04-21 17:47:50
如何在Linux中设置透明代理 2001-04-21 18:31:22
IMP 与 Proxy Server 代理伺服主机 2001-06-07 10:08:00
用Squid实现代理上网及计费 2002-01-31 09:17:57
Socks5代理服务器配置 2005-03-25 11:22:35
Linux下Socks5代理的安装与配置 2005-04-06 14:36:38

★  感谢所有的作者为我们学习技术知识提供了一条捷径  ★
www.fanqiang.com