Linux防火墙开启关闭查询
1.centos7防火墙
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
服务与端口的启用。
a)服务临时:firewall-cmd --zone=public --add-service=https
b)永久:firewall-cmd --permanent --zone=public --add-service=https
c)端口临时:firewall-cmd ?--zone=public --add-port=8080-8081/tcp
d)永久:firewall-cmd --permanent --zone=public --add-port=8080-8081/tcp
加入服务或端口需要重新启动防火墙。
systemctl restart firewalld.service
firewall-cmd --reload #重启firewall
#停止firewall
systemctl stop firewalld.service
查看修改后的防火墙是否生效。
firewall-cmd --zone=public --query-port=8080/tcp
或者
firewall-cmd --query-port=8080/tcp
查看已经开放的端口:
firewall-cmd --list-ports
2.CentOS 7 以下版本 iptables 命令
#加入端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9090 -j ACCEPT
如要开放80,22,8080 端口,输入以下命令即可
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
然后保存:
/etc/rc.d/init.d/iptables save
查看打开的端口:
/etc/init.d/iptables status
关闭防火墙
1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop
查看防火墙状态: service iptables status
3.ubuntu防火墙
启用
sudo ufw enable
sudo ufw default deny
#运行以上两条命令后,开启了防火墙,并在系统启动时自动开启。
#关闭所有外部对本机的访问,但本机访问外部正常。
开启/禁用
sudo ufw allow|deny [service]
打开或关闭某个端口,例如:
sudo ufw allow smtp #允许所有的外部IP访问本机的25/tcp (smtp)端口
sudo ufw allow 22/tcp #允许所有的外部IP访问本机的22/tcp (ssh)端口
sudo ufw allow 53 #允许外部访问53端口(tcp/udp)
sudo ufw allow from 192.168.1.100 #允许此IP访问所有的本机端口
sudo ufw allow proto udp 192.168.0.1 port 53 to 192.168.0.2 port 53
sudo ufw deny smtp #禁止外部访问smtp服务
sudo ufw delete allow smtp #删除上面建立的某条规则
查看防火墙状态
sudo ufw status
补充:
#开启/关闭防火墙 (默认设置是’disable’)
ufw enable|disable
#转换日志状态
ufw logging on|off
#设置默认策略 (比如 “mostly open” vs “mostly closed”)
ufw default allow|deny
#许可或者屏蔽某些入埠的包 (可以在“status” 中查看到服务列表[见后文])
#可以用“协议:端口”的方式指定一个存在于/etc/services中的服务名称,也可以通过包的meta-data。 ‘allow’ 参数将把条目加入 /etc/ufw/maps ,而 ‘deny’ 则相反。基本语法如下:
ufw allow|deny [service]
#显示防火墙和端口的侦听状态,参见 /var/lib/ufw/maps。括号中的数字将不会被显示出来。
ufw status
UFW使用范例:
#允许 53 端口
$ sudo ufw allow 53
#禁用 53 端口
$ sudo ufw delete allow 53
#允许 80 端口
$ sudo ufw allow 80/tcp
#禁用 80 端口
$ sudo ufw delete allow 80/tcp
#允许 smtp 端口
$ sudo ufw allow smtp
#删除 smtp 端口的许可
$ sudo ufw delete allow smtp
#允许某特定 IP
$ sudo ufw allow from 192.168.254.254
#删除上面的规则
$ sudo ufw delete allow from 192.168.254.254
Linux防火墙开启关闭查询的更多相关文章
- linux防火墙开启-关闭
1.永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2. 即时生效,重启后复原 开启: service iptab ...
- Linux下开启关闭防火墙
一.Linux下开启/关闭防火墙命令 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重 ...
- CentOs7 使用iptables防火墙开启关闭端口
CentOs7 使用iptables防火墙开启关闭端口 # 0x01介绍 iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分iptables文件设置路径:命令:v ...
- linux 防火墙开启80端口永久保存
经常使用CentOS的朋友,可能会遇到和我一样的问题.开启了防火墙导致80端口无法访问,刚开始学习centos的朋友可以参考下.经常使用CentOS的朋友,可能会遇到和我一样的问题.最近在Linux ...
- 一 SSH 无密码登陆 & Linux防火墙 & SELinux关闭
如果系统环境崩溃. 调用/usr/bin/vim /etc/profile SHH无密码登陆 所有要做得节点上运行 修改 host name vi /etc/sysconfig/netwo ...
- Linux防火墙的关闭和开启
1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...
- Linux防火墙的关闭和开启(转)
1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...
- Linux 防火墙开放、查询、关闭端口
1. 开放指定端口 firewall-cmd --zone=public --add-port=5121/tcp --permanent # --permanent 永久生效,如果不加此条,重启后该命 ...
- 【linux系列】linux防火墙的关闭开启
即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...
随机推荐
- sqlserver常用存储过程基本语法
一.定义变量--简单赋值 declare @a intset @a=5 print @a --使用select语句赋值 declare @user1 nvarchar(50) select @user ...
- java第十次笔记
- dockerfile编辑时常用的sed命令,用来修改配置文件。
sed 替换部分文件内容 随着使用,会逐步更新. #替换整行sed '/mengqingbo/c lanqiuxiaozi="FALSE"' fileName #匹配行前加sed ...
- vue 路由(1)
路由的使用 (5步) 1.首先安装路由 npm install vue-router2.引入 vue-router import VueRouter from 'vue-router' 3.使用 ...
- 26. Remove Duplicates from Sorted Array★
题目内容: Given a sorted array, remove the duplicates in place such that each element appear only once a ...
- Windows下PyMC安装
先安装Anaconda2 然后conda install -c https://conda.binstar.org/pymc pymc
- Android中的几个基本常用控件
Android 中常用的几大UI控件 1. TextView : 用于在界面中显示一段文本信息 <TextView android:id="@+id/text_view" / ...
- Android软键盘的隐藏显示、事件监听的代码
把开发过程中重要的一些内容片段做个珍藏,如下资料是关于Android软键盘的隐藏显示.事件监听的内容,应该是对小伙伴们有所用途. public class ResizeLayout extends L ...
- WordCount优化版测试小程序实现
Github地址:https://github.com/hcy6668/wordCountPro.git PSP表格: PSP PSP阶段 预估耗时(小时) 实际耗时(小时) Planning ...
- angular.js 渲染
angular.js 小常识 具体看代码,转载请备注来源. html结构 <%@ page language="java" contentType="text/ ...