|
|
最近由于单位业务上的需要,要求局域网内的一些指定工作站接入到外部的一个特定网络。
但对方只给了一个IP地址,并要求购买路由器以保证接入其指定网络。由于预算不足,决定
使用一台破旧PC建立一个网关服务器。
机器的配置为630T主板+1.1G的图拉丁+128M内存,版载显卡共享2M内存为显存,另加2块
网卡3com的3c905和D-link的530TX,一块旧硬盘。
网络环境大体如下:
eth0 (3c905) 内网IP:192.168.0.252 100baseTx-FD
eth1 (530TX) 外网IP:172.60.1.174 网关:172.60.1.173 掩码:255.255.255.252
外网光纤接入,由光模转换器转换后直接连网关服务器的eth1
起初使用了windows2000server,配置好IP地址后,使用路由和远程服务加了2条NAT的路由,
为了安全起见安装了norton的企业版杀毒软件,停止了绝大多数不必要的服务,这时候内网
用户把网关设为192.168.0.252后直接就能接入外部专用网络。
使用ping 172.60.1.173 -t -l 10240 命令测试后发现丢包严重,在30%左右,把530TX网卡
工作模式调整为10baseT-FD后,丢包现象消失,但发现网关服务器资源占用非常严重,直接
在该机上操作鼠标都有钝钝的感觉,看任务管理器显示发现物理内存已经使用近100M,虚拟
内存使用在50M左右。总体效果不理想,服务器的稳定问题让人担心。而且使用网络扫描软件
扫了一下网关服务器发现还是一大堆的端口开放,服务器的安全也不让人放心。
为了让老机继续发挥余热,为了建立一个安全稳定的网关服务器,安装了slackware10.2,没有
X之类的东东,只选择了一些基本的软件包,安装顺利完成,占用磁盘控件也就500M左右。
安装完毕后做了如下设定:
1、防止资源占用,没有开启hotplug,直接修改rc.modules,开启3c905和530TX两个网卡模块。
2、开启rc.modules脚本中的IP masquerading模块,无需使用rc.ip_forward脚本。
3、配置rc.inet1.conf设定eth0、eth1的IP和网关。
4、在rc.local加入mii-tool命令修正eth1的工作模式。
重新启动,OK,不到30分钟,一个稳定的网管服务器建立完毕。
客户机使用ping 172.60.1.173 -t -l 10240 测试数据收发稳定,运行top命令查看机器运行情况,
发现内存占用才90M多一点,swap根本没有用到,CPU空闲在98%左右。使用网络扫描软件扫描后只
发现一个22端口开放(为了方便管理开启了sshd)。
具体配置文件如下
rc.modules 只是简单修改一下原始文件即可
- /sbin/modprobe 3c59x
- /sbin/modprobe via-rhine
- # IP masquerading modules:
- # These modules are used with IP masquerading, a process which allows you to
- # use a Linux box connected to the Internet (via PPP or SLIP, or some other
- # means) as a gateway for other Linux, Windows, Macintosh boxes on your local
- # network that don't have real IP addresses on the Internet. The packets
- # going through the Linux machine are "masqueraded", or made to look as if
- # they're all coming from the one real IP address on the Internet.
- #
- # As a quick example (for a much more extensive treatment, see the IP-Masquerade
- # mini-HOWTO) to allow Internet access to a local network 192.168.11.0 with a
- # netmask of 255.255.255.0, you'd use these commands in /etc/rc.d/rc.local:
- #
- # # EXTERNAL -> external network interface
- # # INTERNAL -> internal network interface
- EXTERNAL=eth1
- INTERNAL=eth0
- echo 1 > /proc/sys/net/ipv4/ip_forward
- echo "Setting up NAT (Network Address Translation)..."
- # # by default, nothing is forwarded.
- iptables -P FORWARD DROP
- # # Allow all connections OUT and only related ones IN
- iptables -A FORWARD -i $EXTERNAL -o $INTERNAL -m state --state ESTABLISHED,RELATED -j
- ACCEPT
- iptables -A FORWARD -i $INTERNAL -o $EXTERNAL -j ACCEPT
- # # enable MASQUERADING
- iptables -t nat -A POSTROUTING -o $EXTERNAL -j MASQUERADE
复制代码
rc.local
- /sbin/mii-tool 10baseT-FD eth1
复制代码
rc.inet1.conf
- # Config information for eth0:
- IPADDR[0]="192.168.0.252"
- NETMASK[0]="255.255.255.0"
- USE_DHCP[0]=""
- DHCP_HOSTNAME[0]=""
- # Config information for eth1:
- IPADDR[1]="172.60.1.174"
- NETMASK[1]="255.255.255.252"
- USE_DHCP[1]=""
- DHCP_HOSTNAME[1]=""
- # Default gateway IP address:
- GATEWAY="172.60.1.173"
复制代码
为了保证内网的工作站安全,完全可以在rc.modules中加载包过滤等模块,也可以另写防火墙脚本。
这里只是简单实现一个NAT网关的功能。 |
|