找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 184631|回复: 269

[12/8更新]OpenWrt 上实现 NAT1 (Full cone NAT) 的方法,无需 DMZ/UPnP

 火... [复制链接]
本帖最后由 LGA1150 于 2019-1-4 20:22 编辑

源码及作者博客
https://github.com/Chion82/netfilter-full-cone-nat
https://blog.chionlab.moe/2018/02/09/full-cone-nat-with-linux/

编译:
更新:我已写好 Makefile,无需再对内核打补丁 https://github.com/LGA1150/openwrt-fullconenat
cd 到源码目录,把我的仓库 clone 进去
  1. git clone -b master --single-branch https://github.com/LGA1150/openwrt-fullconenat package/fullconenat
复制代码
然后 make menuconfig 选择 Network -> Firewall -> iptables-mod-fullconenat 就行了

使用:
我写了补丁修改了 firewall3 和 LuCI 里的选项 https://github.com/LGA1150/fullconenat-fw3-patch
  1. mkdir -p package/network/config/firewall/patches
  2. wget -O package/network/config/firewall/patches/fullconenat.patch https://github.com/LGA1150/fullconenat-fw3-patch/raw/master/fullconenat.patch
  3. wget -O- https://github.com/LGA1150/fullconenat-fw3-patch/raw/master/Makefile.patch | patch -p1
  4. pushd feeds/luci
  5. wget -O- https://github.com/LGA1150/fullconenat-fw3-patch/raw/master/luci.patch | patch -p1
  6. popd
复制代码


如果之前打过了补丁,要撤销更改后才能再次打新的补丁:
  1. rm -rf package/network/config/firewall
  2. git checkout package/network/config/firewall
  3. pushd feeds/luci
  4. rm -vf applications/luci-app-firewall/luasrc/model/cbi/firewall/*.{rej,orig}
  5. git checkout applications/luci-app-firewall/luasrc/model/cbi/firewall
  6. popd
复制代码


之后在网络-防火墙中可以选择 Full Cone

验证:使用“NAT类型检测工具”(自行搜索)测试,测试时要关闭 Windows 防火墙





本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

点评

你说的很对。: 5.0 我赞同你的说法。: 5.0
这是openwrt官方给的实现Full Cone Nat方案:如果要实现Full Cone Nat,只要在启动项中把firewall先disable,然后在close就可以了。不显示Full Cone Net原因是Windows防火墙没关。 This is openwrt's official impl   发表于 2019-2-20 04:40
你说的很对。: 5 我赞同你的说法。: 5
支持楼主加油加油  发表于 2018-6-8 11:45

评分

参与人数 17恩山币 +32 收起 理由
李*** + 1 感谢你的分享,无论怎样,你都是最无私的人!来,说说,你E盘上还有啥一起给我吧!
v77*** + 1 2333
Reddot*** + 1 感谢你的分享,无论怎样,你都是最无私的人!来,说说,你E盘上还有啥一起给我吧!
imy*** + 1 面对这种帖子,我内心复杂,真不知道说什么好……
ascc*** + 1 率全体恩山路由党以及党魁向你学习!
snake*** + 1 不要怂、就是干
papa*** + 1 率全体恩山路由党以及党魁向你学习!
zhl*** + 2 赢了会所嫩模,输了回家蒸馍
tin*** + 1 k2p无法编译能用的固件,只能在cc的成品上安装ipk,请问能通过安装ipk实现
梦里*** + 1 今天天气不错,适合泡妞。
etnpe*** + 1 我来恩山就是为了撩你!
v2*** + 1 强大的恩山!(以下重复1万次)
chen*** + 5 今天天气不错,适合泡妞。
ITd*** + 1 兄弟,你肥皂又掉了…你是故意掉的?
zsh*** + 5 强大的恩山!(以下重复1万次)
pro_*** + 3 我来恩山就是为了撩你!
safe*** + 5 谢谢楼主的知识普及, OFFLOAD及NAT类的专家!!!恩山需要更多你这样的营

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
支持一波        字数补丁
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

又见一高手!
谢谢分享!!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

来自手机 | 显示全部楼层
感谢,这么多动作和酸奶广告有没有影响
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

本帖最后由 hzdrro 于 2018-5-13 16:11 编辑

和shortcut-fe冲突


  1.   CC [M]  net/netfilter/xt_FULLCONENAT.o
  2. net/netfilter/xt_FULLCONENAT.c: In function 'xt_in':
  3. net/netfilter/xt_FULLCONENAT.c:39:13: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  4.    return par->in;
  5.           ~~~^~~~
  6. net/netfilter/xt_FULLCONENAT.c: In function 'xt_out':
  7. net/netfilter/xt_FULLCONENAT.c:43:13: warning: return discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  8.    return par->out;
  9.           ~~~^~~~~
  10. net/netfilter/xt_FULLCONENAT.c: In function 'fullconenat_tg_check':
  11. net/netfilter/xt_FULLCONENAT.c:617:22: error: invalid use of undefined type 'struct nf_ct_event_notifier'
  12.      ct_event_notifier.fcn = ct_event_cb;
  13.                       ^
  14. net/netfilter/xt_FULLCONENAT.c:619:50: error: passing argument 2 of 'nf_conntrack_register_notifier' from incompatible pointer type [-Werror=incompatible-pointer-types]
  15.      if (nf_conntrack_register_notifier(par->net, &ct_event_notifier) == 0) {
  16.                                                   ^
  17. In file included from ./include/net/netfilter/nf_conntrack_core.h:18:0,
  18.                  from net/netfilter/xt_FULLCONENAT.c:25:
  19. ./include/net/netfilter/nf_conntrack_ecache.h:74:12: note: expected 'struct notifier_block *' but argument is of type 'struct nf_ct_event_notifier *'
  20. extern int nf_conntrack_register_notifier(struct net *net, struct notifier_block *nb);
  21.             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. net/netfilter/xt_FULLCONENAT.c: In function 'fullconenat_tg_destroy':
  23. net/netfilter/xt_FULLCONENAT.c:643:50: error: passing argument 2 of 'nf_conntrack_unregister_notifier' from incompatible pointer type [-Werror=incompatible-pointer-types]
  24.        nf_conntrack_unregister_notifier(par->net, &ct_event_notifier);
  25.                                                   ^
  26. In file included from ./include/net/netfilter/nf_conntrack_core.h:18:0,
  27.                  from net/netfilter/xt_FULLCONENAT.c:25:
  28. ./include/net/netfilter/nf_conntrack_ecache.h:75:12: note: expected 'struct notifier_block *' but argument is of type 'struct nf_ct_event_notifier *'
  29. extern int nf_conntrack_unregister_notifier(struct net *net, struct notifier_block *nb);
  30.             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. net/netfilter/xt_FULLCONENAT.c: At top level:
  32. net/netfilter/xt_FULLCONENAT.c:81:29: error: storage size of 'ct_event_notifier' isn't known
  33. struct nf_ct_event_notifier ct_event_notifier;
  34.                              ^~~~~~~~~~~~~~~~~
  35. cc1: some warnings being treated as errors
  36. scripts/Makefile.build:299: recipe for target 'net/netfilter/xt_FULLCONENAT.o' failed
复制代码

点评

我把补丁修改了一下,试试这个补丁  详情 回复 发表于 2018-5-16 10:07
没看到冲突的地方,只是缺少了依赖 我编译的时候也遇到了这个问题,后来在 KCONFIG 加上 CONFIG_NF_CONNTRACK_EVENTS=y 就好了 你可以选上 kmod-nf-conntrack-netlink 后再编译  详情 回复 发表于 2018-5-13 16:28
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| | 显示全部楼层

没看到冲突的地方,只是缺少了依赖
我编译的时候也遇到了这个问题,后来在 KCONFIG 加上 CONFIG_NF_CONNTRACK_EVENTS=y 就好了
你可以选上 kmod-nf-conntrack-netlink 后再编译

点评

kmod-nf-conntrack-netlink是选上的,但是只要加入了shortcut-fe就会在nf_ct_event_notifier报错。  详情 回复 发表于 2018-5-13 17:18
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

本帖最后由 hzdrro 于 2018-5-13 17:53 编辑
LGA1150 发表于 2018-5-13 16:28
没看到冲突的地方,只是缺少了依赖
我编译的时候也遇到了这个问题,后来在 KCONFIG 加上 CONFIG_NF_CONN ...

kmod-nf-conntrack-netlink是选上的,但是只要加入了shortcut-fe fast-classifier就会在nf_ct_event_notifier报错。

明白了,
  1. 不过,CONNTRACK_EVENTS 并不是 netfilter 中常用的 feature。在内核树中,只有 netlink 的 conntrack 模块使用了它。
  2. 可能正由于此,conntrack notifier被设计成 在同一个network namespace中,同时只能有一个回调被注册 ,能够注册的唯一的事件回调会保存在 net->ct.nf_conntrack_event_cb 。因此这造成了 issue #5 的BUG:该模块不能与其他占用 CONNTRACK_EVENTS 的模块(标准内核树中只有netlink)同时共用。
复制代码
怪不得会冲突


我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

来自手机 | 显示全部楼层
很好,谢谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

可惜只支持udp,不支持tcp

点评

RFC3489 定义的 NAT 类型 也只是针对 UDP 的,TCP 还是用 UPnP 吧  详情 回复 发表于 2018-5-14 18:11
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 来自手机 | 显示全部楼层
ekenchan 发表于 2018-5-14 16:52
可惜只支持udp,不支持tcp

RFC3489 定义的 NAT 类型 也只是针对 UDP 的,TCP 还是用 UPnP 吧
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

Lede能适用嘛。

点评

一样的,字数补丁  详情 回复 发表于 2018-5-14 22:06
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| | 显示全部楼层

一样的,字数补丁

点评

再多问一句,我是x86的没关系吧  详情 回复 发表于 2018-5-15 01:06
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

LGA1150 发表于 2018-5-14 22:06
一样的,字数补丁

再多问一句,我是x86的没关系吧

点评

你是 Ubuntu 都没问题,理论上所有 Linux 发行版通用  详情 回复 发表于 2018-5-15 01:44
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 来自手机 | 显示全部楼层
隔壁小叔叔 发表于 2018-5-15 01:06
再多问一句,我是x86的没关系吧

你是 Ubuntu 都没问题,理论上所有 Linux 发行版通用
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

这个要支持,回去试试
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-27 10:19

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表