LINUX提供了强大的防火墙iptables ,但是由于iptables语法比较繁琐,所以不利于部署和维护,shorewall是第三方免费的防火墙生成器,相当于对iptables又进行了一次集合和优化。介绍一下简单的部署:
需要下载两个程序:
shorewall-perl-4.2.2.1.tgz #shorewall的安装环境
shorewall-common-4.2.2.1.tgz #shorewall的主程序
首先解压缩shorewall-perl-4.2.2.1.tgz
tar -zxvf shorewall-perl-4.2.2.1.tgz
cd shorewall-perl-4.2.2.1
./configure
make
make install
然后解压缩shorewall-common-4.2.2.1.tgz
tar -zxvf shorewall-common-4.2.2.1.tgz
cd shorewall-common-4.2.2.1
./configure
make
make install
shorewall 的基本配置文档是/etc/shorewall/shorewall.conf
将STARTUP_ENABLED=yes 设置为yes,启用shorewall
/etc/shorewall 下有很多配置文档,基本的为zones,interfaces,policy,masq等
zones为定义防火墙的区域,我个人认为类似CISCO防火墙的inside ,outside定义
vi /etc/shorewall/zones
# Shorewall version 4 - Zones File
#
# For information about this file, type "man shorewall-zones"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-zones.html[/url]
#
###############################################################################
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
fw firewall
in ipv4
out ipv4
#LAST LINE - ADD YOUR ENTRIES ABOVE THIS ONE - DO NOT REMOVE
#
# For information about this file, type "man shorewall-zones"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-zones.html[/url]
#
###############################################################################
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
fw firewall
in ipv4
out ipv4
#LAST LINE - ADD YOUR ENTRIES ABOVE THIS ONE - DO NOT REMOVE
我定义了in 和out 两个区域,注意fw为默认区域,是指linux 防火墙本身。
然后保存退出。
编辑interfaces
vi /etc/shorewall/interfaces
#
# Shorewall version 4 - Interfaces File
#
# For information about entries in this file, type "man shorewall-interfaces"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-interfaces.html[/url]
#
###############################################################################
#ZONE INTERFACE BROADCAST OPTIONS
in eth0
out eth1
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE
# Shorewall version 4 - Interfaces File
#
# For information about entries in this file, type "man shorewall-interfaces"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-interfaces.html[/url]
#
###############################################################################
#ZONE INTERFACE BROADCAST OPTIONS
in eth0
out eth1
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE
我将eth0 网卡端口划分进in区域,将eth1端口划分进out区域,注意在这里我的eth0网卡是内网卡,eth1网卡为外部网卡。
保存退出
然后定义策略policy
vi /etc/shorewall/policy
# Shorewall version 4 - Policy File
#
# For information about entries in this file, type "man shorewall-policy"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-policy.html[/url]
#
###############################################################################
#SOURCE DEST POLICY LOG LIMIT: CONNLIMIT:
# LEVEL BURST MASK
fw all ACCEPT
all fw ACCEPT
in out ACCEPT
out in DROP
#LAST LINE -- DO NOT REMOVE
#
# For information about entries in this file, type "man shorewall-policy"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-policy.html[/url]
#
###############################################################################
#SOURCE DEST POLICY LOG LIMIT: CONNLIMIT:
# LEVEL BURST MASK
fw all ACCEPT
all fw ACCEPT
in out ACCEPT
out in DROP
#LAST LINE -- DO NOT REMOVE
只要定义了区域,就要定义相关的策略,在这里从fw到任何区域和从任何区域到fw都是accept的,就是说从本机到任何端口或者任何端口到本机的流量都通过,这显然不安全,不错测试,没所谓。从in到out的流量是允许的,从out到in的流量是被拒绝的。然后保存推出。
定义nat,编辑masq文件
vi /etc/showrewall/masq
# Shorewall version 4 - Masq file
#
# For information about entries in this file, type "man shorewall-masq"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-masq.html[/url]
#
###############################################################################
#INTERFACE SOURCE ADDRESS PROTO PORT(S) IPSEC MARK
eth1 eth0
#LAST LINE -- ADD YOUR ENTRIES ABOVE THIS LINE -- DO NOT REMOVE
#
# For information about entries in this file, type "man shorewall-masq"
#
# The manpage is also online at
# [url]http://www.shorewall.net/manpages/shorewall-masq.html[/url]
#
###############################################################################
#INTERFACE SOURCE ADDRESS PROTO PORT(S) IPSEC MARK
eth1 eth0
#LAST LINE -- ADD YOUR ENTRIES ABOVE THIS LINE -- DO NOT REMOVE
定义从eth0 到eth1的nat,这样将会将eht0的网段nat到eth1
保存退出。
然后运行shorewall check 进行配置检查,如果有错误是无法通过的。
然后shorewall restart
注意一旦启用了shorewall则iptables已经启动,并且ipforward也已经启动。
转载于:https://blog.51cto.com/6509e/119513