Eva*_*van 33 server vpn bittorrent transmission
我想确保传输仅在其运行的服务器连接到 VPN 时发送/接收流量。
我发现了这个类似的问题,但我不想强制所有流量通过 VPN,而且我无法找到有关如何从命令行使用 firestarter 的良好指南。
相反,我正在考虑使用 ufw,但我几乎没有使用防火墙的经验,我希望社区可以帮助我。
我的一个想法是强制传输使用特定端口,比如 33442,然后只允许来自 VPN 服务器的 IP 地址的流量进出该端口。我查看了 Ubuntu 服务器指南,我认为可以这样做:
sudo ufw enable
sudo ufw deny port tcp from localhost to any port 33442
sudo ufa allow port tcp from localhost to VPNIP port 33442
sudo ufw deny port udp from localhost to any port 33442
sudo ufa allow port udp from localhost to VPNIP port 33442
Run Code Online (Sandbox Code Playgroud)
这个逻辑是否成立?你会怎么做?我将用于 VPNIP、VPN 服务器的公共 IP,还是应该指定 VPN 将我连接到的本地子网范围?
谢谢你的帮助!
小智 30
创建vpnroute组:
sudo groupadd vpnroute
Run Code Online (Sandbox Code Playgroud)
添加一个iptables规则,拒绝任何vpnroute不通过tun0接口的组成员建立的任何传出网络连接:
sudo iptables -A OUTPUT -m owner --gid-owner vpnroute \! -o tun0 -j REJECT
Run Code Online (Sandbox Code Playgroud)
以组员身份开始传输过程vpnroute:
sudo -g vpnroute transmission-gtk &
Run Code Online (Sandbox Code Playgroud)
小智 7
不要在基于复杂系统脚本的 vpn 中使用更冗长的“操作方法”......! iptables 是最好的(也是万无一失的)方法!!!- 使用一些基于传输用户和组的 IPTABLE 规则来控制 vpn(不像许多使用 systemd 脚本、上下脚本等更复杂的“黑客”方法......),而且非常简单!
第 1 步 - 设置:(假设传输已安装,因此存在 debian-transmission 用户!)
sudo apt-get install iptables
sudo apt-get install iptables-persistent
Run Code Online (Sandbox Code Playgroud)
步骤 2 - 创建传输 IP 规则文件
sudo nano transmission-ip-rules
Run Code Online (Sandbox Code Playgroud)
并在下面的代码块中添加文本,从 #!/bin/bash
sudo apt-get install iptables
sudo apt-get install iptables-persistent
Run Code Online (Sandbox Code Playgroud)
保存文件然后运行
sudo iptables -F
sudo chmod +x transmission-ip-rules
sudo ./transmission-ip-rules
Run Code Online (Sandbox Code Playgroud)
然后确保这些规则在重新启动之间保持不变:
sudo dpkg-reconfigure iptables-persistent
Run Code Online (Sandbox Code Playgroud)
并点击是对两个提示。完毕!
这个脚本的伟大之处在于它将通过设备跟踪所有数据!当你发出
sudo iptables -L -v
Run Code Online (Sandbox Code Playgroud)
它将显示有多少数据流向哪个接口以及哪一侧 INPUT 或 OUTPUT,因此您可以确保 vpn 脚本正常工作。例如;
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1749K 661M ACCEPT all -- tun0 any anywhere anywhere
3416K 3077M ACCEPT all -- eth0 any anywhere anywhere
362K 826M ACCEPT all -- lo any anywhere anywhere
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 all -- any any anywhere anywhere
Chain OUTPUT (policy ACCEPT 2863K packets, 2884M bytes)
pkts bytes target prot opt in out source destination
1260 778K ACCEPT tcp -- any eth0 anywhere 192.168.1.0/ 25 tcp spt:9091 owner GID match debian-transmission
0 0 ACCEPT udp -- any eth0 anywhere 192.168.1.0/ 25 udp spt:9091 owner GID match debian-transmission
1973K 1832M ACCEPT all -- any tun0 anywhere anywhere owner GID match debian-transmission
8880 572K ACCEPT all -- any lo anywhere anywhere owner GID match debian-transmission
13132 939K REJECT all -- any any anywhere anywhere owner GID match debian-transmission reject-with icmp-port-unreachable
Run Code Online (Sandbox Code Playgroud)
此脚本已在从 vpn 连接、断开连接、重新启动时进行了详尽测试。它工作得很好。传输只能使用VPN。与其他脚本相比,此脚本的最大优势在于我已确保如您所见(通过iptables -L -v) 您的数据与传输中的数据相符(通过为每个接口 eth0、vpn (tun0) 添加 INPUT (all) 和 Forward (all) 规则)。所以你确切地知道发生了什么!!!数据总数与传输不完全一致 - 不幸的是,我无法在输入端区分 debian-transmission 用户,并且会有额外的开销和使用相同 VPN 的其他进程,但您会看到数据大致相符在 INPUT 侧,大约一半在 vpn 的 OUTPUT 确认其工作。另一件需要注意的事情 - vpn 断开连接需要一段时间(所有流量都停止传输)并重新连接传输以在新 vpn 上“开始”,所以不要担心是否需要大约 5 分钟才能再次开始洪流.. .
提示 -如果您想逐行了解此脚本的工作原理,请使用谷歌“MAN iptables”并查看有关带宽监控的文章...
小智 6
这适用于无头传输,我根据运行传输服务的用户限制流量, 10.0.0.0/8您的内部网络是否应该更改以匹配您的网络,tun0您的 OpenVPN 接口,eth0您的 LAN 连接。
添加sudo到命令,如果您不是 root:
iptables -F (我们使用 -F 开关来刷新所有现有规则,因此我们从一个干净的状态开始,从中添加新规则。)
iptables -L (列出当前设置)
NET=10.0.0.0/8
GROUP=debian-transmission
IFACE_INTERNAL=eth0
IFACE_VPN=tun0
ALLOW_PORT_FROM_LOCAL=9091
iptables -A OUTPUT -d $NET -p tcp --sport $ALLOW_PORT_FROM_LOCAL -m owner --gid-owner $GROUP -o $IFACE_INTERNAL -j ACCEPT
iptables -A OUTPUT -d $NET -p udp --sport $ALLOW_PORT_FROM_LOCAL -m owner --gid-owner $GROUP -o $IFACE_INTERNAL -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner $GROUP -o $IFACE_VPN -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner $GROUP -o lo -j ACCEPT
iptables -A OUTPUT -m owner --gid-owner $GROUP -j REJECT
Run Code Online (Sandbox Code Playgroud)
重启后使 iptables 持久化
apt-get install iptables-persistent
service iptables-persistent start
Run Code Online (Sandbox Code Playgroud)
理想情况下,您应该使用具有绑定到特定接口(VPN 接口)功能的 torrent 客户端。
在 torrent 客户端中,Deluge 就是这样做的。因此,您可以安装 Deluge 并在首选项中配置界面,然后就完成了!
| 归档时间: |
|
| 查看次数: |
78564 次 |
| 最近记录: |