natcfg.sh:利用iptables进行端口转发,支持域名、ddns、udp、IP等

natcfg.sh,基于iptables进行端口转发,特色是支持域名、ddns、udp、IP等,在NAT VPS不用设置内网IP,更简单。缺点是不支持端口段。

一、前提操作 非必需

1、卸载 firewalld 和 ufw

apt remove firewalld ufw

yum remove firewalld ufw

然后重启。

2、安装iptables

yum install -y iptables
yum update iptables 
yum install iptables-services

iptables配置文件:/etc/sysconfig/iptables

3、开启转发功能

echo -e "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p

4、设置一下iptable开机启动自动载入规则功能

CentOS 系统:

service iptables save
systemctl enable iptables.service

Debian/Ubuntu 系统:

iptables-save > /etc/iptables.up.rules
echo -e '#!/bin/bash\n/sbin/iptables-restore < /etc/iptables.up.rules' > /etc/network/if-pre-up.d/iptables
chmod +x /etc/network/if-pre-up.d/iptables

二、使用natcfg.sh进行转发

SSH下:

wget --no-check-certificate -qO natcfg.sh https://zhujiwiki.com/wp-content/uploads/2020/11/natcfg/natcfg.sh && bash natcfg.sh

需要继续设置时,执行

bash natcfg.sh

三、卸载natcfg.sh

wget --no-check-certificate -qO natcfg.sh https://zhujiwiki.com/wp-content/uploads/2020/11/natcfg/dnat-uninstall.sh && bash dnat-uninstall.sh

四、配置文件

/etc/dnat/conf

项目已开源:https://github.com/arloor/iptablesUtils

    所有主机信息仅是为及时分享并收录,不做推荐!
    专门搜集、分享国内高速、稳定的香港、日本、韩国、新加坡、美西CN2等优质线路的主机:FastVM