个人工具

ShoreWall安装设置

来自Ubuntu中文

跳转至: 导航, 搜索

这里我们采用 shorewall 作为服务器的专业防火墙,这也是 Ubuntu 推荐的防火墙。

本服务器有一块网卡通过交换机和ADSL相连接,同时交换机上连接其它电脑。 如果有两块网卡,其中一块接ADSL,请修改 eth0 为 你接交换机的网卡,例如 eth1。

  • 安装防火墙
sudo apt-get install shorewall
  • 复制配置文件
sudo cp /usr/share/doc/shorewall/default-config/modules /etc/shorewall/
sudo cp /usr/share/doc/shorewall/default-config/policy /etc/shorewall/
sudo cp /usr/share/doc/shorewall/default-config/nat /etc/shorewall/
sudo cp /usr/share/doc/shorewall/default-config/zones /etc/shorewall/
sudo cp /usr/share/doc/shorewall/default-config/maclist /etc/shorewall/
sudo cp /usr/share/doc/shorewall/default-config/blacklist /etc/shorewall/
sudo gunzip -c /usr/share/doc/shorewall/default-config/interfaces.gz > /etc/shorewall/interfaces
sudo gunzip -c /usr/share/doc/shorewall/default-config/rules.gz > /etc/shorewall/rules
sudo gunzip -c /usr/share/doc/shorewall/default-config/hosts.gz > /etc/shorewall/hosts
sudo gunzip -c /usr/share/doc/shorewall/default-config/masq.gz > /etc/shorewall/masq
  • 配置网卡

假设:你的网卡是 eth0 ,通过 ppp0 上 Internet.

sudo gedit /etc/shorewall/interfaces

在倒数第二行,也就是在 “#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE” 这一行之前添加:

net    ppp0        detect        dhcp,routefilter,norfc1918,tcpflags
loc    eth0        detect        tcpflags
  • 配置网络别名
sudo gedit /etc/shorewall/zones

在倒数第二行,也就是在 “#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE” 这一行之前添加:

net	Net		Internet
loc	Local		Local Networks
  • 配置IP伪装,也就是透明代理
sudo gedit /etc/shorewall/masq

在倒数第二行,也就是在 “#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE” 这一行之前添加:

ppp0			eth0
  • 配置防火墙规则
sudo gedit /etc/shorewall/rules

在倒数第二行,也就是在 “#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE” 这一行之前添加:

#
#	允许 DNS 从 防火墙 连接到 Internet
#
AllowDNS	fw		net
#
#	允许本地网络可以使用 SSH 来管理服务器
#
AllowSSH	loc		fw
#
#	允许 Ping 到防火墙和允许防火墙 Ping 其它网络
#
AllowPing	loc		fw
AllowPing	net		fw
AllowPing	fw		loc
AllowPing	fw		net
#
#	允许 Internet 访问防火墙上的 WEB 服务
#
AllowWeb	net		fw
#
#	允许 Internet 访问防火墙上的 FTP 服务
#
AllowFTP	net		fw
#
#	允许 Internet 访问防火墙上的 邮件 服务
#
AllowSMTP       net		fw
AllowIMAP       net		fw
#
#	允许本地网络可以访问 Internet
#
AllowWeb	loc		net
#
#	允许本地网络可以收发邮件
#
AllowSMTP	loc		net
AllowIMAP	loc		net
AllowPOP3	loc		net
#
#	允许本地网络使用 FTP 到 Internet
#
AllowFTP	loc		net
#
#	允许本地网络从 Internet 查询 DNS 
#
AllowDNS	loc		net
#
#	允许本地网络使用 MSN
#
ACCEPT          loc     	net     tcp     1863
ACCEPT          loc     	net     tcp     443
ACCEPT          loc     	net:gateway.messenger.hotmail.com all
#
#	将WEB访问重新定向到 3128 ,通过squid完成访问 ,访问服务器地址 192.168.0.1 除外。
#
#REDIRECT        loc     3128    tcp     www     - 	!192.168.0.1
  • 修改 shorewall.conf 自动开启 IP 转发
sudo gedit /etc/shorewall/shorewall.conf

查找到:

IP_FORWARDING=Keep

修改为:

IP_FORWARDING=On
  • 保存关闭文件
  • 修改 /etc/default/shorewall 自动运行防火墙
sudo gedit /etc/default/shorewall

查找到:

startup=0

修改为:

startup=1
  • 启动防火墙
sudo shorewall start
  • 至此防火墙配置完成。