Ubuntu Linux系统下设置shorewall防火墙

服务器采用Ubuntu作为操作系统,两块网卡,一块接外网(eth0),一块接内网(eth1)。采用shorewall作为防火墙。

配置网卡:

sudo vi /etc/network/interfaces

Ubuntu下设置shorewall防火墙

服务器采用Ubuntu作为操作系统,两块网卡,一块接外网(eth0),一块接内网(eth1)。采用shorewall作为防火墙。

配置网卡:

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 eth0

# 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.6

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

1、安装shorewall

sudo apt-get install shorewall

2、拷贝配置文件

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

3、配置网卡

sudo vi /etc/shorewall/interfaces

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

net eth0 detect

loc eth1 detect

4、配置网络别名

sudo vi /etc/shorewall/zones

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

net Net Internet

loc Local Local Networks

5、配置IP伪装,也就是透明代理

sudo vi /etc/shorewall/masq

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

eth0 eth1

6、配置策略

sudo vi /etc/shorewall/policy

在#LAST LINE — DO NOT REMOVE这一行最后加上:

loc net ACCEPT

net all DROP info

all all REJECT info

7、配置防火墙规则

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

8、修改 shorewall.conf 自动开启 IP 转发

sudo gedit /etc/shorewall/shorewall.conf

查找到:

IP_FORWARDING=Keep

修改为:

IP_FORWARDING=On

# 保存关闭文件

9、修改 /etc/default/shorewall 自动运行防火墙

sudo vi /etc/default/shorewall

查找到:

startup=0

修改为:

startup=1

10、启动防火墙

sudo shorewall start

11、至此防火墙配置完成。

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/127452.html<

(0)
运维的头像运维
上一篇2025-02-24 16:41
下一篇 2025-02-24 16:42

相关推荐

  • AlphaNine美国怎么样?AlphaNine美国官网入口

    AlphaNine 美国作为 2026 年高性能计算与边缘 AI 领域的领军品牌,其核心优势在于通过自研异构计算架构实现了 40% 的能效比提升,是解决企业级数据延迟与算力瓶颈的首选方案,尤其在 2026 年中美科技博弈背景下,其合规性与本土化服务能力成为关键决策点,AlphaNine 美国技术架构与 2026……

    2026-05-02
    0
  • AviarHostVPS测评,实测体验,AviarHostVPS怎么样,AviarHostVPS好用吗

    AviarHostVPS 在 2026 年实测中展现出极高的性价比与网络稳定性,是中小型企业搭建海外业务及开发者进行轻量级应用部署的理想选择,尤其适合关注AviarHostVPS 价格与海外服务器免备案场景的用户,在云计算市场高度内卷的 2026 年,VPS 服务商的筛选标准已从单纯的“低价”转向“性能密度”与……

    2026-05-02
    0
  • hypervmart美国是什么?hypervmart美国官网入口

    2026 年 Hypervmart 美国站已全面接入 AI 智能选品与跨境物流自动化系统,成为中小卖家切入北美市场的首选低成本独立站解决方案,其核心优势在于“零库存 + 高转化”的闭环模式,随着 2026 年全球跨境电商进入“精细化运营”深水区,Hypervmart 美国站凭借其对北美消费者行为的深度洞察,在独……

    2026-05-02
    0
  • hypervmart是什么,hypervmart官网入口

    hypervmart 在 2026 年是否值得投资?核心结论:是,但需精准匹配供应链场景hypervmart 作为 2026 年跨境零售与 B2B 融合的新兴平台,其核心价值在于利用 AI 驱动的供应链优化技术,为中小卖家提供低于行业平均 15% 的履约成本,但成功与否高度依赖卖家对“跨境物流时效”与“海外仓选……

    2026-05-02
    0
  • RAKsmart独立服务器2026年测评,CN2 GIA实测数据与性能表现,CN2 GIA服务器到底怎么样,CN2 GIA独立服务器推荐

    RAKsmart 独立服务器在 2026 年已确立为连接中国内地与全球的高性能网络枢纽,其 CN2 GIA 线路实测延迟稳定在 35ms 以内,吞吐量突破 900Mbps,是跨境业务场景下兼顾稳定性与性价比的优选方案,核心网络性能深度解析2026 年 CN2 GIA 线路实测数据在 2026 年的网络架构中,R……

    2026-05-02
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注