[Tutorial] Turn your OpenWRT router in VPN or Socks5 transmitter

Lukmat

Elite Member
Executive VIP
Jr. VIP
Joined
Jan 22, 2008
Messages
5,791
Reaction score
8,181
The tutorial is fixed by AI grammarly because I am not native
For claude code or codex guys:
1. Tell your AI to fetch this tutorial
2. Tell it to execute via SSH
3. In 5 minutes you have router for proxy usage

-------------------

Router to use: Cudy WR3000
Goal: use proxy on your phones without telling apps you are using the proxy
Up to 16 wifi networks
Currently I have 4 phones with independent proxies
Each network can have own independent VPN or proxy

1782399314991.png



Turn a $30 Router Into a Privacy Gateway (SOCKS5 Proxy & WireGuard VPN)

A step-by-step guide to setting up a Cudy WR3000 (or any OpenWrt-compatible router) so that every device on your network — phones, laptops, smart TVs — automatically routes through either a SOCKS5 proxy or a WireGuard VPN. No per-device configuration needed.




What You'll Build


Your phone / laptop / TV
|
WiFi or LAN cable
|
┌──────────────────────┐
│ Cudy WR3000 │
│ (OpenWrt) │
│ │
│ Option A: SOCKS5 │ ← transparent proxy, change exit IP in seconds
│ Option B: WireGuard │ ← encrypted VPN tunnel (e.g. Surfshark)
└──────────────────────┘
|
Your ISP / Internet


Option A (SOCKS5) is great when you have residential or mobile proxies and need to swap IPs frequently — one command changes the exit IP for your entire network.

Option B (WireGuard VPN) is better for always-on privacy with a commercial VPN provider like Surfshark, Mullvad, or IVPN.

You can set up both and switch between them.




Prerequisites

WhatWhy
Cudy WR3000 v1 (~$30)Cheap, powerful (256 MB RAM, Wi-Fi 6), well-supported by OpenWrt. Any OpenWrt router works — just find the right firmware image.
Ethernet cableTo connect the router to your main router/modem (WAN) and optionally to your computer during setup.
A computer with SSHMac/Linux have it built-in. Windows: use PowerShell or PuTTY.
SOCKS5 proxy credentials (Option A)From a proxy provider — you'll get an IP, port, username, and password.
WireGuard config file (Option B)From your VPN provider (e.g. Surfshark Manual Setup > WireGuard).




Part 1: Install OpenWrt

If your router already runs OpenWrt, skip to Part 2 or Part 3.

1.1 Download the firmware

Go to openwrt.org and find the sysupgrade image for your router model.

For Cudy WR3000 v1: search "Cudy WR3000" on the OpenWrt Table of Hardware.

1.2 Flash it

  1. Open your router's stock web admin (usually 192.168.10.1 for Cudy).
  2. Go to System > Firmware Upgrade.
  3. Upload the OpenWrt sysupgrade .bin file.
  4. Wait 2-3 minutes. Don't unplug power.
  5. The router will reboot. Its new address is 192.168.1.1.

1.3 First login

Code:

No password is set by default. Set one now:

Code:
passwd

1.4 Connect the router to the internet

Plug an ethernet cable from your main router/modem into the WAN port of the Cudy. The Cudy gets internet via DHCP automatically.

Verify:

Code:
ping -c 3 google.com

1.5 Update package lists

Code:
opkg update

You now have a working OpenWrt router. Pick your path below.




Part 2 (Option A): Transparent SOCKS5 Proxy

This setup makes every device on your network use a SOCKS5 proxy — without any device knowing about it. The router intercepts all TCP traffic and tunnels it through the proxy.

How it works

Code:
Device sends normal HTTP/HTTPS request
    ↓
Router intercepts it (nftables REDIRECT)
    ↓
redsocks converts it to SOCKS5
    ↓
Traffic exits through the proxy server

DNS is also routed through the proxy (via dnstc), so your ISP can't see what domains you visit.

2.1 Install redsocks

Code:
opkg update
opkg install redsocks

2.2 Configure redsocks

Create /etc/redsocks.conf with your proxy details. Replace the four values with your own:

Code:
cat > /etc/redsocks.conf << 'EOF'
base {
 log_debug = off;
 log_info = on;
 log = "syslog:daemon";
 daemon = on;
 redirector = iptables;
}

redsocks {
 local_ip = 0.0.0.0;
 local_port = 12345;

 ip = YOUR_PROXY_IP;
 port = YOUR_PROXY_PORT;

 type = socks5;
 login = "YOUR_USERNAME";
 password = "YOUR_PASSWORD";
}

dnstc {
 local_ip = 0.0.0.0;
 local_port = 5300;
}
EOF

What is dnstc? It's a tiny DNS forwarder that tells clients "your answer is too big, retry over TCP." This forces DNS queries through the TCP proxy chain instead of leaking over UDP to your ISP.

2.3 Create the init script for redsocks

Code:
cat > /etc/init.d/redsocks << 'INITEOF'
#!/bin/sh /etc/rc.common
START=90

[ -e "/etc/redsocks.conf" ] || exit 0

start() {
    if [ -e "/var/run/redsocks.pid" ]; then
        echo "redsocks is already running"
        exit 0
    fi
    echo -n "Starting redsocks..."
    /usr/sbin/redsocks -p /var/run/redsocks.pid
    echo " done"
}

stop() {
    if [ ! -e "/var/run/redsocks.pid" ]; then
        echo "redsocks is not running"
        exit 0
    fi
    echo -n "Stopping redsocks..."
    kill $(cat /var/run/redsocks.pid)
    rm /var/run/redsocks.pid
    echo " done"
}
INITEOF
chmod +x /etc/init.d/redsocks

2.4 Create the firewall rules

This is the magic. These nftables rules intercept all traffic from your LAN and redirect it through redsocks.

Code:
cat > /usr/bin/redsocks-rules << 'NFTEOF'
#!/bin/sh
LAN_IF="br-lan"
RS_PORT=12345
DNS_PORT=5300

nft -f - <<EOF
table ip redsocks {}
delete table ip redsocks
table ip6 redsocks {}
delete table ip6 redsocks
table ip redsocks {
    chain prerouting {
        type nat hook prerouting priority -100; policy accept;

        # Don't proxy traffic to private/local addresses
        iifname "${LAN_IF}" ip daddr { 0.0.0.0/8, 10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.168.0.0/16, 224.0.0.0/4, 240.0.0.0/4 } return

        # Redirect DNS (UDP 53) to dnstc, which forces TCP
        iifname "${LAN_IF}" udp dport 53 redirect to :${DNS_PORT}

        # Redirect all TCP to redsocks
        iifname "${LAN_IF}" meta l4proto tcp redirect to :${RS_PORT}
    }

    chain forward {
        type filter hook forward priority -5; policy accept;
        # Block all non-TCP (kills QUIC/UDP so apps fall back to TCP)
        iifname "${LAN_IF}" meta l4proto udp reject
    }
}

# Block IPv6 forwarding entirely (proxy is IPv4-only)
table ip6 redsocks {
    chain forward {
        type filter hook forward priority -5; policy accept;
        iifname "${LAN_IF}" reject
    }
}
EOF
NFTEOF
chmod +x /usr/bin/redsocks-rules

What each rule does:

RulePurpose
ip daddr { private ranges } returnDon't proxy local traffic (router admin, LAN devices talking to each other).
udp dport 53 redirect to :5300Catch DNS and route it through dnstc → TCP → proxy. Prevents DNS leaks.
meta l4proto tcp redirect to :12345Send all TCP to redsocks, which forwards it to your SOCKS5 proxy.
meta l4proto udp rejectBlock UDP. This kills QUIC (fast but unproxyable) and forces apps to fall back to normal TCP.
ip6 ... rejectBlock IPv6 forwarding. Most SOCKS5 proxies are IPv4-only; without this, IPv6 traffic would bypass the proxy.

2.5 Create the redirect init script

Code:
cat > /etc/init.d/redsocks-redir << 'INITEOF'
#!/bin/sh /etc/rc.common
START=91
STOP=10

start() {
    /usr/bin/redsocks-rules
}

stop() {
    nft delete table ip redsocks 2>/dev/null
}

restart() {
    /usr/bin/redsocks-rules
}
INITEOF
chmod +x /etc/init.d/redsocks-redir

2.6 Create the one-command proxy switcher

This is the killer feature — change your exit IP from your laptop in one command:

Code:
cat > /usr/bin/setproxy << 'SPEOF'
#!/bin/sh
# Usage: setproxy <ip> <port> [username] [password]
CONF=/etc/redsocks.conf
IP="$1"; PORT="$2"; LOGIN="$3"; PASS="$4"

if [ -z "$IP" ] || [ -z "$PORT" ]; then
  echo "Usage: setproxy <ip> <port> [username] [password]"
  exit 1
fi

AUTH=""
[ -n "$LOGIN" ] && AUTH="${AUTH} login = \"${LOGIN}\";
"
[ -n "$PASS" ] && AUTH="${AUTH} password = \"${PASS}\";
"

cat > "$CONF" <<EOF
base {
 log_debug = off;
 log_info = on;
 log = "syslog:daemon";
 daemon = on;
 redirector = iptables;
}

redsocks {
 local_ip = 0.0.0.0;
 local_port = 12345;

 ip = ${IP};
 port = ${PORT};

 type = socks5;
${AUTH}}

dnstc {
 local_ip = 0.0.0.0;
 local_port = 5300;
}
EOF

killall redsocks 2>/dev/null
rm -f /var/run/redsocks.pid
sleep 1
/etc/init.d/redsocks start >/dev/null 2>&1
sleep 1
/usr/bin/redsocks-rules 2>/dev/null

if pidof redsocks >/dev/null; then
  echo "OK: proxy = ${IP}:${PORT} (login: ${LOGIN:-none}). redsocks is running."
else
  echo "ERROR: redsocks failed to start. Debug:  logread | grep redsocks | tail"
  exit 1
fi
SPEOF
chmod +x /usr/bin/setproxy

2.7 Add a watchdog (auto-restart if redsocks crashes)

Code:
cat > /usr/bin/redsocks_watchdog.sh << 'WDEOF'
#!/bin/sh
if ! pidof redsocks >/dev/null 2>&1; then
    rm -f /var/run/redsocks.pid
    /etc/init.d/redsocks start >/dev/null 2>&1
    /usr/bin/redsocks-rules >/dev/null 2>&1
    logger -t redsocks_watchdog "redsocks was down -> restarted"
fi
nft list table ip redsocks >/dev/null 2>&1 || /usr/bin/redsocks-rules >/dev/null 2>&1
WDEOF
chmod +x /usr/bin/redsocks_watchdog.sh

# Run watchdog every minute
(crontab -l 2>/dev/null; echo '* * * * * /usr/bin/redsocks_watchdog.sh') | crontab -

2.8 Enable and start everything

Code:
service redsocks enable
service redsocks-redir enable
service redsocks start
/usr/bin/redsocks-rules

2.9 Test it

On any device connected to the router's WiFi, open:

2.10 Switching proxies

From your computer (Mac/Linux), swap the entire network's exit IP in one command:

Code:
# With authentication
ssh [email protected] setproxy 103.219.170.11 24283 myuser mypass

# Without authentication
ssh [email protected] setproxy 103.219.170.11 24283

The change is instant — no router reboot needed.




Part 3 (Option B): WireGuard VPN

WireGuard is a modern, fast VPN protocol. This setup routes all traffic through a commercial VPN provider.

3.1 Install WireGuard

Code:
opkg update
opkg install wireguard-tools luci-proto-wireguard

3.2 Get your config from your VPN provider

Most providers (Surfshark, Mullvad, IVPN, etc.) let you download a .conf file. It looks like this:

Code:
[Interface]
PrivateKey = YOUR_PRIVATE_KEY
Address = 10.14.0.2/16
DNS = 162.252.172.57

[Peer]
PublicKey = SERVER_PUBLIC_KEY
AllowedIPs = 0.0.0.0/0
Endpoint = us-lax.prod.surfshark.com:51820
PersistentKeepalive = 25

You'll need three values from this file:
  • PrivateKey (your key)
  • PublicKey (server's key)
  • Endpoint (server address)

3.3 Configure the WireGuard interface

Code:
# Create the WireGuard interface
uci set network.wg0=interface
uci set network.wg0.proto='wireguard'
uci set network.wg0.private_key='YOUR_PRIVATE_KEY'
uci add_list network.wg0.addresses='10.14.0.2/16'
uci set network.wg0.metric='10'

# Add the VPN server as a peer
uci set network.wg_peer0=wireguard_wg0
uci set network.wg_peer0.public_key='SERVER_PUBLIC_KEY'
uci set network.wg_peer0.endpoint_host='us-lax.prod.surfshark.com'
uci set network.wg_peer0.endpoint_port='51820'
uci set network.wg_peer0.persistent_keepalive='25'
uci add_list network.wg_peer0.allowed_ips='0.0.0.0/0'
uci set network.wg_peer0.route_allowed_ips='1'

# Save and apply
uci commit network

What is metric='10'? It's a priority number. Lower = preferred. Your regular WAN connection has metric 100, so WireGuard (metric 10) takes priority. All traffic goes through the VPN. If the VPN goes down, traffic falls back to the regular connection.

3.4 Add WireGuard to the firewall

WireGuard needs to be in the wan firewall zone so it can reach the internet:

Code:
# Get the current wan zone networks and add wg0
uci add_list firewall.@zone[1].network='wg0'
uci commit firewall

How to verify: uci show firewall.@zone[1] — you should see network='wan' 'wan6' 'wg0' (or similar).

3.5 Set DNS to your VPN provider's servers

Using your VPN provider's DNS prevents your ISP from seeing your DNS queries:

Code:
uci set network.wg0.dns='162.252.172.57 149.154.159.92'
uci commit network

3.6 Disable IPv6 (prevents leaks)

Most VPN tunnels are IPv4-only. Without disabling IPv6, some traffic could bypass the VPN:

Code:
# Disable IPv6 system-wide
echo 'net.ipv6.conf.all.disable_ipv6=1' >> /etc/sysctl.conf
sysctl -p

# Disable the IPv6 WAN interface
uci set network.wan6.auto='0'
uci commit network

# Block IPv6 forwarding in the firewall
uci add firewall rule
uci set firewall.@rule[-1].name='Block-IPv6-Forward-Leak'
uci set firewall.@rule[-1].family='ipv6'
uci set firewall.@rule[-1].src='lan'
uci set firewall.@rule[-1].dest='wan'
uci set firewall.@rule[-1].target='REJECT'
uci commit firewall

3.7 Restart networking

Code:
/etc/init.d/network restart
/etc/init.d/firewall restart

3.8 Verify the VPN is working

Code:
# Check WireGuard status
wg show

# Check your exit IP
wget -qO- http://ifconfig.me

The IP should match your VPN provider's server, not your ISP.

On any device connected to the router, visit whatismyipaddress.com to confirm.

3.9 Switching VPN servers

To change to a different server (e.g. from US to UK):

  1. Generate a new config in your VPN provider's dashboard.
  2. Run:

Code:
uci set network.wg_peer0.public_key='NEW_SERVER_PUBLIC_KEY'
uci set network.wg_peer0.endpoint_host='uk-lon.prod.surfshark.com'
uci commit network
/etc/init.d/network restart




Bonus: Randomize Your WiFi MAC Address

Every WiFi access point broadcasts a unique MAC address (BSSID). This can be used to track your router's physical location (e.g. by Google's location services). Randomizing it on every boot adds a layer of privacy.

Code:
# Create the randomizer script
cat > /usr/bin/rand-bssid << 'RBEOF'
#!/bin/sh
RAND=$(head -c5 /dev/urandom | hexdump -v -e '/1 ":%02x"')
MAC="02${RAND}"
uci set wireless.default_radio0.macaddr="${MAC}"
uci commit wireless
wifi reload radio0 >/dev/null 2>&1
logger -t rand-bssid "Set random BSSID radio0 = ${MAC}"
RBEOF
chmod +x /usr/bin/rand-bssid

# Create init script (runs before networking starts)
cat > /etc/init.d/randbssid << 'INITEOF'
#!/bin/sh /etc/rc.common
START=15
start() {
    /usr/bin/rand-bssid
}
INITEOF
chmod +x /etc/init.d/randbssid
service randbssid enable

Why 02? The 02 prefix marks the MAC as "locally administered," which tells other devices it's intentionally custom and not a manufacturer-assigned address.




Troubleshooting

SOCKS5 issues

ProblemFix
No internet on devicesssh [email protected] 'logread | grep redsocks | tail' — check for proxy connection errors.
redsocks not runningssh [email protected] '/etc/init.d/redsocks restart; /usr/bin/redsocks-rules'
Check firewall rulesssh [email protected] 'nft list table ip redsocks'
DNS leakingMake sure dnstc section exists in /etc/redsocks.conf and UDP 53 redirect rule is active.
QUIC/UDP bypassing proxyThe udp reject rule should block it. Check with nft list table ip redsocks.
Nuclear optionssh [email protected] reboot

VPN issues

ProblemFix
wg show shows no handshakeCheck that endpoint_host resolves: nslookup us-lax.prod.surfshark.com. The WAN must be connected to the internet first.
Slow speedsTry a closer server. WireGuard itself adds minimal overhead.
IPv6 leakRun curl -6 ifconfig.me — it should fail. If it doesn't, revisit step 3.6.
VPN connected but no internetMake sure wg0 is in the wan firewall zone and route_allowed_ips is 1.




Security Notes

  • SSH keys: For convenience, copy your SSH public key to the router so you don't need a password:
    Code:
    ssh-copy-id [email protected]
  • Change the default password if you haven't already (passwd on the router).
  • LuCI web interface is at http://192.168.1.1 — handy for Wi-Fi settings, but all the proxy/VPN config is best done via SSH.
  • Proxy credentials are stored in plain text in /etc/redsocks.conf. The router itself is the security boundary — anyone with SSH access can read them.




Quick Reference

Code:
# === SOCKS5 ===
# Change proxy (from your Mac/PC):
ssh [email protected] setproxy IP PORT USER PASS

# Check status:
ssh [email protected] 'pidof redsocks && echo "running" || echo "stopped"'

# === WireGuard VPN ===
# Check VPN status:
ssh [email protected] wg show

# Change VPN server:
ssh [email protected] 'uci set network.wg_peer0.public_key="NEW_KEY"; \
  uci set network.wg_peer0.endpoint_host="NEW_HOST"; \
  uci commit network; /etc/init.d/network restart'

# === General ===
# What IP does the world see?
ssh [email protected] 'wget -qO- http://ifconfig.me'

# Reboot the router:
ssh [email protected] reboot




Built and tested on a Cudy WR3000 v1 running OpenWrt 24.10.5. Total cost: ~$30 for the router + your proxy/VPN subscription.
 
This guide is awesome and super useful. It is a great idea to spend $30 to build a proxy and VPN gateway when you are dealing with a lot of phones that need separate IP addresses.

The custom nftables rules and the script that lets you switch proxies with 1 command saves a lot of time. Thanks for putting instructions and troubleshooting steps. : )
 
This guide is awesome and super useful. It is a great idea to spend $30 to build a proxy and VPN gateway when you are dealing with a lot of phones that need separate IP addresses.

The custom nftables rules and the script that lets you switch proxies with 1 command saves a lot of time. Thanks for putting instructions and troubleshooting steps. : )
I am currently using it on 4 phones, planning on 10 phones soon
Works smooth, much faster than sharing for example proxy from Windows via hotspot.

... and you can route DNS, disable UDP and iPv6
 
Awesome guide, I'm building something similiar, I'm using sing-box for the proxy client, it support many protocol including wireguard as outbound connection. It also allow you route specific client, domain, or ip to different outbound.
 
I am currently using it on 4 phones, planning on 10 phones soon
Works smooth, much faster than sharing for example proxy from Windows via hotspot.

... and you can route DNS, disable UDP and iPv6
Phone are better than a router that cost 30/40€ and can handle up tp 16 wifi?
 
Phone are better than a router that cost 30/40€ and can handle up tp 16 wifi?
What? I am using router to have independent proxies on phones, that apps cannot detect
Forget shadowsocks, redsocks, etc. on phone, apps with security sdks know in seconds
 
What? I am using router to have independent proxies on phones, that apps cannot detect
Forget shadowsocks, redsocks, etc. on phone, apps with security sdks know in seconds
Ah ok make sense :D
Do you use 4g proxies? from mobile data
 
Ah ok make sense :D
Do you use 4g proxies? from mobile data
any socks5 and vpn with manual configs like surfshark works
 
The tutorial is fixed by AI grammarly because I am not native
For claude code or codex guys:
1. Tell your AI to fetch this tutorial
2. Tell it to execute via SSH
3. In 5 minutes you have router for proxy usage

-------------------

Router to use: Cudy WR3000
Goal: use proxy on your phones without telling apps you are using the proxy
Up to 16 wifi networks
Currently I have 4 phones with independent proxies
Each network can have own independent VPN or proxy

View attachment 531252



Turn a $30 Router Into a Privacy Gateway (SOCKS5 Proxy & WireGuard VPN)

A step-by-step guide to setting up a Cudy WR3000 (or any OpenWrt-compatible router) so that every device on your network — phones, laptops, smart TVs — automatically routes through either a SOCKS5 proxy or a WireGuard VPN. No per-device configuration needed.




What You'll Build


Your phone / laptop / TV
|
WiFi or LAN cable
|
┌──────────────────────┐
│ Cudy WR3000 │
│ (OpenWrt) │
│ │
│ Option A: SOCKS5 │ ← transparent proxy, change exit IP in seconds
│ Option B: WireGuard │ ← encrypted VPN tunnel (e.g. Surfshark)
└──────────────────────┘
|
Your ISP / Internet


Option A (SOCKS5) is great when you have residential or mobile proxies and need to swap IPs frequently — one command changes the exit IP for your entire network.

Option B (WireGuard VPN) is better for always-on privacy with a commercial VPN provider like Surfshark, Mullvad, or IVPN.

You can set up both and switch between them.




Prerequisites

WhatWhy
Cudy WR3000 v1 (~$30)Cheap, powerful (256 MB RAM, Wi-Fi 6), well-supported by OpenWrt. Any OpenWrt router works — just find the right firmware image.
Ethernet cableTo connect the router to your main router/modem (WAN) and optionally to your computer during setup.
A computer with SSHMac/Linux have it built-in. Windows: use PowerShell or PuTTY.
SOCKS5 proxy credentials (Option A)From a proxy provider — you'll get an IP, port, username, and password.
WireGuard config file (Option B)From your VPN provider (e.g. Surfshark Manual Setup > WireGuard).




Part 1: Install OpenWrt



1.1 Download the firmware

Go to openwrt.org and find the sysupgrade image for your router model.

For Cudy WR3000 v1: search "Cudy WR3000" on the OpenWrt Table of Hardware.

1.2 Flash it

  1. Open your router's stock web admin (usually 192.168.10.1 for Cudy).
  2. Go to System > Firmware Upgrade.
  3. Upload the OpenWrt sysupgrade .bin file.
  4. Wait 2-3 minutes. Don't unplug power.
  5. The router will reboot. Its new address is 192.168.1.1.

1.3 First login

Code:

No password is set by default. Set one now:

Code:
passwd

1.4 Connect the router to the internet

Plug an ethernet cable from your main router/modem into the WAN port of the Cudy. The Cudy gets internet via DHCP automatically.

Verify:

Code:
ping -c 3 google.com

1.5 Update package lists

Code:
opkg update

You now have a working OpenWrt router. Pick your path below.




Part 2 (Option A): Transparent SOCKS5 Proxy

This setup makes every device on your network use a SOCKS5 proxy — without any device knowing about it. The router intercepts all TCP traffic and tunnels it through the proxy.

How it works

Code:
Device sends normal HTTP/HTTPS request
    ↓
Router intercepts it (nftables REDIRECT)
    ↓
redsocks converts it to SOCKS5
    ↓
Traffic exits through the proxy server

DNS is also routed through the proxy (via dnstc), so your ISP can't see what domains you visit.

2.1 Install redsocks

Code:
opkg update
opkg install redsocks

2.2 Configure redsocks

Create /etc/redsocks.conf with your proxy details. Replace the four values with your own:

Code:
cat > /etc/redsocks.conf << 'EOF'
base {
 log_debug = off;
 log_info = on;
 log = "syslog:daemon";
 daemon = on;
 redirector = iptables;
}

redsocks {
 local_ip = 0.0.0.0;
 local_port = 12345;

 ip = YOUR_PROXY_IP;
 port = YOUR_PROXY_PORT;

 type = socks5;
 login = "YOUR_USERNAME";
 password = "YOUR_PASSWORD";
}

dnstc {
 local_ip = 0.0.0.0;
 local_port = 5300;
}
EOF



2.3 Create the init script for redsocks

Code:
cat > /etc/init.d/redsocks << 'INITEOF'
#!/bin/sh /etc/rc.common
START=90

[ -e "/etc/redsocks.conf" ] || exit 0

start() {
    if [ -e "/var/run/redsocks.pid" ]; then
        echo "redsocks is already running"
        exit 0
    fi
    echo -n "Starting redsocks..."
    /usr/sbin/redsocks -p /var/run/redsocks.pid
    echo " done"
}

stop() {
    if [ ! -e "/var/run/redsocks.pid" ]; then
        echo "redsocks is not running"
        exit 0
    fi
    echo -n "Stopping redsocks..."
    kill $(cat /var/run/redsocks.pid)
    rm /var/run/redsocks.pid
    echo " done"
}
INITEOF
chmod +x /etc/init.d/redsocks

2.4 Create the firewall rules

This is the magic. These nftables rules intercept all traffic from your LAN and redirect it through redsocks.

Code:
cat > /usr/bin/redsocks-rules << 'NFTEOF'
#!/bin/sh
LAN_IF="br-lan"
RS_PORT=12345
DNS_PORT=5300

nft -f - <<EOF
table ip redsocks {}
delete table ip redsocks
table ip6 redsocks {}
delete table ip6 redsocks
table ip redsocks {
    chain prerouting {
        type nat hook prerouting priority -100; policy accept;

        # Don't proxy traffic to private/local addresses
        iifname "${LAN_IF}" ip daddr { 0.0.0.0/8, 10.0.0.0/8, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.168.0.0/16, 224.0.0.0/4, 240.0.0.0/4 } return

        # Redirect DNS (UDP 53) to dnstc, which forces TCP
        iifname "${LAN_IF}" udp dport 53 redirect to :${DNS_PORT}

        # Redirect all TCP to redsocks
        iifname "${LAN_IF}" meta l4proto tcp redirect to :${RS_PORT}
    }

    chain forward {
        type filter hook forward priority -5; policy accept;
        # Block all non-TCP (kills QUIC/UDP so apps fall back to TCP)
        iifname "${LAN_IF}" meta l4proto udp reject
    }
}

# Block IPv6 forwarding entirely (proxy is IPv4-only)
table ip6 redsocks {
    chain forward {
        type filter hook forward priority -5; policy accept;
        iifname "${LAN_IF}" reject
    }
}
EOF
NFTEOF
chmod +x /usr/bin/redsocks-rules

What each rule does:

RulePurpose
ip daddr { private ranges } returnDon't proxy local traffic (router admin, LAN devices talking to each other).
udp dport 53 redirect to :5300Catch DNS and route it through dnstc → TCP → proxy. Prevents DNS leaks.
meta l4proto tcp redirect to :12345Send all TCP to redsocks, which forwards it to your SOCKS5 proxy.
meta l4proto udp rejectBlock UDP. This kills QUIC (fast but unproxyable) and forces apps to fall back to normal TCP.
ip6 ... rejectBlock IPv6 forwarding. Most SOCKS5 proxies are IPv4-only; without this, IPv6 traffic would bypass the proxy.

2.5 Create the redirect init script

Code:
cat > /etc/init.d/redsocks-redir << 'INITEOF'
#!/bin/sh /etc/rc.common
START=91
STOP=10

start() {
    /usr/bin/redsocks-rules
}

stop() {
    nft delete table ip redsocks 2>/dev/null
}

restart() {
    /usr/bin/redsocks-rules
}
INITEOF
chmod +x /etc/init.d/redsocks-redir

2.6 Create the one-command proxy switcher

This is the killer feature — change your exit IP from your laptop in one command:

Code:
cat > /usr/bin/setproxy << 'SPEOF'
#!/bin/sh
# Usage: setproxy <ip> <port> [username] [password]
CONF=/etc/redsocks.conf
IP="$1"; PORT="$2"; LOGIN="$3"; PASS="$4"

if [ -z "$IP" ] || [ -z "$PORT" ]; then
  echo "Usage: setproxy <ip> <port> [username] [password]"
  exit 1
fi

AUTH=""
[ -n "$LOGIN" ] && AUTH="${AUTH} login = \"${LOGIN}\";
"
[ -n "$PASS" ] && AUTH="${AUTH} password = \"${PASS}\";
"

cat > "$CONF" <<EOF
base {
 log_debug = off;
 log_info = on;
 log = "syslog:daemon";
 daemon = on;
 redirector = iptables;
}

redsocks {
 local_ip = 0.0.0.0;
 local_port = 12345;

 ip = ${IP};
 port = ${PORT};

 type = socks5;
${AUTH}}

dnstc {
 local_ip = 0.0.0.0;
 local_port = 5300;
}
EOF

killall redsocks 2>/dev/null
rm -f /var/run/redsocks.pid
sleep 1
/etc/init.d/redsocks start >/dev/null 2>&1
sleep 1
/usr/bin/redsocks-rules 2>/dev/null

if pidof redsocks >/dev/null; then
  echo "OK: proxy = ${IP}:${PORT} (login: ${LOGIN:-none}). redsocks is running."
else
  echo "ERROR: redsocks failed to start. Debug:  logread | grep redsocks | tail"
  exit 1
fi
SPEOF
chmod +x /usr/bin/setproxy

2.7 Add a watchdog (auto-restart if redsocks crashes)

Code:
cat > /usr/bin/redsocks_watchdog.sh << 'WDEOF'
#!/bin/sh
if ! pidof redsocks >/dev/null 2>&1; then
    rm -f /var/run/redsocks.pid
    /etc/init.d/redsocks start >/dev/null 2>&1
    /usr/bin/redsocks-rules >/dev/null 2>&1
    logger -t redsocks_watchdog "redsocks was down -> restarted"
fi
nft list table ip redsocks >/dev/null 2>&1 || /usr/bin/redsocks-rules >/dev/null 2>&1
WDEOF
chmod +x /usr/bin/redsocks_watchdog.sh

# Run watchdog every minute
(crontab -l 2>/dev/null; echo '* * * * * /usr/bin/redsocks_watchdog.sh') | crontab -

2.8 Enable and start everything

Code:
service redsocks enable
service redsocks-redir enable
service redsocks start
/usr/bin/redsocks-rules

2.9 Test it

On any device connected to the router's WiFi, open:

2.10 Switching proxies

From your computer (Mac/Linux), swap the entire network's exit IP in one command:

Code:
# With authentication
ssh [email protected] setproxy 103.219.170.11 24283 myuser mypass

# Without authentication
ssh [email protected] setproxy 103.219.170.11 24283

The change is instant — no router reboot needed.




Part 3 (Option B): WireGuard VPN

WireGuard is a modern, fast VPN protocol. This setup routes all traffic through a commercial VPN provider.

3.1 Install WireGuard

Code:
opkg update
opkg install wireguard-tools luci-proto-wireguard

3.2 Get your config from your VPN provider

Most providers (Surfshark, Mullvad, IVPN, etc.) let you download a .conf file. It looks like this:

Code:
[Interface]
PrivateKey = YOUR_PRIVATE_KEY
Address = 10.14.0.2/16
DNS = 162.252.172.57

[Peer]
PublicKey = SERVER_PUBLIC_KEY
AllowedIPs = 0.0.0.0/0
Endpoint = us-lax.prod.surfshark.com:51820
PersistentKeepalive = 25

You'll need three values from this file:
  • PrivateKey (your key)
  • PublicKey (server's key)
  • Endpoint (server address)

3.3 Configure the WireGuard interface

Code:
# Create the WireGuard interface
uci set network.wg0=interface
uci set network.wg0.proto='wireguard'
uci set network.wg0.private_key='YOUR_PRIVATE_KEY'
uci add_list network.wg0.addresses='10.14.0.2/16'
uci set network.wg0.metric='10'

# Add the VPN server as a peer
uci set network.wg_peer0=wireguard_wg0
uci set network.wg_peer0.public_key='SERVER_PUBLIC_KEY'
uci set network.wg_peer0.endpoint_host='us-lax.prod.surfshark.com'
uci set network.wg_peer0.endpoint_port='51820'
uci set network.wg_peer0.persistent_keepalive='25'
uci add_list network.wg_peer0.allowed_ips='0.0.0.0/0'
uci set network.wg_peer0.route_allowed_ips='1'

# Save and apply
uci commit network



3.4 Add WireGuard to the firewall

WireGuard needs to be in the wan firewall zone so it can reach the internet:

Code:
# Get the current wan zone networks and add wg0
uci add_list firewall.@zone[1].network='wg0'
uci commit firewall



3.5 Set DNS to your VPN provider's servers

Using your VPN provider's DNS prevents your ISP from seeing your DNS queries:

Code:
uci set network.wg0.dns='162.252.172.57 149.154.159.92'
uci commit network

3.6 Disable IPv6 (prevents leaks)

Most VPN tunnels are IPv4-only. Without disabling IPv6, some traffic could bypass the VPN:

Code:
# Disable IPv6 system-wide
echo 'net.ipv6.conf.all.disable_ipv6=1' >> /etc/sysctl.conf
sysctl -p

# Disable the IPv6 WAN interface
uci set network.wan6.auto='0'
uci commit network

# Block IPv6 forwarding in the firewall
uci add firewall rule
uci set firewall.@rule[-1].name='Block-IPv6-Forward-Leak'
uci set firewall.@rule[-1].family='ipv6'
uci set firewall.@rule[-1].src='lan'
uci set firewall.@rule[-1].dest='wan'
uci set firewall.@rule[-1].target='REJECT'
uci commit firewall

3.7 Restart networking

Code:
/etc/init.d/network restart
/etc/init.d/firewall restart

3.8 Verify the VPN is working

Code:
# Check WireGuard status
wg show

# Check your exit IP
wget -qO- http://ifconfig.me

The IP should match your VPN provider's server, not your ISP.

On any device connected to the router, visit whatismyipaddress.com to confirm.

3.9 Switching VPN servers

To change to a different server (e.g. from US to UK):

  1. Generate a new config in your VPN provider's dashboard.
  2. Run:

Code:
uci set network.wg_peer0.public_key='NEW_SERVER_PUBLIC_KEY'
uci set network.wg_peer0.endpoint_host='uk-lon.prod.surfshark.com'
uci commit network
/etc/init.d/network restart




Bonus: Randomize Your WiFi MAC Address

Every WiFi access point broadcasts a unique MAC address (BSSID). This can be used to track your router's physical location (e.g. by Google's location services). Randomizing it on every boot adds a layer of privacy.

Code:
# Create the randomizer script
cat > /usr/bin/rand-bssid << 'RBEOF'
#!/bin/sh
RAND=$(head -c5 /dev/urandom | hexdump -v -e '/1 ":%02x"')
MAC="02${RAND}"
uci set wireless.default_radio0.macaddr="${MAC}"
uci commit wireless
wifi reload radio0 >/dev/null 2>&1
logger -t rand-bssid "Set random BSSID radio0 = ${MAC}"
RBEOF
chmod +x /usr/bin/rand-bssid

# Create init script (runs before networking starts)
cat > /etc/init.d/randbssid << 'INITEOF'
#!/bin/sh /etc/rc.common
START=15
start() {
    /usr/bin/rand-bssid
}
INITEOF
chmod +x /etc/init.d/randbssid
service randbssid enable






Troubleshooting

SOCKS5 issues

ProblemFix
No internet on devicesssh [email protected] 'logread | grep redsocks | tail' — check for proxy connection errors.
redsocks not runningssh [email protected] '/etc/init.d/redsocks restart; /usr/bin/redsocks-rules'
Check firewall rulesssh [email protected] 'nft list table ip redsocks'
DNS leakingMake sure dnstc section exists in /etc/redsocks.conf and UDP 53 redirect rule is active.
QUIC/UDP bypassing proxyThe udp reject rule should block it. Check with nft list table ip redsocks.
Nuclear optionssh [email protected] reboot

VPN issues

ProblemFix
wg show shows no handshakeCheck that endpoint_host resolves: nslookup us-lax.prod.surfshark.com. The WAN must be connected to the internet first.
Slow speedsTry a closer server. WireGuard itself adds minimal overhead.
IPv6 leakRun curl -6 ifconfig.me — it should fail. If it doesn't, revisit step 3.6.
VPN connected but no internetMake sure wg0 is in the wan firewall zone and route_allowed_ips is 1.




Security Notes

  • SSH keys: For convenience, copy your SSH public key to the router so you don't need a password:
    Code:
    ssh-copy-id [email protected]
  • Change the default password if you haven't already (passwd on the router).
  • LuCI web interface is at http://192.168.1.1 — handy for Wi-Fi settings, but all the proxy/VPN config is best done via SSH.
  • Proxy credentials are stored in plain text in /etc/redsocks.conf. The router itself is the security boundary — anyone with SSH access can read them.




Quick Reference

Code:
# === SOCKS5 ===
# Change proxy (from your Mac/PC):
ssh [email protected] setproxy IP PORT USER PASS

# Check status:
ssh [email protected] 'pidof redsocks && echo "running" || echo "stopped"'

# === WireGuard VPN ===
# Check VPN status:
ssh [email protected] wg show

# Change VPN server:
ssh [email protected] 'uci set network.wg_peer0.public_key="NEW_KEY"; \
  uci set network.wg_peer0.endpoint_host="NEW_HOST"; \
  uci commit network; /etc/init.d/network restart'

# === General ===
# What IP does the world see?
ssh [email protected] 'wget -qO- http://ifconfig.me'

# Reboot the router:
ssh [email protected] reboot




Built and tested on a Cudy WR3000 v1 running OpenWrt 24.10.5. Total cost: ~$30 for the router + your proxy/VPN subscription.

fantastic little thigs you did there
i scrolled so long my mouses stopped working
 
I do similar once I have more than 3 or 4 devices. For one phone I keep it simple, but once I need separate wifi, dns and failover rules, the router is way cleaner than touching every device one by one. Biggest win for me is swapping the upstream once and all phones follow it.
 
Great share Luke!

I have bought a few things from you.

Have you or anyone tested this to social media (IG, TikTok...)? Works fine without bans?
 
Have you or anyone tested this to social media (IG, TikTok...)? Works fine without bans?
Works

On TikTok and Snapchat tested

Compared to redsocks/shadowsocks/socksdroid where I have captchas instantly
 
Sorry to bother you with another question, my technical knowledge isn't very advanced.

With this setup, I can't make the IP change automatically; I have to do it manually, right?

Is there any way to use this setup with one of the well-known social media bots so that the bot can automatically change the IP between accounts? I mean something like airplane mode on/off or a URL that changes the IP, or...

Any advice or ideas, please?
 
With this setup, I can't make the IP change automatically; I have to do it manually, right?

if you have url from proxy provider then yes
 
Back
Top