Who this is for: what an OpenWrt side gateway actually solves

If your home already has a perfectly serviceable primary router, replacing it is often the highest-risk way to add proxy policy. A side gateway is the opposite mindset. You keep the primary router boring and stable, then place one OpenWrt device on the same LAN to act as a controlled second hop for the devices that need Clash or Mihomo. That could be a small x86 box, a repurposed router, or any always-on OpenWrt appliance with enough flash and memory to hold the core, rule caches, and logs. The point is not to seize the WAN role. The point is to centralize routing rules, DNS decisions, and traffic capture for the clients you deliberately point at that box.

This pattern is especially useful when the devices that need policy routing are the devices that are hardest to configure individually. TVs, game consoles, streaming boxes, and some phones may have limited proxy controls, inconsistent DNS settings, or no support for per-app routing. Once the OpenWrt box becomes their default gateway, TUN and DNS logic can happen one layer below the application, which makes behavior much more consistent. If you already understand the networking ideas from the container-based walkthrough in Docker Clash side gateway and port mapping, this article translates the same topology discipline into a native OpenWrt environment.

The crucial shift is operational. In a side-gateway design, you are now managing two authorities on the same LAN: the primary router, which may still hand out addresses and provide the baseline route to the internet, and the OpenWrt side box, which selectively becomes the new default gateway and DNS path for chosen clients. Most breakage in this model is not mysterious. It usually comes from failing to define which box owns DHCP, which box answers DNS, whether IPv6 is still escaping through the primary router, or whether the OpenWrt box is accidentally forwarding queries back into itself. Once those roles are written down clearly, OpenWrt plus Clash stops feeling magical and starts feeling maintainable.

Topology first: primary router, side box, and the real default gateway

The cleanest side-gateway deployment starts with a small table, not a package install. Write down your LAN subnet, the primary router IP, the future OpenWrt side-gateway IP, and the list of devices that should use it. In most homes that table might look like 192.168.1.0/24, primary router 192.168.1.1, side OpenWrt 192.168.1.2 or 192.168.1.10, and a shortlist such as Apple TV, PlayStation, two phones, and one test laptop. This sounds basic, but it keeps you from making the most common category of mistake: editing DNS, TUN, and firewall rules before you even know which path packets are supposed to take.

A side gateway is not a second NAT island unless you intentionally make it one. In the most stable version, the OpenWrt device lives on the same LAN as the primary router and gets a fixed IP, ideally via DHCP reservation on the primary router. Only the clients you choose will use that IP as their default gateway and, depending on your DNS plan, also as their DNS target. That means the rest of the household remains on the normal path. If the side box reboots or you are testing a risky config change, you only interrupt the devices you explicitly moved onto it. This rollback property is the real value of the pattern, and it is why many people prefer it to making OpenWrt the one true router on day one.

For living-room devices that must remain on the same broadcast domain for casting, game discovery, or local media access, keeping everything inside one LAN is often the least painful option. If you are planning a setup for a streaming device, the companion article on Apple TV on a side gateway with same-LAN DNS shows how that same principle works in a client-specific scenario. The lesson carries back here: before TUN, before fake-ip, before any advanced rule provider, decide what the gateway should be for each device and whether the DNS server should follow the same path.

OpenWrt preparation: firmware, storage, and package strategy

OpenWrt is flexible, but small routers remain small routers. Before you install a Clash-family core, confirm that your hardware can survive the job. You need room for the binary, subscriptions or rule providers, optional Geo data, and logs that are actually useful when you are debugging. A device that is fine as a plain access point may become fragile once you add a large ruleset and transparent traffic handling. If flash is tight, you may need extroot or external storage. If RAM is tight, over-aggressive debug logging or heavyweight DNS modes can become a problem long before the CPU becomes the bottleneck.

You should also know whether your OpenWrt build uses older firewall conventions or fw4 with nftables. Side-gateway behavior is less about the GUI and more about how routing, forwarding, and DNS interception interact under the hood. TUN setup steps that look harmless on one release may need a slightly different mental model on another because route insertion and firewall defaults are not identical. That is why it helps to treat the deployment as three layers: the core binary and config, the service manager that starts it at the right time, and the OpenWrt networking stack that must permit it to capture or forward traffic.

One more practical rule: do not enable multiple services that all want to own transparent routing. If the router already has another proxy package, redirection script, VPN client, or DNS hijack rule that manipulates routes, pick one architecture and disable the rest. Many “OpenWrt Clash broke everything” stories are really “two separate tools both believed they controlled the default route.” Keeping the system minimal makes later upgrades easier too. When you eventually compare config changes against the Clash Meta and Mihomo upgrade guide, fewer moving parts mean fewer surprises.

Install the core: config, working directory, and the minimum viable connectivity test

Before you touch TUN, make the core work in the simplest possible way. Put the binary and configuration in a predictable location, confirm the service can start after networking is ready, and verify that the config syntax is valid. The first milestone is not “all clients on the LAN are now proxied.” The first milestone is “the OpenWrt box itself can load the config, reach the subscription or rule sources, and make successful outbound connections through the selected node.” If you skip this step, every failure later becomes ambiguous: was it the node, the YAML, the route table, or DNS?

A low-risk path is to start with a mixed port or separate HTTP and SOCKS listeners, then test locally from the OpenWrt device with explicit commands. If curl -x or another manual probe cannot use the core from the box itself, there is no value in enabling transparent capture yet. Fix the obvious layer first. Watch the logs long enough to see that the service stays up, listeners bind as expected, and rule providers refresh cleanly. Only after this basic path is stable should you involve other clients on the LAN.

Rule order matters even more once you later feed whole-device traffic into the engine. Put the most specific rules above broad fallbacks, keep MATCH at the end, and verify that private subnets and router management addresses are not accidentally pushed into proxy policies. If you are upgrading from older samples or tutorial fragments copied months ago, compare deprecated keys and new behaviors with the Mihomo upgrade notes. It is much cheaper to resolve schema drift now than after TUN magnifies a small mistake into a house-wide outage.

Enable TUN on OpenWrt: interface, routing, and firewall cooperation

TUN mode is what makes a side gateway truly useful for clients that cannot or will not speak an application proxy. Conceptually, it allows the operating system to pass matching IP traffic into the Clash or Mihomo core so that routing policy applies below the app layer. On OpenWrt, however, turning on TUN is not a checkbox you should trust blindly. You need to verify three things at once: the tun section in the config, the system’s ability to create and manage the tun interface, and the firewall or forwarding rules that let traffic come in from the LAN and leave toward the primary router or upstream path.

Once TUN is enabled, inspect the system immediately. Look at ip route, ip rule, and the actual presence of the tun interface. Reboot the service once to ensure the interface is recreated cleanly and that startup ordering does not cause a race with networking. If another package previously installed policy routing rules, you may see priority conflicts or duplicate rules. These are not cosmetic. A single bad rule can send the router’s own DNS queries into a loop, or cause the OpenWrt device to proxy traffic that should have remained local.

IPv6 deserves special suspicion during this phase. Many devices prefer IPv6 when it is available, which means you can think TUN is working because some IPv4 traffic is following the new route while the actual app traffic escapes over IPv6 through the primary router. The symptom often looks like “some domains ignore the rules” or “speed tests seem inconsistent.” During rollout, it is reasonable to temporarily narrow IPv6 exposure, disable it on a test client, or make the DNS and RA behavior conservative until the IPv4 path is unquestionably correct. For the broader theory and cross-platform pitfalls, keep the companion guide on Clash TUN mode and global traffic nearby.

DNS chain design: dnsmasq, Clash listening ports, and the fake-ip trade-off

The routing layer gets most of the attention, but DNS is where side gateways actually fail. The ideal chain is simple and one-way: client asks the OpenWrt box, OpenWrt forwards the query to the Clash DNS listener, Clash decides how to resolve it upstream, then the answer returns to the client. If any link points backward, you create a recursion loop. If the client uses one DNS path but packets are routed along another, your rules become impossible to reason about. If the OpenWrt host itself uses a different resolver path from the clients, you can spend hours debugging “works on the router, fails on the TV” behavior that is really just split DNS.

On OpenWrt, dnsmasq often already owns port 53, so the common design is to keep clients aimed at the OpenWrt LAN IP and have dnsmasq forward upstream queries to the Clash core on a local listening port. That keeps DHCP and local name handling on the router while still giving Clash the last meaningful word on upstream resolution. The failure mode to avoid is letting Clash send its upstream DNS back to the same dnsmasq listener that forwarded the query in the first place. The visual symptom is classic: you can ping raw IP addresses, but normal websites fail or hang because the name never resolves cleanly.

Be conservative with fake-ip until the basic chain is stable. Fake-IP can be useful, but in living-room networks it can also collide with stale caches, device quirks, or services that react badly when names map to synthetic addresses for too long. Starting with a more literal resolution mode gives you a cleaner baseline. Once that works, you can experiment upward. If a client shows the dreaded “connected but no internet” message even though the node is healthy, follow the layered logging workflow from the log, DNS, and rule troubleshooting guide and include every OpenWrt forwarding hop in your checklist.

Make clients really use the side gateway: manual settings, reservations, and DHCP options

For phones and laptops, changing the gateway and DNS directly in the Wi-Fi details is often enough for testing. For TVs and consoles, the settings may be called router, default gateway, primary DNS, or manual network mode. The exact labels differ, but the requirement is always the same: the device must actually send traffic to the OpenWrt side box first. If you want only a few devices to use the proxy path, resist the temptation to change the default gateway for the entire LAN in one shot. That removes your rollback safety net and turns a small experiment into a whole-house cutover.

A more controlled approach is to use DHCP reservations or per-device DHCP options so that only selected MAC addresses receive the side-gateway IP as option 3 and the corresponding DNS plan as option 6. Router interfaces vary wildly, but the design principle is universal: gateway and DNS should describe the same path. If the device uses the side gateway for routing but a random public DNS directly, your policy outcomes become inconsistent. Likewise, if a browser enables its own DoH while the rest of the system uses the local DNS chain, web tests may hide the real network path. Always verify with at least two different types of clients or services.

This is also where documentation saves time. Keep a small note of which devices are manual, which rely on DHCP, and which are supposed to stay on the primary router. A home network becomes hard to reason about once nobody remembers whether a TV was pointed at the side gateway three months ago for one test and never switched back. If you want a permanent reference point for route concepts and client behavior, the broader documentation hub is the right place to keep bookmarked alongside this article.

Troubleshoot outages and odd symptoms: split the problem before you fix it

When the side gateway misbehaves, do not treat the whole network as one problem. Split it. If the OpenWrt box itself has internet access but all clients fail, check forwarding, firewall permissions, client subnet masks, and any AP isolation setting before you blame the node or subscription. If the router can resolve domains but the client cannot, trace the DNS chain hop by hop with direct queries. If enabling TUN causes the whole setup to collapse instantly, disable TUN, return to explicit local port testing, and confirm the core is still healthy before you look at route tables again. One variable at a time is not a nice-to-have here; it is the only way to avoid chasing ghosts.

Performance issues deserve their own branch of the checklist. Slow streaming or intermittent failures are often about MTU, UDP and QUIC handling, overloaded nodes, or an IPv6 path that remains outside the intended policy. Keep test conditions narrow: one device, one node, one DNS mode, one route change. Record what you changed and how to reverse it. A side gateway should be maintained like infrastructure, even in a home. The smaller your changes, the easier it is to recover.

Over time, the best defense against configuration drift is a short operational notebook containing your topology diagram, reserved IP list, DNS chain, and the answer to one question: which box is currently authoritative for each role? Once that note exists, it becomes far easier to upgrade the core, compare behaviors across releases, or decide whether a given issue belongs to OpenWrt, the Clash config, or a specific client. The point of a side gateway is not to make the network more clever. It is to make advanced routing possible without giving up a predictable way back.

Network proxy tools can support legitimate privacy, development, testing, and remote-work use cases, but they should not be used to bypass laws, service terms, workplace policies, or access restrictions that apply in your environment. Verify the rules that govern the network you are on before deployment.
You can check open-source core releases, issues, and source history on GitHub when you need technical background. For actual desktop or mobile client downloads, use the official download page on this site as the primary entry point, then use repository pages separately for source and licensing context.

Closing: the best side gateway is the one with safe defaults and an easy rollback

A good OpenWrt side gateway is valuable not because it is clever, but because it gives you controlled policy without gambling the whole household on one experimental router state. Keep the primary path stable, move selected devices to the side gateway deliberately, align TUN and DNS as one design instead of two disconnected tweaks, and most “mysterious” outages turn into ordinary configuration mismatches that can be fixed methodically.

Compared with scattering incompatible proxy settings across individual devices, centralizing the policy on one OpenWrt box usually lowers maintenance cost once the topology is documented and the DNS path is clean. If you want that same rule logic available on laptops and phones outside the house as well, download Clash from the official site and build from one consistent toolchain.

→ Download Clash for free and experience the difference