首页 > 系统相关 >iptables 杂谈ACCEPT和RETURN

iptables 杂谈ACCEPT和RETURN

时间:2023-11-28 14:59:26浏览次数:32  
标签:iptables RETURN 0.0 rule ACCEPT my

iptables 杂谈ACCEPT和RETURN

这两个目标,确实比较模糊。

目录

实验

这里是实验的情况:

  1. 新建两个iptables的规则链,并且相连,如果是ACCEPT:

    -N my_rule_1
    -N my_rule_2
    -A my_rule_1 -j ACCEPT
    -A my_rule_2 -j ACCEPT
    -A parental_ctrl_0 -j my_rule_1
    -A parental_ctrl_0 -j my_rule_2
    

    查看运行的数据:

    root@openwrt:/lib/parental_control# iptables -vnL my_rule_1; iptables -vnL my_rule_2
    Chain my_rule_1 (1 references)
     pkts bytes target     prot opt in     out     source               destination         
      377 66935 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           
        0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    Chain my_rule_2 (1 references)
     pkts bytes target     prot opt in     out     source               destination         
        0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           
        0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0
    

    可见,只有第一条链的数据包有增长,而后面的数据包不会增长。说明:ACCEPT后,并不会走后面的规则链,即跳过当前的链,在这里,起码从parental_ctrl_0跳走了,甚至可能是从FORWARD跳走了。

  2. 如果是RETURN:

    root@openwrt:/lib/parental_control# iptables -S |grep app
    -N my_rule_1
    -N my_rule_2
    -A my_rule_1 -j RETURN
    -A my_rule_2 -j RETURN
    -A parental_ctrl_0 -j my_rule_1
    -A parental_ctrl_0 -j my_rule_2
    

    再看看统计的情况:

    root@openwrt:/lib/parental_control# iptables -vnL my_rule_1; iptables -vnL my_rule_2
    Chain my_rule_1 (1 references)
     pkts bytes target     prot opt in     out     source               destination         
      280 60176 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    Chain my_rule_2 (1 references)
     pkts bytes target     prot opt in     out     source               destination         
      280 60176 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0
    

    可以看到,两条链的数据包是完全相同的。也就说明,RETURN会从当前的链返回,然后继续走后面的规则链,不会从hook点跳走。

结论

  1. ACCEPT,并不会走后面的规则链,即跳过当前的hook点
  2. RETURN,会从当前的链继续,走后面的规则链,不跳过hook点

标签:iptables,RETURN,0.0,rule,ACCEPT,my
From: https://www.cnblogs.com/adam-ma/p/17861944.html

相关文章

  • python函数return会结束整个函数的执行
    一:问题python函数中有for循环,对for循环进行return,函数会继续往下执行么? 二:回答不会。如下所示:defdemo3():print("a")foriinrange(3):print(i)returniprint("b")defdemo4():print("a")foriinran......
  • 第八章iptables防火墙
    安装iptables服务保存不上,可能没安装iptables服务yuminstalliptables-services.x86_64关闭防火墙systemctlstopfirewalldsystemctlmaskfirewalld2安装iptables服务yuminstalliptables-services3设置iptables服务开机启动systemctlenableiptables4重启iptab......
  • Docker启动失败,提示"iptables: No chain/target/match by that name"
    一、问题现象docker容器报错:docker:Errorresponsefromdaemon:driverfailedprogrammingexternalconnectivityonendpointetlmysql(12ccdbcef942bef6f32dbfc157dd1b49319ee2df4d68bf7b9a9b9ea88b5bd4fa):(iptablesfailed:iptables--wait-tnat-ADOCKER-ptc......
  • try catch 块 在catch块或者try块 return 掉 finally会执行吗?
    1.在catch块return掉finally会执行吗?答案:会代码:点击查看代码try{ints=1;Console.WriteLine(1);vara=5/(1-s);//除以0捕获异常}catch(Exception){Console.WriteLine(2);return;}finally{Console.WriteLine(3);}Co......
  • linux iptables初步理解
    引用:https://www.bilibili.com/video/BV1Jz4y1u7Lz/?spm_id_from=333.788&vd_source=e05f4a55dd5d8e27f74472aa7fd97ace1.iptables处理模型:linux内核有一个netfilter框架来设置这个防火墙linux可以像路由器一样做转发处理的,所以流量处理就有如下路径:iptables有四......
  • firewalld与iptables区别
    ComparisonofFirewalldtosystem-config-firewallandiptablesTheessentialdifferencebetweenfirewalldandiptablesserviceare:Theiptablesservicestoresconfigurationin/etc/sysconfig/iptableswhilefirewalldstoresitinvariousXMLfilesin/u......
  • C#中的yield return和yield break
      原文链接:https://blog.csdn.net/chenweicode/article/details/906653311.yieldreturn和yieldbreak通常在迭代器中使用,用yieldreturn来返回值,用yieldbreak来结束迭代器。(迭代器中不建议使用return和break)2.迭代器中的yieldbreak相当于普通方法中的return,直接终止方法......
  • centos:subprocess.CalledProcessError: Command ‘[‘ninja‘, ‘-v‘]‘ returned n
    一、原因pytorch版本大于1.5二、解决1、降低pytorch版本将pytorch版本降到1.5以下2、禁用ninjiapytorch默认使用ninjia作为backend,将其禁用。替换为以下代码setup(...,cmdclass={#'build_ext':BuildExtension,'build_ext':BuildExtension.w......
  • TortoiseGit拉取出现“Could not open repository. libgit2 returned: repository pat
    TortoiseGit拉取出现“Couldnotopenrepository.libgit2returned:repositorypath……”错误的解决办法1、......
  • for循环内部有return 如果先遇到return 是否就不再执行后面的程序了
    是的,一旦在for循环内部遇到return语句,函数将立即返回,并且后续的循环迭代以及循环内的其他代码将不再执行。return语句的作用是立即终止函数的执行并将结果返回给调用者。例如,考虑以下示例:defexample_function():foriinrange(5):print(i)ifi==2:......