全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 875|回复: 7

基于nftables的明文转发脚本

[复制链接]
发表于 2021-12-15 23:15:12 | 显示全部楼层 |阅读模式
本帖最后由 h202 于 2021-12-15 23:18 编辑

转载请注明源链接
明文转发非隧道 至于什么是nftables请google
详情参见 https://github.com/arloor/nftables-nat-rust
使用python创建nftables转发规则 可端口段转发 可转发域名
debian10没问题 其他系统自测
转发使用systemd运行 更换服务器也很方便 (nat.conf上传到新服务器然后restart就好)
重启之后转发也在 (这点很重要)
我将 nat.conf 从/etc 下转到了 /root 下 (找起来方便)

  1. #!/usr/bin/env bash
  2. apt-get update -y
  3. apt-get install python3 nftables dnsutils -y
  4. echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
  5. sysctl -p
  6. wget https://cdn.jsdelivr.net/gh/arloor/nftables-nat-rust@master/nat.py -O /usr/local/bin/nat.py
  7. cat > /etc/systemd/system/nat.service <<EOF
  8. [Unit]
  9. Description=dnat-service
  10. After=network-online.target
  11. Wants=network-online.target

  12. [Service]
  13. WorkingDirectory=/
  14. ExecStart=/usr/bin/python3 /usr/local/bin/nat.py /root/nat.conf
  15. LimitNOFILE=100000
  16. Restart=always
  17. RestartSec=60

  18. [Install]
  19. WantedBy=multi-user.target
  20. EOF
  21. systemctl daemon-reload
  22. systemctl enable nat
  23. systemctl start nftables
  24. systemctl enable nftables
  25. cat > /root/nat.conf <<EOF
  26. SINGLE,49999,59999,baidu.com
  27. EOF
  28. systemctl start nat
复制代码
发表于 2021-12-15 23:17:28 | 显示全部楼层
iptables坚定不移yyds
发表于 2021-12-15 23:16:55 来自手机 | 显示全部楼层
这个好东西,试试看看
发表于 2021-12-15 23:17:37 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2021-12-15 23:17:58 | 显示全部楼层
hcyme 发表于 2021-12-15 23:16
这个好东西,试试看看

我自己用的生产工具
 楼主| 发表于 2021-12-15 23:19:05 | 显示全部楼层
HOH 发表于 2021-12-15 23:17
iptables坚定不移yyds

重启就掉转发
 楼主| 发表于 2021-12-15 23:22:35 | 显示全部楼层
Mr.Qin 发表于 2021-12-15 23:17
流下了没有技术的泪水,

所以你为什么不自己努力当技术佬
发表于 2021-12-15 23:25:11 | 显示全部楼层
好东西,回头试下。

我一直只会用haproxy来实现类似的转发,主要能直接修改配置文件,外加单端口复用sni分流/故障轮询/负载均衡。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-4-17 07:52 , Processed in 0.065271 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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