linux_5.10 iptables踩坑

因为开发板要充当热点,要用iptables把wlan转发到eth上,结果发现没有iptables

1.直接从网站下了一个iptables
写BUILD.gn

import("//build/ohos.gni")

config("iptables_config") {
  cflags = [
    "-D_LARGEFILE_SOURCE=1",
    "-D_LARGE_FILES",
    "-D_FILE_OFFSET_BITS=64",
    "-D_REENTRANT",
    "-DENABLE_IPV4",
    "-DENABLE_IPV6",
    "-Wall",
    "-Wno-error",
    "-Wno-pointer-arith",
    "-Wno-sign-compare",
    "-Wno-unused-parameter",
    "-Wno-missing-field-initializers",
    "-Wno-parentheses-equality",
    "-DNO_SHARED_LIBS=1",
    "-DALL_INCLUSIVE",
    "-DXTABLES_INTERNAL",
  ]
}

ohos_executable("iptables") {
  sources = [
    "//third_party/iptables/iptables/ip6tables-standalone.c",
    "//third_party/iptables/iptables/ip6tables.c",
    "//third_party/iptables/iptables/iptables-restore.c",
    "//third_party/iptables/iptables/iptables-save.c",
    "//third_party/iptables/iptables/iptables-standalone.c",
    "//third_party/iptables/iptables/iptables-xml.c",
    "//third_party/iptables/iptables/iptables.c",
    "//third_party/iptables/iptables/xshared.c",
    "//third_party/iptables/iptables/xtables-legacy-multi.c",
  ]

  include_dirs = [
    "//third_party/iptables",
    "//third_party/iptables/extensions",
    "//third_party/iptables/include",
    "//third_party/iptables/iptables",
    "//third_party/iptables/libiptc",
  ]
  configs = [ ":iptables_config" ]

  install_enable = true

  deps = [
    "//third_party/iptables/extensions:libext",
    "//third_party/iptables/extensions:libext4",
    "//third_party/iptables/extensions:libext6",
    "//third_party/iptables/libiptc:libip4tc",
    "//third_party/iptables/libiptc:libip6tc",
    "//third_party/iptables/libxtables:libxtables",
  ]

  part_name = "netmanager_base"
  subsystem_name = "communication"
}

2.配置内核,按网站配置内核
[] Networking support —> [CONFIG_NET]
Networking Options —>
[
] Network packet filtering framework (Netfilter) —> [CONFIG_NETFILTER]
[] Advanced netfilter configuration [CONFIG_NETFILTER_ADVANCED]
Core Netfilter Configuration —>
<
/M> Netfilter connection tracking support [CONFIG_NF_CONNTRACK]
</M> Netfilter Xtables support (required for ip_tables) [CONFIG_NETFILTER_XTABLES]
<
/M> LOG target support [CONFIG_NETFILTER_XT_TARGET_LOG]
IP: Netfilter Configuration —>
<*/M> IP tables support (required for filtering/masq/NAT) [CONFIG_IP_NF_IPTABLES]

1.第一个问题

can’t initialize iptables table `nat’

在网上试了N种方法无效,突然想起来有没有可能内核没有配置
将CONFIG_NF_NAT改成Y
顺带这把iptables相关的全改了

后续解冲突,基本需要编译的文件都在ipv4文件夹下和netfilter文件夹下

2.第二个问题

nat问题解决完,又出现新的BUG
MASQUERADE Target not found

1.没道理,iptables所有东西我都加了,找了一份安卓的kernel看,发现有一个ipt_MASQUERADE.c的文件.
2.移过来,解不完的冲突,放弃.
3.检查了一下kernel的版本,发现一个是4.x,一个是5.x
4.在网上下了几份5.x的,发现都没有ipt_MASQUERADE.c,难道命令变化了
5.打开我自己的手机,kernel版本是linux_5.10,尝试把wifi转发到sim卡上去,iptables -t nat -A POSTROUTING -o ccmni0-j MASQUERADE,命令可用
6.既然iptables命令没有变化,肯定是能够支持的MASQUERADE.直接全局搜索
终于在在xt_MASQUERADE.c里找到了
在这里插入图片描述
7.最后找了份linux5.X的config,把ip和netfileter的配置copy下来了

cv大法好!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值