From 3857ae0adb273f7344d434444a09f8c99be0074a Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 16 Feb 2026 14:35:09 +0200 Subject: [PATCH] openwrt polymarket without additoional packages --- .../openwrt/hotplug-iface-99-starlink-policy | 4 + linux/openwrt/openwrt-starlink-luci-setup.md | 72 +++++++++++++++- linux/openwrt/starlink-policy-route.sh | 82 +++++++++++++++++++ 3 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 linux/openwrt/hotplug-iface-99-starlink-policy create mode 100644 linux/openwrt/starlink-policy-route.sh diff --git a/linux/openwrt/hotplug-iface-99-starlink-policy b/linux/openwrt/hotplug-iface-99-starlink-policy new file mode 100644 index 0000000..0e4e460 --- /dev/null +++ b/linux/openwrt/hotplug-iface-99-starlink-policy @@ -0,0 +1,4 @@ +#!/bin/sh +# Copy to router: /etc/hotplug.d/iface/99-starlink-policy +# chmod +x /etc/hotplug.d/iface/99-starlink-policy +[ "$INTERFACE" = "wan2" ] && [ "$ACTION" = "ifup" ] && /etc/starlink-policy-route.sh setup diff --git a/linux/openwrt/openwrt-starlink-luci-setup.md b/linux/openwrt/openwrt-starlink-luci-setup.md index b0576bd..5e31845 100644 --- a/linux/openwrt/openwrt-starlink-luci-setup.md +++ b/linux/openwrt/openwrt-starlink-luci-setup.md @@ -46,7 +46,7 @@ The client connection gets an IP via DHCP from Starlink. You must create a proto - Submit. 3. On the new interface’s page: - **General Setup**: ensure "Bring up on boot" or similar is checked. - - **Firewall Settings**: assign to **wan** (same zone as your main WAN). This is required for NAT and mwan3. + - **Firewall Settings**: assign to **wan** (same zone as your main WAN). Required for NAT and for policy routing (mwan3 or the script in Part 2b). - **Save & Apply**. ### 1.4 Verify Starlink connectivity @@ -127,16 +127,83 @@ mwan3 matches by **destination IP**, not domain. You need to add the IPs (or CID --- +## Part 2b: Policy routing without mwan3 (low flash) + +If you cannot install mwan3 (e.g. only ~80 KB free on flash), you can get the same behaviour using **ip rules** and a **custom routing table**. No extra packages: uses `ip`, `resolveip`, `ubus`, `jsonfilter` (all default on OpenWrt). + +### 2b.1 Copy and run the script + +1. Copy `starlink-policy-route.sh` to the router (e.g. `/etc/starlink-policy-route.sh`). +2. Make it executable: `chmod +x /etc/starlink-policy-route.sh`. +3. Run once when wan2 is up: `/etc/starlink-policy-route.sh setup`. + +The script resolves `polymarket.com` and `www.polymarket.com` (via `resolveip`), gets wan2 gateway from `ubus`, adds a default route in table 100 via wan2, and adds `ip rule add to table 100` for each resolved IP. All other traffic keeps using the main WAN. + +### 2b.2 Run on wan2 up (hotplug) + +So routes are applied after Starlink (wan2) gets an IP, create a hotplug script: + +```bash +# On router: create /etc/hotplug.d/iface/99-starlink-policy +#!/bin/sh +[ "$INTERFACE" = "wan2" ] && [ "$ACTION" = "ifup" ] && /etc/starlink-policy-route.sh setup +``` + +Make it executable: `chmod +x /etc/hotplug.d/iface/99-starlink-policy`. + +### 2b.3 Optional: set IPs manually + +If DNS is not ready when the script runs (e.g. wan2 up before main WAN), resolve the domains on a PC and set them in the script: + +```bash +# In starlink-policy-route.sh set (replace with real IPs): +POLYMARKET_IPS="104.18.2.2 172.67.1.1" +``` + +Then the script skips `resolveip` and uses these IPs. Update them if the site stops working (CDN changes). + +### 2b.4 Remove routes + +To remove the policy routes: `/etc/starlink-policy-route.sh remove`. + +--- + +## Part 2c: Policy routing via LuCI only (static routes) + +You can achieve the same result **entirely in LuCI** without mwan3 or scripts by adding **static routes** for each Polymarket IP via wan2. More specific routes override the default route, so traffic to those IPs will use Starlink. + +### 2c.1 Get the IPs + +On a PC (or any device with DNS): run `nslookup polymarket.com` and `nslookup www.polymarket.com`. Note the IPv4 addresses (e.g. `104.18.x.x`, `172.67.x.x`). Add other hostnames you need (e.g. `gamma-api.polymarket.com`). + +### 2c.2 Add static routes in LuCI + +1. Go to **Network** → **Routes** (or **Static routes**, depending on your LuCI). +2. Click **Add** (or **Add new IPv4 route**). +3. For each Polymarket IP: + - **Target**: the IP with `/32` (e.g. `104.18.2.2/32`). + - **Gateway**: choose **Use gateway from interface** and select **wan2** (Starlink), or enter the Starlink gateway IP if your LuCI shows it. + - **Metric**: leave default (e.g. 0) or set the same as other static routes. + - Save. +4. Repeat for every IP you resolved. +5. **Save & Apply**. + +Traffic to those destinations will now go via wan2; all other traffic uses the default route (main WAN). If the site stops working later, CDN IPs may have changed—resolve the domains again and add or update the static routes in LuCI. + +--- + ## Part 3: Quick reference (LuCI locations) | Step | LuCI path | |-------------------------|-------------------------------------| | Create Starlink client | Network → Wireless → Scan → Join | -| WAN interface for WiFi | Network → Interaces → Add (DHCP, wan zone) | +| WAN interface for WiFi | Network → Interfaces → Add (DHCP, wan zone) | | Load Balancing config | Network → Load Balancing | | Interfaces (wan, wan2) | Load Balancing → Interfaces | | Policies | Load Balancing → Policies | | Rules (polymarket, default) | Load Balancing → Rules | +| Policy without mwan3 | Part 2b: script + hotplug | +| Policy via LuCI only | Part 2c: Network → Routes (static) | --- @@ -146,3 +213,4 @@ mwan3 matches by **destination IP**, not domain. You need to add the IPs (or CID - **All traffic still via main WAN**: Ensure the polymarket rule is **above** the default rule; check **Destination address** uses the correct IPs/CIDRs; ensure **starlink_only** policy uses only **wan2_m1**. - **Polymarket works then stops**: CDN IPs changed; re-resolve the domain(s) and update the rule’s destination IPs. - **LuCI "Load Balancing" missing**: Install `luci-app-mwan3` via SSH and refresh the page. +- **Using Part 2b (no mwan3)**: If polymarket stops working, CDN IPs may have changed; run `resolveip -4 polymarket.com` (or from a PC) and set `POLYMARKET_IPS` in the script, or ensure the script runs when DNS is available (e.g. after both WANs are up). diff --git a/linux/openwrt/starlink-policy-route.sh b/linux/openwrt/starlink-policy-route.sh new file mode 100644 index 0000000..9da4b3f --- /dev/null +++ b/linux/openwrt/starlink-policy-route.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# Policy routing: send traffic to specified domains via Starlink (wan2). +# No mwan3 required. Uses ip rule + custom table. Run on OpenWrt. +# Usage: run from hotplug (wan2 ifup) or manually after wan2 is up. +# Requires: ip, resolveip, ubus, jsonfilter (all default on OpenWrt). + +TABLE_ID=100 +WAN2_IF=wan2 +DOMAINS="polymarket.com www.polymarket.com" + +# Optional: set IPs manually if resolveip fails (e.g. no DNS yet). Space-separated. +# POLYMARKET_IPS="1.2.3.4 5.6.7.8" +POLYMARKET_IPS="" + +get_wan2_gw() { + local status + status=$(ubus call network.interface."$WAN2_IF" status 2>/dev/null) || return 1 + echo "$status" | jsonfilter -e '@.route[0].nexthop' 2>/dev/null +} + +get_wan2_dev() { + local status + status=$(ubus call network.interface."$WAN2_IF" status 2>/dev/null) || return 1 + echo "$status" | jsonfilter -e '@.device' 2>/dev/null +} + +resolve_domains() { + if [ -n "$POLYMARKET_IPS" ]; then + echo "$POLYMARKET_IPS" + return + fi + local list="" + for d in $DOMAINS; do + for ip in $(resolveip -4 -t 2 "$d" 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'); do + [ -n "$ip" ] && list="$list $ip" + done + done + echo "$list" | tr ' ' '\n' | sort -u | tr '\n' ' ' +} + +do_setup() { + local gw dev ips ip + gw=$(get_wan2_gw) + dev=$(get_wan2_dev) + if [ -z "$gw" ] || [ -z "$dev" ]; then + logger -t starlink-policy "wan2 not ready (gw=$gw dev=$dev)" + return 1 + fi + ips=$(resolve_domains) + if [ -z "$ips" ]; then + logger -t starlink-policy "No IPs resolved for: $DOMAINS. Set POLYMARKET_IPS in script or check DNS." + return 1 + fi + for ip in $ips; do + ip rule del to "$ip" table $TABLE_ID 2>/dev/null + done + ip route flush table $TABLE_ID 2>/dev/null + ip route add default via "$gw" dev "$dev" table $TABLE_ID + for ip in $ips; do + ip rule add to "$ip" table $TABLE_ID + done + logger -t starlink-policy "Routes via wan2 ($dev): $ips" +} + +do_remove() { + local ips ip + ips=$(resolve_domains) + for ip in $ips; do + ip rule del to "$ip" table $TABLE_ID 2>/dev/null + done + ip route flush table $TABLE_ID 2>/dev/null + logger -t starlink-policy "Removed policy routes for table $TABLE_ID" +} + +case "${1:-setup}" in + setup) do_setup ;; + remove) do_remove ;; + *) + echo "Usage: $0 [setup|remove]" + exit 1 + ;; +esac