Code Monkey home page Code Monkey logo

iptablesutils's Introduction

利用iptables设置端口转发的shell脚本

项目作用

  1. 便捷地设置iptables流量转发规则
  2. 当域名解析的地址发生变化时,自动更新流量转发规则,不需要手动变更(适用于ddns域名)

用法

# 如果vps不能访问 raw.githubusercontent.com 推荐使用这个
bash <(curl -fsSL https://www.arloor.com/sh/iptablesUtils/natcfg.sh)

bash <(curl -fsSL https://raw.githubusercontent.com/arloor/iptablesUtils/master/natcfg.sh)

输出如下:

#############################################################
# Usage: setup iptables nat rules for domian/ip             #
# Website:  http://www.arloor.com/                          #
# Author: ARLOOR <[email protected]>                         #
# Github: https://github.com/arloor/iptablesUtils           #
#############################################################

你要做什么呢(请输入数字)?Ctrl+C 退出本脚本
1) 增加转发规则          3) 列出所有转发规则
2) 删除转发规则          4) 查看当前iptables配置
#?

此时按照需要,输入1-4中的任意数字,然后按照提示即可

卸载

wget --no-check-certificate -qO uninstall.sh https://raw.githubusercontent.com/arloor/iptablesUtils/master/dnat-uninstall.sh && bash uninstall.sh

查看日志

journalctl -exu dnat

配置文件备份和导入导出

配置文件在

/etc/dnat/conf

trojan转发

总是有人说,不能转发trojan,这么说的人大部分是证书配置不对。最简单的解决方案是:客户端选择不验证证书。复杂一点是自己把证书和中转机的域名搭配好。

小白记住一句话就好:客户端不验证证书。


推荐新项目——使用nftables实现nat转发

iptables的后继者nftables已经在debain和centos最新的操作系统中作为生产工具提供,nftables提供了很多新的特性,解决了iptables很多痛点。

因此创建了一个新的项目/arloor/nftables-nat-rust。该项目使用nftables作为nat转发实现,相比本项目具有如下优点:

  1. 支持端口段转发
  2. 转发规则使用配置文件,可以进行备份以及导入
  3. 更加现代

所以强烈推荐使用/arloor/nftables-nat-rust。不用担心,本项目依然可以正常稳定使用。

PS: 新旧两个项目并不兼容,切换到新项目时,请先卸载此项目

电报交流群

https://t.me/popstary

iptablesutils's People

Contributors

arloor avatar catboy96 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iptablesutils's Issues

规则失效的问题

通过DHCP/dhclient获取IP的机器,用这个iptables脚本设置好转发到DDNS的规则,转发生效可用。
当机器再次通过DHCP/dhclient获取了新IP之后,规则全部失效,需要通过此脚本删除已有的DDNS端口转发规则,重新设置新的DDNS端口转发规则,才能重新生效。

centos/debian/ubuntu都会存在此问题。

提示tls错误

您好,非常感谢您的贡献,让我们用上这个脚本。我在尝试中转V2的时候,普通tcp协议没有问题,正常使用;当准备使用脚本中转ws tls的时候(不中转正常使用),就中转失败了,客户端提示tls错误。不知道哪里出现问题了,前来问问大佬,谢谢!

关于iptables脚本,只需要udp转发

你好,我使用你的natcfg脚本,做ddns域名端口转发,但是我只需要udp转发,我把脚本里的tcp添加规则注释了,但是还是会添加tcp转发,请问还需要改那里,才能只做udp端口转发。

一个功能请求

现在的端口转发,输入域名,先把域名解析成IP,再转发的,能不能直接对域名转发,不解析IP?
或者哪一个转发方式可以实现直接对域名的转发,不解析IP的

Debian 11可能会缺少依赖

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye

添加任意需要解析域名后

journalctl -exu dnat

host: error while loading shared libraries: libdns-9.16.27-Debian.so: cannot open shared object file: No such file or directory
Warn:解析失败

解决方法参考:screetsec/TheFatRat#579

sudo apt-get update
sudo apt-get install host

iptables中转会导致SSR错误吗?

2020-03-30 11:25:21 ERROR tcprelay.py:1519 [Errno 104] Connection reset by peer
2020-03-30 11:25:21 ERROR tcprelay.py:1520 exception from ::ffff:103.56.xx.xx:56343
2020-03-30 11:25:50 ERROR tcprelay.py:1519 [Errno 104] Connection reset by peer
2020-03-30 11:25:50 ERROR tcprelay.py:1520 exception from ::ffff:103.56.xx.xx::56352
2020-03-30 11:26:02 ERROR tcprelay.py:1519 [Errno 104] Connection reset by peer
2020-03-30 11:26:02 ERROR tcprelay.py:1520 exception from ::ffff:103.56.xx.xx::56348
2020-03-30 11:26:20 ERROR tcprelay.py:1519 [Errno 104] Connection reset by peer
2020-03-30 11:26:20 ERROR tcprelay.py:1520 exception from ::ffff:103.56.xx.xx::56354
2020-03-30 11:44:08 ERROR tcprelay.py:1519 [Errno 104] Connection reset by peer

103.56.xx.xx为国内中转,用GOST转发的国外落地则没有这个错误。

本机动态探测

希望可以添加本机动态ip探测

如果中转机是动态ip 不会主动探测 需要重启natcfg 才可以重新转发

There is a bug in deleting rules.

'sort -r' may become the cause of a mis-delete of iptables rule.
like rule 10 is in front of rule 2.
i think 'sort -rn' is better.

关于DDNS域名防火墙规则消失的问题

vultr centos7 64位
安装了APPNODE面板
在面板里面安装了IPTABLES防火墙

情况1,
运行一键脚本之后,重启vps,防火墙规则消失

情况2,
运行一键脚本之后,在appnode面板,防火墙原文模式里面,改成编辑模式,什么也不改动,直接保存,重启vps之后,防火墙规则存在。但是,ddns更新之后,规则数量会翻倍。
意思是:转发一个端口,四个规则。会变成八个规则,成对的重复。

刚才支持一下。感谢您的贡献。

似乎动态转发跑久了会失效?

root@10-46-122-94:# journalctl -exu dnat8443
-- No entries --
root@10-46-122-94:
# systemctl status dnat8443
● dnat8443.service - 动态设置iptables转发规则
Loaded: loaded (/lib/systemd/system/dnat8443.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-09-12 16:50:20 CST; 3 days ago
Main PID: 17867 (bash)
Tasks: 2
Memory: 2.6M
CPU: 27.667s
CGroup: /system.slice/dnat8443.service
├─16465 sleep 120
└─17867 /bin/bash /usr/local/bin/dnat.sh 8443 8443 DDNS地址

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
相关log如上
systemctl restart dnat8443 后可恢复正常并且有正确的log出现
该问题目前仅在UCloud北京Ubuntu 18.04.2 LTS的两台机器上出现
其余机器暂没有发现这个现象

关于多网卡问题

想问下大佬,如果NAT是有3个网卡,对应联通电信移动三个出口,如何指定转发流量走特定的出口呢

Any possibility to find target server ip/info?

Server B, my target pc.
Server A, pulibc server

After installing this script on A, is there any possiblity to find ip/information about Server B?

Again, thank you for your contibution for this perfect script.

转发DDNS脚本不存在

本地端口号:10114
远程端口号:30007
目标域名:某个DDNS域名
脚本不存在,请通过github提交issue通知作者

本地多IP地址优化

您好,感谢您的脚本,非常好用,但是会有一个问题和您反馈:
在本地为多IP地址的情况下,(eg:多线NAT.每一个本地地址对应一个出口)dnat脚本会出错,导致错误。
希望可以增加一个手动填写本地地址的选项

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.