一个用于 Linux 服务器的 SNAT / NAT / 端口放行管理脚本。
支持:
- SNAT 配置
- VPN 出口转发
- 端口放行
- IPv4 转发
- nftables / iptables
- firewalld / ufw
- 自动持久化
- 多 Linux 发行版
适用于:
- 飞将VPN
- OpenVPN
- WireGuard
- IPsec
- SoftEther
- Docker 网络
- VPS 出口转发
- VPN 服务器部署
- 多网卡 NAT 转发
支持:
- Debian
- Ubuntu
- CentOS
- RHEL
- Rocky Linux
- AlmaLinux
- Fedora
- Arch Linux
- Alpine Linux
以及大部分衍生发行版。
支持:
- iptables
- nftables
- firewalld
- ufw
自动识别并适配当前系统。
自动开启:
net.ipv4.ip_forward=1无需手动修改。
适用于:
- tun0
- wg0
- ppp0
- ipsec
- docker
- 任意自定义接口
自动完成:
- FORWARD
- MASQUERADE
- SNAT
- 端口放行
系统重启后规则自动恢复。
支持:
| 后端 | 持久化 |
|---|---|
| iptables | iptables-save |
| nftables | nft ruleset |
| firewalld | permanent |
| ufw | rules 文件 |
- Debian
- Ubuntu
- Kali Linux
- Linux Mint
- Proxmox VE
- Deepin
- Pop!_OS
- Armbian
- CentOS
- Rocky Linux
- AlmaLinux
- Fedora
- Oracle Linux
- TencentOS
- OpenCloudOS
- Alpine Linux
- Arch Linux
- Manjaro
- systemd
- OpenRC
支持任意 Linux 网卡:
eth0
ens18
ens192
enp1s0
wlan0
tun0
wg0
ppp0
docker0
wget -O snat.sh https://raw.githubusercontent.com/yangpin97/snat/refs/heads/main/snat.sh或者:
curl -o snat.sh https://pan.yydy.link:2023/d/share/script/snat.sh或者:
curl -o snat.sh https://www.feijiangkeji.com/assets/uploads/snat.shchmod +x snat.shsudo ./snat.sh运行后会自动:
- 检测系统
- 检测防火墙
- 检测网卡
- 检测 IPv4 转发状态
然后进入菜单。
用于:
- VPN 客户端上网
- 内网 NAT
- 出口转发
自动添加:
MASQUERADE
SNAT
FORWARD支持:
- TCP
- UDP
- 单端口
- 端口范围
例如:
80
443
10000-20000
支持:
- 删除 SNAT
- 删除 FORWARD
- 删除端口规则
显示当前:
- iptables
- nftables
- firewalld
- ufw
规则状态。
tun0 -> eth0
客户端流量自动 NAT 出口。
wg0 -> ens18
自动配置:
- FORWARD
- MASQUERADE
适用于:
- strongSwan
- libreswan
- Cisco IPsec
脚本会自动检测并使用:
| 系统 | 方式 |
|---|---|
| Debian/Ubuntu | iptables-persistent |
| RHEL | service save |
| nftables | /etc/nftables.conf |
| firewalld | permanent |
| ufw | before.rules |
推荐系统:
| 系统 | 推荐度 |
|---|---|
| Debian 12 | ⭐⭐⭐⭐⭐ |
| Ubuntu 22.04+ | ⭐⭐⭐⭐⭐ |
| Rocky Linux 9 | ⭐⭐⭐⭐⭐ |
| AlmaLinux 9 | ⭐⭐⭐⭐⭐ |
| Fedora | ⭐⭐⭐⭐ |
| Alpine | ⭐⭐⭐ |
| Arch | ⭐⭐⭐ |
推荐:
sudo ./snat.sh如果使用:
- AWS
- Azure
- GCP
- 阿里云
- 腾讯云
请确保:
- 已放行对应端口
- 已允许转发流量
某些 VPS 厂商:
- 禁止 MAC spoof
- 禁止转发
- 禁止多 IP
请确认服务商策略。
- Debian 12
- Ubuntu 22.04
- Ubuntu 24.04
- CentOS 7
- Rocky Linux 9
- AlmaLinux 9
- Alpine 3
- Arch Linux
MIT License
如果这个项目对你有帮助,欢迎 Star ⭐