firewalld的基本使用
systemctl
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
配置firewalld-cmd
查看有哪些服务已经在列表中允许通过:
firewall-cmd --list-services
添加服务
firewall-cmd --permanent --add-service openvpn (--permanent永久生效,没有此参数重启后失效)
firewalld对指定IP开放指定端口的配置
允许192.168.142.166访问5432端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"
删除规则 firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"
重新加载配置文件
firewall-cmd --reload
firewalld 配置转发
firewall-cmd --zone=inernal --change-interface=eno2 firewall-cmd --zone=internal --change-interface=eno2 firewall-cmd --zone=public --add-forward-port=port=8040:proto=tcp:toport=8040:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8041:proto=tcp:toport=8041:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8042:proto=tcp:toport=8042:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8043:proto=tcp:toport=8043:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8044:proto=tcp:toport=8044:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8045:proto=tcp:toport=8045:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-masquerade --permanent firewall-cmd --zone=internal --add-masquerade --permanent firewall-cmd --reload firewall-cmd --list-all-zones
NET转发,firewalld实现内网访问外网
应用场景:机房服务器里一些没有外网IP的,通过跳板机上网。
服务端,使用firewalld防火墙实现nat路由转发
systemctl start firewalld.service #关闭其他防火墙,然后开启firewalld firewall-cmd --add-masquerade --permanent #内部主机依靠firewalld转发上网 firewall-cmd --reload #生效
客户端,修改网关为跳板机内网IP
vim /etc/sysconfig/network-scripts/ifcfg-em2 IPADDR=192.168.224.22 NETMASK=255.255.255.0 GATEWAY=192.168.224.9 DNS1=8.8.8.8 ZONE=internal # 重启网卡 ifdown em2 && ifup em2 # 测试 ping www.baidu.com
firewalld的基本使用
systemctl
systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
配置firewalld-cmd
查看有哪些服务已经在列表中允许通过:
firewall-cmd --list-services
添加服务
firewall-cmd --permanent --add-service openvpn (--permanent永久生效,没有此参数重启后失效)
firewalld对指定IP开放指定端口的配置
允许192.168.142.166访问5432端口 firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"
删除规则 firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="5432" accept"
重新加载配置文件
firewall-cmd --reload
firewalld 配置转发
firewall-cmd --zone=inernal --change-interface=eno2 firewall-cmd --zone=internal --change-interface=eno2 firewall-cmd --zone=public --add-forward-port=port=8040:proto=tcp:toport=8040:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8041:proto=tcp:toport=8041:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8042:proto=tcp:toport=8042:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8043:proto=tcp:toport=8043:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8044:proto=tcp:toport=8044:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-forward-port=port=8045:proto=tcp:toport=8045:toaddr=192.168.224.5 --permanent firewall-cmd --zone=public --add-masquerade --permanent firewall-cmd --zone=internal --add-masquerade --permanent firewall-cmd --reload firewall-cmd --list-all-zones
NET转发,firewalld实现内网访问外网
应用场景:机房服务器里一些没有外网IP的,通过跳板机上网。
服务端,使用firewalld防火墙实现nat路由转发
systemctl start firewalld.service #关闭其他防火墙,然后开启firewalld firewall-cmd --add-masquerade --permanent #内部主机依靠firewalld转发上网 firewall-cmd --reload #生效
客户端,修改网关为跳板机内网IP
vim /etc/sysconfig/network-scripts/ifcfg-em2 IPADDR=192.168.224.22 NETMASK=255.255.255.0 GATEWAY=192.168.224.9 DNS1=8.8.8.8 ZONE=internal # 重启网卡 ifdown em2 && ifup em2 # 测试 ping www.baidu.com