大家好,欢迎再次光临,我是你们的朋友全栈君。
CentOS7的防火墙配置与之前的版本有显著差异,CentOS7默认采用的是firewall,而CentOS 6.x则使用iptables。
一、iptables防火墙1、基本操作
# 查看防火墙状态service iptables status
# 停止防火墙service iptables stop
# 启动防火墙service iptables start
# 重启防火墙service iptables restart
# 永久关闭防火墙chkconfig iptables off
# 永久关闭后重启chkconfig iptables on
2、开启80端口vim /etc/sysconfig/iptables # 添加以下代码-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT保存并退出后,重启防火墙service iptables restart
二、firewall防火墙1、查看firewall服务状态systemctl status firewalld
如果显示Active: active (running)并高亮,则表示已启动状态。如果显示Active: inactive (dead)且为灰色,表示已停止状态,也可通过单词判断。
2、查看firewall的状态firewall-cmd –state
3、开启、重启、关闭firewalld.service服务# 开启service firewalld start
# 重启service firewalld restart
# 关闭service firewalld stop
4、查看防火墙规则firewall-cmd –list-all
5、查询、开放、关闭端口# 查询端口是否开放firewall-cmd –query-port=8080/tcp
# 开放80端口firewall-cmd –permanent –add-port=80/tcp
# 移除端口firewall-cmd –permanent –remove-port=8080/tcp
# 重启防火墙(修改配置后需要重启防火墙)firewall-cmd –reload
# 参数解释1、firwall-cmd:是Linux提供的操作firewall的工具;2、–permanent:表示设置为持久;3、–add-port:表示添加的端口;
CentOS7默认使用firewalld防火墙,如果想换回iptables防火墙,可以关闭firewalld并安装iptables。
1、关闭firewall:停止firewall systemctl stop firewalld.service禁止firewall开机启动 systemctl disable firewalld.service查看默认防火墙状态(关闭后显示notrunning,开启后显示running)firewall-cmd --state
2.安装iptables-servicesyum install iptables-services
3.修改防火墙配置文件vi /etc/sysconfig/iptables
默认的文件为:
![linux防火墙查看状态firewall、iptable[通俗易懂]](https://www.chuangxiangniao.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
在修改之前使用telnet命令查看端口是否开放。
1.启动telnet。控制面板–>程序和功能–>打开或关闭windows功能–>勾选Telnet的两个选项。2.打开cmd窗口,输入telnet,如果端口关闭或者无法连接,则显示不能打开到主机的链接,链接失败;端口打开的情况下,链接成功,则进入telnet页面(全黑的),证明端口可用。
(1)telnet IP 端口。(2)telnet 域名 端口。
![linux防火墙查看状态firewall、iptable[通俗易懂]](https://www.chuangxiangniao.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
![linux防火墙查看状态firewall、iptable[通俗易懂]](https://www.chuangxiangniao.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
如果成功连接会进入的界面
![linux防火墙查看状态firewall、iptable[通俗易懂]](https://www.chuangxiangniao.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
连接失败
添加端口80、8080、3306、3690端口:
![linux防火墙查看状态firewall、iptable[通俗易懂]](https://www.chuangxiangniao.com/wp-content/themes/justnews/themer/assets/images/lazy.png)
esc :wq! 退出保存修改。
4.重启防火墙使配置生效systemctl restart iptables.service
刚刚yum install iptables.service之后系统如果没有重启,iptables.service是找不到的,会报unit not found。耽误时间的小坑!
设置防火墙开机启动:systemctl enable iptables.service
发布者:全栈程序员栈长,转载请注明出处:https://www.php.cn/link/6e4150c261d1fa9881f7f90ea71f0f23
以上就是linux防火墙查看状态firewall、iptable[通俗易懂]的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/32928.html
微信扫一扫
支付宝扫一扫