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防火墙开启关闭查询的更多相关文章

  1. linux防火墙开启-关闭

    1.永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off 2. 即时生效,重启后复原 开启: service iptab ...

  2. Linux下开启关闭防火墙

    一.Linux下开启/关闭防火墙命令 1) 永久性生效,重启后不会复原 开启: chkconfig iptables on 关闭: chkconfig iptables off   2) 即时生效,重 ...

  3. CentOs7 使用iptables防火墙开启关闭端口

    CentOs7 使用iptables防火墙开启关闭端口   # 0x01介绍 iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分iptables文件设置路径:命令:v ...

  4. linux 防火墙开启80端口永久保存

    经常使用CentOS的朋友,可能会遇到和我一样的问题.开启了防火墙导致80端口无法访问,刚开始学习centos的朋友可以参考下.经常使用CentOS的朋友,可能会遇到和我一样的问题.最近在Linux ...

  5. 一 SSH 无密码登陆 & Linux防火墙 & SELinux关闭

    如果系统环境崩溃.   调用/usr/bin/vim /etc/profile   SHH无密码登陆 所有要做得节点上运行   修改 host name vi /etc/sysconfig/netwo ...

  6. Linux防火墙的关闭和开启

    1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...

  7. Linux防火墙的关闭和开启(转)

    1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...

  8. Linux 防火墙开放、查询、关闭端口

    1. 开放指定端口 firewall-cmd --zone=public --add-port=5121/tcp --permanent # --permanent 永久生效,如果不加此条,重启后该命 ...

  9. 【linux系列】linux防火墙的关闭开启

    即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...

随机推荐

  1. prerender-spa-plugin Vue预渲染配合meta-info优化seo

    记录一下解决方案的过程 先安装prerender和puppeteer插件  这个国外大神写的  github地址就不附上了(百度有) cnpm install prerender-spa-plugin ...

  2. javaScript简单的留言板

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  3. 详细介绍Ubuntu 16.04系统环境安装Docker CE容器的过程

    由于项目的需要,我们在很多软件配置环境中需要用到Docker容器,这个时候我们可以用自己的VPS主机搭建.在这篇文章中,笔者将会利用Ubuntu 16.04系统环境安装Docker CE容器的过程.如 ...

  4. Eclipse远程调试+FTPClient在jdk6以上写法不兼容问题的排查

    业务场景: 应业务新需求的UAT测试,需要部署一份新tomcat到测试环境.新环境正常启动并运行了一天,没太大差错.但今天发现原本在另一个老的tomcat下运行的好好的FTP上传文件模块突然出了问题. ...

  5. Unity资源内存管理--webstream控制

    一 使用前提 1,需要使用资源热更新 2,使用Assetbundle资源热更(AssetBundle是产生webstream的元凶) 二 为什么要用AssetBundle AssetBundle本质上 ...

  6. JDBC原理

    JDBC原理   JDBC是什么: Java Database Connectivity:Java访问数据库的解决方案 JDBC是Java应用程序访问数据库的里程碑式解决方案.Java研发者希望用相同 ...

  7. Tensorflow实战系列之五:

    打算写实例分割的实战,类似mask-rcnn. Tensorflow实战先写五个系列吧,后面新的技术再添加~~

  8. Type curtilage home

    This year's National Day coincides with the Mid-Autumn festival, the double false merger about eight ...

  9. for ,foreach ,map 循环的区别

    一.for循环 1.for - 循环代码块一定的次数 遍历数组最常用到的for循环,是最为熟知的一种方法 for (var i=0; i<5; i++) { x=x + "The nu ...

  10. Vue语法学习第四课(2)——class与style的绑定

    之前学到的指令 v-bind 在用于绑定class和style时,表达式结果可以是字符串.数组.对象. 一.绑定HTMLClass ① 对象语法 <div class="static& ...