zoukankan      html  css  js  c++  java
  • linux开放关闭防火墙端口

    原文:http://blog.csdn.net/fengspg/article/details/21337617

    1) 重启后生效 
    开启: chkconfig iptables on
    关闭: chkconfig iptables off

    2) 即时生效,重启后失效
    开启: service iptables start
    关闭: service iptables stop


    查看iptables文件

        vim /etc/sysconfig/iptables   

    redhat部分-----------

    1:端口开放

    /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT  

    2:保存修改

    /etc/rc.d/init.d/iptables save  

    3: 重启服务

    /etc/rc.d/init.d/iptables restart 

    4:查看端口状态

    /etc/init.d/iptables status  

    结果如下

    Chain INPUT (policy ACCEPT)
    num target prot opt source destination
    1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:2181
    2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:6379
    3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080
    4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
    5 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
    6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
    7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
    8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

    Chain FORWARD (policy ACCEPT)
    num target prot opt source destination
    1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited

    Chain OUTPUT (policy ACCEPT)
    num target prot opt source destination

    5:删除端口(2表示上面的num列)

    1. /sbin/iptables  -D INPUT 2  

    centos7部分-----------

    开启端口

    1. firewall-cmd --zone=public --add-port=80/tcp --permanent  

    --zone #作用域
    --add-port=80/tcp  #添加端口,格式为:端口/通讯协议
    --permanent   #永久生效,没有此参数重启后失效

    重新加载防火墙

    1. firewall-cmd --reload  

    检查修改是否生效

    1. firewall-cmd --zone= public --query-port=80/tcp  

    删除某端口

      firewall-cmd --zone= public --remove-port=80/tcp   

      firewall-cmd --zone=public --remove-service=http  

  • 相关阅读:
    An Introduction to C & GUI Programming -----Simon Long 学习笔记 6
    An Introduction to C & GUI Programming -----Simon Long 学习笔记 5
    An Introduction to C & GUI Programming -----Simon Long 学习笔记 4
    An Introduction to C & GUI Programming -----Simon Long 学习笔记 3
    An Introduction to C & GUI Programming -----Simon Long 学习笔记 2
    替罪羊树 (Scapegoat Tree)
    Miller-Rabin 质数检测
    杜教筛
    狄利克雷卷积&莫比乌斯反演
    取整函数的性质
  • 原文地址:https://www.cnblogs.com/shihaiming/p/5937640.html
Copyright © 2011-2022 走看看