yum install net-tools
netstat -tanulp|grep rinetd
1.首先看看当前firewalld的状态,至少得先启动吧,查看命令如下:
systemctl status firewalld
2.如果没启动firewalld那就启动吧
systemctl start firewalld
3.启动之后需要查看一个masquerade状态,查询命令如下:
firewall-cmd --query-masquerade
4.假如查到结果为no那么就启动它
firewall-cmd --add-masquerade
5.现在准备工作好了,假如我们要把当前DMZ区的a端口映射为内网xxx.xxx.xxx.xxx:b这个地址上,首先防火墙打开a端口
firewall-cmd --zone=public --add-port=a/tcp --permanent (大家看清楚,里面的a替换为所需要对外的端口)
6.接下来就是映射
firewall-cmd --permanent --zone=public --add-forward-port=port=a:proto=tcp:toaddr=xxx.xxx.xxx.xxx:toport=b
7.需要生效就得重新加载
firewall-cmd --reload
8.重新加载之后,步骤4再执行一次,因为重新加载步骤4就还原了(加--permanent是永久)
9.查看一下结果
firewall-cmd --zone=public --list-all
10.如无意外映射成功需要删除的话如下:
firewall-cmd --permanent --zone=public --remove-forward-port=port=a:proto=tcp:toaddr=xxx.xxx.xxx.xxx:toport=b
————————————————
版权声明:本文为CSDN博主「路边草随风」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:
https://blog.csdn.net/luohualiushui1/article/details/86583239
一、Firewalld简介
Filewalld(动态防火墙)是redhat7系统中变更对于netfilter内核模块的管理工具,支持动态更新技术并加入了区域(zone)的概念,区域就是firewalld预先准备了几套防火墙策略集合(策略模板),用户可以根据生产场景的不同而选择合适的策略集合,从而实现防火墙策略之间的快速切换。
二、firewalld与iptables的切换
yum install iptables-services.x86_64 -y ##安装iptables服务
systemctl stop firewalld.service ##关火墙
systemctl disable firewalld.service ##开机不自启
systemctl mask firewalld.service ##屏蔽firewalld服务
systemctl start iptables.service ##打开iptables服务
systemctl enable iptables.service ##开机自启
iptables -nL ##查看iptables策略
systemctl unmask firewalld.service ##解除屏蔽firewalld服务
1
2
3
4
5
6
7
8
9
三、firewalld策略修改
域的管理
firewall-cmd --get-zones ##查看有哪些域
firewall-cmd --get-default-zone ##查看默认域
firewall-cmd --list-a ##查看当前域详细信息
firewall-cmd --zone=public --list-all ##查看指定域详细信息
firewall-cmd --set-default-zone=trusted ##设定默认域为trusted
firewall-cmd --get-active-zones
1
2
3
4
5
6
权限管理
firewall-config ##图形修改火墙
firewall-cmd --zone=trusted --add-source=172.25.254.5 ##使指定来源拥有在指定域的权限
firewall-cmd --zone=trusted --remove-source=172.25.254.5 ##移除指定来源
firewall-cmd --get-services ##查看防火墙管理的服务
firewall-cmd --add-service=http ##添加http服务
firewall-cmd --remove-service=http ##移除http服务
firewall-cmd --add-masquerade ##伪装ip
firewall-cmd --reload ##重新加载火墙(对已经通过火墙的用户无效)
firewall-cmd --complete-reload ##完全重新加载火墙(影响已经通过火墙的用户)
--permanent ##永久
1
2
3
4
5
6
7
8
9
10
网卡增减
firewall-cmd --zone=public --remove-interface=eth0 ##从指定域移除指定网卡
firewall-cmd --zone=trusted --add-interface=eth0 ##添加网卡到指定域
1
2
端口增减
firewall-cmd --zone=public --add-port=666/tcp ##添加指定域端口
firewall-cmd --zone=public --remove-port=666/tcp ##删除端口
1
2
四、陆游功能
路由器(多网卡端)
两个ip:分别为
1.1.1.105
172.25.254.105
firewall-cmd --permanent --add-masquerade ##伪装ip
firewall-cmd --reload ##重新加载火墙
sysctl -a | grep forward ##查看内核是否允许陆游功能
(要求 net.ipv4.ip_forward = 1)
vim /etc/sysctl.conf ##陆游功能文件(net.ipv4.ip_forward = 0时编辑)
net.ipv4.ip_forward = 1 ##在文件最后写入
sysctl -p ##重新读取陆游功能文件
1
2
3
4
5
6
7
客户端
ip:1.1.1.205
vim /etc/sysconfig/network
GATEWAY=1.1.1.105 ##设置网关为路由器的同网段的ip
1
2
通过路由器(服务端)连接172.25.254.网段的主机
ping 172.25.254.5
1
陆游地址转换
firewall-cmd --permanent --zone=public --add-forward-port=port=22:proto=tcp:toport=22:toaddr=1.1.1.205
##其他主机连接22端口时自动转到主机1.1.1.205上
1
2
————————————————
版权声明:本文为CSDN博主「小白运维之路」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44297303/article/details/88031236