Centos 7防火墙计谋配置指南
1.开启防火墙1. user切换到root用户
su root
密码:
# cd ~
#
2. 查看防火墙服务状态
systemcl status firewalld
3. 查看firewall的状态
systemctl firewall state 或 firewall-cmd --state
4. 启动/关闭防火墙
启动防火墙
systemctl start firewalld
重启防火墙
systemctl restart firewalld或systemctl reload firewalld
关闭
systemctl stop firewalld
设置开机自启动防火墙
systemctl enable firewalld.service
查看防火墙设置开机自启是否成功
systemctl is-enabled firewalld.service
2.防火墙端口配置
1. 查看已开启端口
firewall-cmd --list-ports 或 netstat -ntlp
2. 查看防火墙规则
firewall-cmd --list-all
3. 查看答应协议
firewall-cmd --list-protocals
4. 开启、关闭、查询端口
查询端口是否开放
firewall-cmd --query-port=80/tcp
命令规则:
--permanent:表示永久生效,若没有重启失效;
-- zone :表示作用域
--add-port=80/tcp 表示添加端口,格式为端口/通讯协议
开启端口的关键字:add
移除的关键字:remove
永久增加/开启80端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=998/tcp
firewall-cmd --add-port=999/tcp
重启防火墙服务
systemctl restart firewalld
删除端口
firewall-cmd --remove-port=999/tcp
3.防火墙ip指向限制配置
1. 答应指定ip访问所有流量
允许ip访问的关键字:accept
阻止ip访问的关键字:drop
开启192.168.43.88访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.43.100" accept"
重启防火墙服务
firewall-cmd --reload
禁止192.168.43.88访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.43.100" drop"
2. 答应指定ip访问指定端口
允许IPV4 Ip是8.8.8.8 连接端口80 accept表示允许使用
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="8.8.8.8" port protocol="tcp" port="80" accept"
允许IPV4 Ip是10.168.186.25 连接端口22 accept表示允许使用
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.25" port protocol="tcp" port="22" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.25,10.168.186.211" port protocol="tcp" port="3306" accept"
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.168.186.0/24" port protocol="tcp" port="22" accept"
以上运行完后提示success则表示配置成功
3. 答应指定ip访问指定协议
阻止ICMP包
firewall-cmd--permanent --add-rich-rule="rule protocol value="icmp" drop"
允许特定地址通过icmp
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="120.12.23.136" protocol value="icmp" accept"
4. 答应指定ip访问指定服务
firewall-cmd --remove-rich-rule="rule family="ipv4" source address="10.168.186.25" service name="ssh" drop"
从允许通过防火墙的列表里移除SSH服务
sudo firewall-cmd --remove-service=ssh --permanent
firewall-cmd --remove-rich-rule="rule protocol value="icmp" drop" --permanent
5. 防火墙移除某个服务
firewall-cmd --remove-rich-rule="rule family="ipv4" source address="10.168.186.25" service name="ssh" drop"
从允许通过防火墙的列表里移除SSH服务
sudo firewall-cmd --remove-service=ssh --permanent
firewall-cmd --remove-rich-rule="rule protocol value="icmp" drop" --permanent
6. 其他
重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
加入白名单
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="8.8.8.8" port protocol="tcp" port="80" accept"
查看规则
firewall-cmd --list-rich-rules
显示是
rule family="ipv4" source address="8.8.8.8" port port="80" protocol="tcp" accept
删除规则
firewall-cmd --permanent --remove-rich-rule="rule family="ipv4" source address="8.8.8.8" port port="80" protocol="tcp" accept"
注意端口添加,删除后要更新防火墙
firewall-cmd --reload
4.获取所有支持的服务
firewall-cmd --get-services
1. 增长、删除和服务
增加服务 (临时增加)
firewall-cmd --add-service=http
删除服务 (临时删除)
firewall-cmd --remove-service=http
查询服务
firewall-cmd --query-service=http
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]