linux-ubuntu关闭防火墙

SYNOPSIS
       iptables [-t table] {-A|-C|-D} chain rule-specification
       ip6tables [-t table] {-A|-C|-D} chain rule-specification
       iptables [-t table] -I chain [rulenum] rule-specification
       iptables [-t table] -R chain rulenum rule-specification
       iptables [-t table] -D chain rulenum

        iptables 是linux下一款强大的防火墙,在不考虑效率的情况下,功能强大到足能够替代大多数硬件防火墙。可是强大的防火墙假设应用不当,可能挡住的可不光是那些潜在的攻击,还有可能是你自己哦。

这个带来的危害对于普通的个人PC来说可能无关紧要。可是想象一下,假设这是一台server,一旦发生这种情况。不光是影院正常的服务。还须要到现场去恢复。这会给你带来多少损失呢?

所以我想说的是,当你敲入每个iptables 相关命令的时候都要万分小心。

    1.应用每个规则到DROP target时,都要细致检查规则。应用之前要考虑他给你带来的影响。

    2.在redhat中我们能够使用service iptables stop来关闭防火墙,可是在有些版本号如ubuntu中这个命令却不起作用,大家可能在网上搜索到不少文章告诉你用iptables -F这个命令来关闭防火墙,可是使用这个命令前。千万记得用iptables -L查看一下你的系统中全部链的默认target。iptables -F这个命令仅仅是清除全部规则。仅仅不会真正关闭iptables.想象一下,假设你的链默认target是DROP,本来你有规则来同意一些特定的port,但一旦应用iptables -L 。清除了全部规则以后。默认的target就会阻止不论什么訪问。当然包含远程ssh管理server的你。

 

所以我建议的关闭防火墙命令是

    iptables -P INPUT ACCEPT
    iptables -P FORWARD ACCEPT
    iptables -P OUTPUT ACCEPT
    iptables -F

    

     总之,当你要在你的server上做不论什么变更时,最好有一个測试环境做过充分的測试再应用到你的server。

除此之外。要用好iptables,那就要理解iptables的执行原理,知道对于每个数据包iptables是怎么样来处理的。这样才干准确地书写规则,避免带来不必要的麻烦。

       iptables [-t table] -S [chain [rulenum]]
       iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]
       iptables [-t table] -N chain
       iptables [-t table] -X [chain]
       iptables [-t table] -P chain target
       iptables [-t table] -E old-chain-name new-chain-name
       rule-specification = [matches...] [target]
       match = -m matchname [per-match-options]
       target = -j targetname [per-target-options]


屏蔽ICMP ping请求

我们能够通过同意以下的命令屏蔽ping请求:

 
  
  1. # iptables -A INPUT -p icmp --icmp-type echo-request -j DROP  
  2. # iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP 

也能够依照特定的网段和主机限制ping请求:

 
  
  1. # iptables -A INPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-request -j ACCEPT 

下面命令仅仅接受受限制的ping请求:

 
  
  1. #假定默认INPUT策略为丢弃数据包  
  2. # iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT  
  3. # iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT  
  4. # iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT  
  5. #全部的server都对ping请求作出应答  
  6. # iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT 

 

屏蔽或开启常见port

屏蔽或开启经常使用的TCP、UDPport:

 
  
  1. #能够使用DROP替换ACCEPT。实现端口屏蔽。

     
  2. #打开22端口(SSH)  
  3. # iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  4. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT  
  5. #打开TCP/UDP631端口(打印服务)  
  6. # iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 631 -j ACCEPT  
  7. # iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 631 -j ACCEPT  
  8. # 打开123端口,同意局域网用户进行NTP时间同步  
  9. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -j ACCEPT  
  10. #打开25端口(SMTP)  
  11. # iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT  
  12. # 打开DNS端口  
  13. # iptables -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT  
  14. # iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT  
  15. #打开http/https端口  
  16. # iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT  
  17. # iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT  
  18. #打开TCP110端口(POP3)  
  19. # iptables -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT  
  20. #打开TCP143端口  
  21. # iptables -A INPUT -m state --state NEW -p tcp --dport 143 -j ACCEPT  
  22. #为局域网用户开启Samba訪问  
  23. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 137 -j ACCEPT  
  24. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 138 -j ACCEPT  
  25. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT  
  26. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT  
  27. #为局域网用户开启代理server訪问  
  28. # iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 3128 -j ACCEPT  
  29. #为局域网用户开启MySQL訪问  
  30. # iptables -I INPUT -p tcp --dport 3306 -j ACCEPT 

 

版权声明:本文博主原创文章。博客,未经同意不得转载。

转载于:https://www.cnblogs.com/mengfanrong/p/4855326.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值