• Linux 上关于iptables


    有几个命令:
    1、service iptables staus
     
    2、service iptables start 
     
    3、service iptables restart
     
    有个配置文件/ect/sysconfig/iptables
     
     
    执行第一条命令的时候发现没有任何反应,到/ect/sysconfig/目录下也没有iptables这个文件,应该是iptables没有安装,那么通过yum命令来安装
    1 yum install -t iptables
     
    安装成功之后执行第二个命令,报下面的错误:
    1 [root@iZ28fg6zc2zZ ~]# service iptables start
    2 iptables: No config file.                                  [WARNING]
    错误信息是对应的iptables没有对应的配置文件,应该是yum安装的时候文件没有生成。
    解决办法:
     1 [root@iZ28fg6zc2zZ ~]# iptables -F 
     2 
     3 [root@iZ28fg6zc2zZ ~]# service iptables save
     4 iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
     5 
     6 [root@iZ28fg6zc2zZ ~]# service iptables restart
     7 iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
     8 iptables: Flushing firewall rules:                         [  OK  ]
     9 iptables: Unloading modules:                               [  OK  ]
    10 iptables: Applying firewall rules:                         [  OK  ]
    11 [root@iZ28fg6zc2zZ ~]#
    执行上面的步骤之后,/ect/sysconfig/目录下就有iptables这个配置文件了,剩下的就可以正常操作了。
     
     
    开放端口,一些命令,讲解的很细致,感谢作者。
     
    就我自己添加的顺序看下面的例子:
     1 1.  iptables -A OUTPUT -p tcp -m tcp --sport 6379 -j ACCEPT 
     2      添加6379这个端口
     3 
     4   2.  /etc/init.d/iptables save
     5      
     6   3.  cat /etc/sysconfig/iptables
     7      看你添加的端口存在不
     8   4.  service iptables restart
     9      存在,执行这个命令
    10 
    11      看博主的解释:
    12 - 只修改/etc/sysconfig/iptables 使其生效的办法是修改好后先service iptables restart,然后才调用/etc/rc.d/init.d/iptables save,
    13 - 因为/etc/rc.d/init.d/iptables save会在iptables服务启动时重新加载,要是在重启之前直接先调用了/etc/rc.d/init.d/iptables save那么你
    14 - 的/etc/sysconfig/iptables 配置就回滚到上次启动服务的配置了,这点必须注意!!!

     参考资料:http://www.linuxidc.com/Linux/2012-03/56066.htm

    下面粘出博主的/ect/sysconfig/iptables的配置

     1 - /etc/sysconfig/iptables文件配置如下:
     2 - # Generated by iptables-save v1.4.7 on Fri Mar  2 19:59:43 2012
     3 - *filter
     4 - :INPUT DROP [0:0]
     5 - :FORWARD DROP [0:0]
     6 - :OUTPUT DROP [8:496]
     7 - -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
     8 - #ping使用的端口
     9 - -A INPUT -p icmp -j ACCEPT
    10 - -A INPUT -i lo -j ACCEPT
    11 - -A INPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT
    12 - -A INPUT -s 192.168.2.200/32 -d 192.168.2.200/32 -j ACCEPT
    13 - #允许服务器自己的SSH(对外部请求来说服务器是目标所以使用--dport)
    14 - -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
    15 - #80端口不用说了吧,服务器网站访问端口
    16 - -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    17 - -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
    18 - -A INPUT -p tcp -m tcp --dport 11211 -j ACCEPT
    19 - -A INPUT -p tcp -m tcp --dport 11212 -j ACCEPT
    20 - -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    21 - #53端口是DNS相关,TCP和UDP都要配置
    22 - -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
    23 - -A INPUT -p udp -m udp --dport 53 -j ACCEPT
    24 - #ping使用的端口
    25 - -A OUTPUT -p icmp -j ACCEPT
    26 - -A OUTPUT -s 127.0.0.1/32 -d 127.0.0.1/32 -j ACCEPT
    27 - -A OUTPUT -s 192.168.2.200/32 -d 192.168.2.200/32 -j ACCEPT
    28 - #允许服务器SSH到其他机器(使用外部端口就使用--dport)
    29 - -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT
    30 - #允许服务器自己的SSH(自已为源输出就使用--sport)
    31 - -A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT
    32 - #访问外部网站80端口(使用外部端口就使用--dport)
    33 - -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT
    34 - #如果服务器需要访问外部网站,那么OUTPUT也需要配置53端口(使用外部端口就使用--dport)
    35 - -A OUTPUT -p tcp -m tcp --dport 53 -j ACCEPT
    36 - -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT
    37 - #如果有访问外部邮箱,那么打开邮箱相关端口(使用外部端口就使用--dport)
    38 - -A OUTPUT -p tcp -m tcp --dport 465 -j ACCEPT
    39 - -A OUTPUT -p tcp -m tcp --dport 25 -j ACCEPT
    40 - -A OUTPUT -p tcp -m tcp --dport 110 -j ACCEPT
    41 - #服务器网站访问端口(自已为源输出就使用--sport)
    42 - -A OUTPUT -p tcp -m tcp --sport 80 -j ACCEPT
    43 - -A OUTPUT -p tcp -m tcp --sport 3306 -j ACCEPT
    44 - -A OUTPUT -p tcp -m tcp --sport 11211 -j ACCEPT
    45 - -A OUTPUT -p tcp -m tcp --sport 11212 -j ACCEPT
    46 - COMMIT
    47 - # Completed on Fri Mar  2 19:59:43 2012

     以上都是16年有段时间安装过程所做的记录,最近整理笔记整理出来,先放这里吧!如有错误请各位指正!谢谢

  • 相关阅读:
    Debugging Auto Layout:Ambiguous Layouts
    Debugging Auto Layout:Unsatisfiable Layouts
    Debugging Auto Layout
    Auto Layout Cookbook:Views with Intrinsic Content Size
    编译地址与运行地址
    Memory Controller
    ARM寄存器
    C++指针悬挂(赋值运算符重载)
    多态性,友元与静态成员 基础知识小结
    ARM 汇编指令集
  • 原文地址:https://www.cnblogs.com/yangh965/p/6774139.html
Copyright © 2020-2023  润新知