Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active February 21, 2024 16:56
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mislav/c534c770e1c1e60a725c to your computer and use it in GitHub Desktop.
Save mislav/c534c770e1c1e60a725c to your computer and use it in GitHub Desktop.
Watch Netflix as if you were in the US by proxying DNS through a DigitalOcean instance.

Watch US Netflix content without a VPN

Update: this approach doesn't seem to work anymore since Netflix cracked down on it. Sorry!

This command-line script sets up a virtual server on DigitalOcean that acts as a DNS proxy. Then, it configures your computer to use that proxy. To Netflix, your traffic will appear as if it were coming from within the US.

DigitalOcean is ultimately a paid service. The maximum that running a virtual server will cost you is USD$5/month. You can destroy the instance while you're not using it, though. They're disposable.

If this setup sounds complicated, or you're on a platform other than OS X, or you're not comfortable with the technical terms discussed here, you might be better off using another service such as unblock-us.com or the Hola Chrome extension.

This small tool is made possible by Anton Belodedenko's netflix-proxy which does most of the hard work.

Prerequisites

  • Sign up for a DigitalOcean account. You will get some initial credit for free.
  • Mac OS X. The DNS configuration of your own system depends on a utility called networksetup.
  • Ruby (comes by default with OS X). The tugboat library is installable via RubyGems.
  • tugboat CLI client for DigitalOcean. Install with gem install tugboat && tugboat authorize

Usage

Install the script from this gist as an executable somewhere in your PATH:

curl -fsSL 'https://gist.githubusercontent.com/mislav/c534c770e1c1e60a725c/raw/netflix.sh' -o ~/bin/netflix
chmod +x ~/bin/netflix

Then:

# Create and configure the virtual server. This can take up to 5 minutes.
# You should be ready to watch Netflix after this is done.
netflix create

# Check the status of your current DNS configuration and of the server instance:
netflix status

# When you want to stop using DNS proxying (you should close Netflix first):
netflix off

# When you want to turn DNS proxying back on, or if
# you happened to switch to a different Wi-Fi network:
netflix on

# To destroy the virtual server and stop paying:
netflix destroy

Netflix has heuristics in place to eventually detect unblockers like these and blacklist them. If that happens (you will see a notice like "It seems like you're using an unblocker"), simply destroy the current instance and create a new one.

#!/bin/bash
set -e
droplet=netflix
interface=Wi-Fi
us_regions=( nyc1 nyc2 nyc3 )
random_region() {
echo ${us_regions[RANDOM % ${#us_regions[@]}]}
}
_server_ip=
server_ip() {
[ -n "$_server_ip" ] || _server_ip="$(tugboat info --name="$droplet" --attribute=ip4 --porcelain)"
echo "$_server_ip"
}
add_client_ip() {
ssh "
set -x
sudo iptables -I FRIENDS -s ${1}/32 -j ACCEPT
iptables-save > /etc/iptables/rules.v4 || iptables-save > /etc/iptables.rules
"
}
sudo_warmup() {
sudo -v -p "Local root password (for changing DNS settings): "
}
tugboat() {
if command -v tugboat &>/dev/null; then
command tugboat "$@"
else
echo "Error: you need \`tugboat' to continue. To install:" >&2
echo " gem install tugboat" >&2
echo " tugboat authorize" >&2
return 1
fi
}
ssh() {
command ssh "root@$(server_ip)" "$@"
}
status() {
echo -n "DNS: "
networksetup -getdnsservers "$interface"
tugboat info --name="$droplet"
}
on() {
sudo_warmup
add_client_ip "$(curl -fsS icanhazip.com)"
sudo networksetup -setdnsservers "$interface" "$(server_ip)"
}
off() {
sudo_warmup
sudo networksetup -setdnsservers "$interface" empty
}
create() {
sudo_warmup
key_id="$(tugboat keys | grep -o 'id: [0-9]\+' | head -1 | awk '{print $2}')"
if [ -z "$key_id" ]; then
echo "Error: no SSH keys stored in your DigitalOcean settings." >&2
echo "Please visit https://cloud.digitalocean.com/settings/security and use 'Add SSH key'." >&2
return 1
fi
tugboat create "$droplet" --size 512mb --image docker --region "$(random_region)" --keys "$key_id" --ip6
tugboat wait --name="$droplet"
sleep 10
ssh "
set -x
git clone https://github.com/ab77/netflix-proxy /opt/netflix-proxy
cd /opt/netflix-proxy
./build.sh
"
on
}
destroy() {
off
tugboat destroy --name="$droplet" --confirm
}
case "$1" in
ssh | status | on | off | create | destroy )
"$@"
;;
* )
echo "Unknown command. Please use one of: status on off create destroy ssh" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment