Duangw

home-gate

操作系统版本:Debian 5.0.0

 

1 硬件

配置3块网卡,分别映射到/dev/vmnet1、/dev/vmnet3、/dev/vmnet2。

 

2 初始安装

采用expert模式安装。

语言选择english。

设置eth0静态IP地址。

不使用网络镜像,不选择security和volatile更新。

只安装基本系统(不选择任何tasksel)。

建立普通用户。

 

3 配置网络

设置eth1和eth2网卡参数。

编辑/etc/network/interfaces:

...
allow-hotplug eth0 eth1 eth2
iface eth0 inet static
        address 10.10.10.1
        netmask 255.255.255.0
        network 10.10.10.0
        broadcast 10.10.10.255
        # dns-* options are implemented by the resolvconf package, if installed
        dns-search copyleft.net
iface eth1 inet static
        address 172.16.0.10
        netmask 255.255.255.0
        network 172.16.0.0
        broadcast 172.16.0.255
        gateway 172.16.0.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-search copyleft.net
iface eth2 inet static
        address 10.10.20.1
        netmask 255.255.255.0
        network 10.10.20.0
        broadcast 10.10.20.255
        # dns-* options are implemented by the resolvconf package, if installed
        dns-search copyleft.net

 

4 配置软件源

这里使用本地服务器上的镜像。

首先备份原来的配置文件:

$ cd /etc/apt
$ sudo cp sources.list sources.list-bak

编辑sources.list,添加:

...
deb ftp://10.10.10.199/pub/debian/ lenny main
deb-src ftp://10.10.10.199/pub/debian/ lenny main

deb ftp://10.10.10.199/pub/debian-security/ lenny/updates main contrib
deb-src ftp://10.10.10.199/pub/debian-security/ lenny/updates main contrib

 

5 更新系统

# aptitude update
# aptitude upgrade

 

6 安装openssh服务器

# aptitude install openssh-server

 

7 安装tcpdump

# aptitude install tcpdump

 

8 安装file

# aptitude install file

 

9 安装ftp客户端

# aptitude install ftp
# aptitude install lftp

 

10 配置iptables防火墙

这里使用Iptables脚本中提供的模板rc.iptables-gate-novpn.ref。

# cp rc.iptables-gate-novpn.ref /etc/init.d/iptables
# update-rc.d iptables start 38 S .
# cd /etc/init.d
# chmod 755 iptables

编辑/etc/init.d/iptables,去掉相关注释,使得:

其中DNAT只重定向http(s)和ftp:

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport http -j DNAT --to 10.10.20.20
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport https -j DNAT --to 10.10.20.20
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport ftp -j DNAT --to 10.10.20.20

 

11 配置ip6tables防火墙

同样使用Iptables脚本中提供的模板rc.ip6tables.ref。

# cp rc.ip6tables.ref /etc/init.d/ip6tables
# update-rc.d ip6tables start 38 S .
# cd /etc/init.d
# chmod 755 ip6tables

 

12 配置内核参数

编辑/etc/sysctl.conf,打开转发:

net.ipv4.ip_forward=1

 

13 配置bind域名服务

这里网关只作为一个forward服务器,本身不负责域名解析。

13.1 安装软件包

# aptitude install bind9
# aptitude install bind9-host

13.2 配置

编辑/etc/bind/named.conf.options,修改:

...
        forward only;
        forwarders {
                172.18.0.30;
        };
...

13.3 防火墙修改

编辑/etc/init.d/iptables,允许内网用户DNS查询:

# enalbe dns query in eth0
iptables -A in-IN -p udp --dport domain -m state --state NEW -j ACCEPT