Ale*_*lex 13 mac proxy socks-proxy osx-mavericks macos
我有一个带端口的 SOCKS 代理。
如何让我的 MAC 使用它?我在网络设置下更改哪些设置?
如果您可以为自己设置一个 SSH 服务器,那么免费的sshuttle可以通过该连接隧道传输所有 TCP 流量,为您完成所有防火墙工作。
要将所有 TCP 流量和 DNS 请求转发到远程 SSH 服务器,命令非常简单:
sshuttle --dns -vr ssh_server 0/0
Run Code Online (Sandbox Code Playgroud)
除了 TCP 和 DNS,sshuttle 不转发其他请求,如 UDP、ICMP、ping 等。
有关更多信息和示例,请参阅在日常工作中使用 Sshuttle一文。
虽然设置系统范围的代理设置是一个好的开始,但您可能还想考虑使用 iptables 来确保所有流量都通过代理。某些应用程序不使用系统范围的配置设置(其中包括 Firefox),因此您必须定制规则以不允许直接连接,而只允许通过代理路由流量。
编辑:虽然我个人使用iptables规则来管理来自我的 VPN 的潜在“泄漏”,但实际上我最初错误地认为 iptables 可以直接与袜子代理一起使用。您需要像tun2socks这样的东西来制作虚拟隧道接口(例如 vpn 的使用)。
之后,您可以设置类似于以下内容的 iptables 脚本:
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# name of primary network interface (before tunnel)
PRIMARY=eth0
# gateway ip address (before tunnel - adsl router ip address)
# automatically determine the ip from the default route
GATEWAY=`route -n | grep $PRIMARY | egrep "^0\.0\.0\.0" | tr -s " " | cut -d" " -f2`
# provided by tun2socks: interface name
TUNNEL=tun0
# If you'd like, putting the tun2socks command here is a good idea. It may or may not be necessary to do so, but either way is more convenient than running the two commands separately.
# iptables rules - important!
LOCAL_NET=192.168.0.0/16
#LOCAL_NET=$GATEWAY
# Flush all previous filter rules, you might not want to include this line if you already have other rules setup
iptables -t filter --flush
iptables -t filter -X MYVPN
iptables -t filter -N MYVPN
# Add local routes to routing table
route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
route add -host 23.21.163.237 dev eth0 gw 192.168.1.1
# Add ssh routes to routing table
ip route add table 128 to 192.168.1.0/24 dev eth0
ip route add table 128 default via 192.168.1.1
# Exceptions for local traffic & vpn server
iptables -t filter -A MYVPN -o lo -j RETURN
iptables -t filter -A MYVPN -o ${TUNNEL} -j RETURN
iptables -t filter -A MYVPN --dst 127.0.0.1 -j RETURN
iptables -t filter -A MYVPN --dst $LOCAL_NET -j RETURN
iptables -t filter -A MYVPN --dst ${SERVER} -j RETURN
iptables -t filter -A MYVPN --dst ${VPN_SERVER} -j RETURN
# Add extra local nets here as necessary
iptables -t filter -A MYVPN -j DROP
# MYVPN traffic leaving this host:
iptables -t filter -A OUTPUT -p tcp --syn -j MYVPN
iptables -t filter -A OUTPUT -p icmp -j MYVPN
iptables -t filter -A OUTPUT -p udp -j MYVPN
Run Code Online (Sandbox Code Playgroud)
自然地,您会想让这个脚本反映您的特定网络(即,如果您使用的是 192.168.0.0/24 子网,请相应地进行调整)。此外,它非常紧密地基于我与 VPN 一起使用的脚本,因此,所有提到的 MYVPN 或 VPN——当您不使用 VPN 时,tun2socks实际上表现得好像您是一样,所以一切都应该一样。
特别感谢Unix.SE上的这个答案引导我朝着正确的方向回答这个问题。
再次编辑:所以,看起来 OS X 实际上会用ipfw而不是 iptables来做这件事(对不起,我主要是一个 linux 人,并认为 OS X 有 iptables 可用)。存在可以修改脚本的等效项,此处指出了其中的一些。 man ipfw应该让你直接了解语法。我将保留原始iptables脚本作为模板,以便您可以从概念上了解正在发生的事情。 WaterRoof看起来可能有助于使使用ipfw更加用户友好;其他前端也可能可用。
为什么系统首选项 -> 网络 ->(在窗口左侧选择一个网络,然后选择右下角的高级) -> 代理(顶部选项卡)不适合您?

| 归档时间: |
|
| 查看次数: |
30233 次 |
| 最近记录: |