Ubuntu Linux系統下設置shorewall防火牆

服務器採用Ubuntu做爲操做系統,兩塊網卡,一塊接外網(eth0),一塊接內網(eth1)。採用shorewall做爲防火牆。服務器

配置網卡:網絡

sudo vi /etc/network/interfacesapp

Ubuntu下設置shorewall防火牆tcp

服務器採用Ubuntu做爲操做系統,兩塊網卡,一塊接外網(eth0),一塊接內網(eth1)。採用shorewall做爲防火牆。ide

配置網卡:oop

sudo vi /etc/network/interfaces
------------------------------------------------
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).操作系統

# The loopback network interface
auto lo
iface lo inet loopback代理

# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
script grep
map eth0orm

# The primary network interface
iface eth0 inet static
address 192.168.2.250
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway 192.168.2.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 202.96.209.6server

auto eth1
iface eth1 inet static
address 192.168.10.254
netmask 255.255.255.0
network 192.168.10.0
broadcast 192.168.10.255

一、安裝shorewall

sudo apt-get install shorewall

二、拷貝配置文件

sudo cp /usr/share/shorewall/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 cp /usr/share/doc/shorewall/default-config/interfaces /etc/shorewall/interfaces

sudo cp /usr/share/doc/shorewall/default-config/rules /etc/shorewall/rules

sudo cp /usr/share/doc/shorewall/default-config/hosts /etc/shorewall/hosts

sudo cp /usr/share/doc/shorewall/default-config/masq /etc/shorewall/masq

三、配置網卡

sudo vi /etc/shorewall/interfaces

在倒數第二行,也就是在 「#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE」 這一行以後加上:

net eth0 detect

loc eth1 detect

四、配置網絡別名

sudo vi /etc/shorewall/zones

在倒數第二行,也就是在 「#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE」 這一行以後加上:

net Net Internet

loc Local Local Networks

五、配置IP假裝,也就是透明代理

sudo vi /etc/shorewall/masq

在倒數第二行,也就是在 「#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE」 這一行以後加上:

eth0 eth1

六、配置策略

sudo vi /etc/shorewall/policy

在#LAST LINE -- DO NOT REMOVE這一行最後加上:

loc net ACCEPT

net all DROP info

all all REJECT info

七、配置防火牆規則

sudo vi /etc/shorewall/rules

在倒數第二行,也就是在 「#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE」 這一行後加上:

#incoming traffic (由 internet 去 firewall)

AllowSSH net fw

AllowDNS net fw

AllowWeb net fw

AllowSMB net fw

AllowNNTP net fw

AllowNTP net fw

AllowRdate net fw

AllowSMTP net fw

DropPing net fw


#outgoing traffic (由 firewall 去 internet)

AllowWeb fw net

AllowDNS fw net

AllowSMTP fw net

AllowSMB fw net

AllowSMTP fw net

AllowNNTP fw net

AllowNTP fw net

AllowRdate fw net

AllowSSH fw net

#open special ports

ACCEPT net fw tcp 9980

八、修改 shorewall.conf 自動開啓 IP 轉發

sudo gedit /etc/shorewall/shorewall.conf

查找到:

IP_FORWARDING=Keep

修改成:

IP_FORWARDING=On

# 保存關閉文件

九、修改 /etc/default/shorewall 自動運行防火牆

sudo vi /etc/default/shorewall

查找到:

startup=0

修改成:

startup=1

十、啓動防火牆

sudo shorewall start

十一、至此防火牆配置完成。

文章如轉載,請註明轉載自【網管小王的獨立博客】:http://www.5iadmin.com/

相關文章
相關標籤/搜索