LinkedIn Sourceforge

Vincent's Blog

Pleasure in the job puts perfection in the work (Aristote)

No More Outage Panic: How I Added Auto-Switching 4G to My Router Setup

Posted on 2025-10-18 14:06:00 from Vincent in OpenBSD

Tired of your WiFi vanishing mid call, leaving you staring at a spinning wheel of movie? I've been there—furious, fumbling for my phone's hotspot like it's 2015. But no more. I just wired up a sneaky 4G sidekick: the TP-Link MR600. It's like a ninja router—silent, speedy, and ready to swoop in when your ISP flakes out. One ping fails? Boom. Traffic flips to cellular backup in seconds. No drama, no downtime. All powered by some clever OpenBSD magic that makes it feel effortless.


photo from https://unsplash.com/@jeshoots

Boosting My Home Network: Adding a Simple 4G Backup with a TP-Link Router

Hey everyone, thanks for stopping by my blog. If you've read my posts before, you know I love messing around with home tech to make things run smoother—especially when it comes to staying connected. Lately, I've been dealing with spotty internet from my main provider, and it's been a pain during work calls or movie nights. So, I decided to add a backup plan: a TP-Link MR600 router that uses 4G as a safety net. Now, if my regular internet goes down, everything switches over automatically. No more yelling at the modem or hotspotting from my phone. Let me walk you through how I set it up—it's easier than it sounds.

The whole thing uses a free tool built into my main computer setup (OpenBSD, if you're curious) to watch for problems and flip the switch. Total cost? Under $100 for the router, plus a cheap data plan. Let's get into it.

Why Add a 4G Backup?

Look, my internet is fine most days, but when it drops—maybe a storm, a cut line, or just bad luck—it's frustrating. In my home office, I need reliable WiFi for work, streaming, and keeping an eye on my smart home stuff. A 4G backup means I don't have to stop what I'm doing. I picked the TP-Link MR600 because it's straightforward, supports fast 4G speeds (up to 300Mbps download), and doesn't need a ton of setup. I grabbed a basic SIM card from a budget phone plan—just for emergencies, so it won't eat up my data.

The key? I kept it simple. No extra wireless networks or address handoffs that could cause headaches. It's just there, waiting to jump in.

Setting Up the TP-Link MR600: Keep It Basic

This little router is plug-and-play once you tweak a few things. I popped in the SIM card, connected it to my network with an Ethernet cable, and logged into its settings (the web address is 192.168.0.254 by default). Here's what I changed:

  • Turned Off WiFi: I already have my own wireless setup, so no need for this to broadcast its own signal.
  • Turned Off DHCP: That's the thing that hands out IP addresses to devices. My main router does that job, so this avoids mix-ups.
  • Set It to 4G Only: Locked it to LTE for the best speeds—no falling back to slower 3G.
  • Gave It a Fixed Address: I set it to 192.168.0.100 on my network. Think of it like giving it a permanent spot in the lineup, next to my main router at 192.168.0.1.

That's it for the router. I plugged its output into a switch, and it's ready to go as my backup gateway.

Organizing My Network: A Bit of Separation for Safety

I like to keep my home network organized into "zones" (tech folks call them VLANs) to make it more secure and tidy. It's like having different rooms in your house—one for the front door (internet entry points) and one for the office gear.

  • Main Zone (VLAN 10): This is where my ISP router (192.168.0.1) and the 4G backup (192.168.0.100) hang out. All outgoing internet traffic starts here.
  • Office Zone (VLAN 20): My computers and stuff are on 192.168.3.0—my main desktop is at 192.168.3.1, for example.

My central computer (running the firewall) connects these zones, so office devices can reach the internet but can't poke around where they shouldn't. If you're not into this level of setup, you can skip the zones and just wire everything to the same switch—it'll still work.

The Smart Switch: Using ifstated to Auto-Swap Connections

Here's the cool part: automation. I use a built-in tool called ifstated on my main router computer. It constantly checks if my primary internet is working by sending a quick "hello" ping to a reliable site (like Google's DNS). If it gets no response, it changes the path to go through the 4G router instead. When the main one comes back, it switches over again. All without me lifting a finger.

I put this setup in a simple config file (/etc/ifstated.conf). Don't worry if code looks scary—I'll explain it step by step after showing it:

init-state start

# Ping test checking connectivity via cluster IP 192.168.3.1 source
publicip_check = '( "ping -q -c 3 -w 2 -S 192.168.3.1 <my-public-ip> " every 10 )'
internet_check = '( "ping -q -c 3 -w 2 -S 192.168.3.1 1.1.1.1 > /dev/null" every 10 )'
carp_master = '( "ifconfig carp10 | grep status: | grep master > /dev/null" every 10 )'

# in ifstated.conf  we leave the module at the 1st valid condition
state start {
    if $publicip_check && $carp_master {
        set-state primary
    }
    if $carp_master {
        set-state backup
    }
    set-state iddle
}

state primary {
    init {
        run "logger -t ifstated 'Switching to PRIMARY route 192.168.0.1'"
        run "/sbin/route delete default"
        run "/sbin/route add default 192.168.0.1"
        run "arp -d 192.168.0.1"
        run "echo 'Default route switched to primary via 192.168.0.1 ' | mail -s 'Default Route Change: Primary' root"
    }
    if ! $carp_master {
        set-state iddle
    }
    if ! $publicip_check && ! $internet_check {
        # we switch in case both public ip and internet are not reachable
        set-state backup
    }
}

state backup {
    init {
        run "logger -t ifstated 'Switching to SECONDARY route 192.168.0.100'"
        run "/sbin/route delete default"
        run "/sbin/route add default 192.168.0.100"
        run "arp -d 192.168.0.100"
        run "(printf 'Default route switched to backup via 192.168.0.100.'  | mail -s 'Default Route Change: Backup' root"
    }
    if ! $carp_master {
        set-state iddle
    }
    # if primary public IP is alive, restore primary route
    if $publicip_check {
        set-state primary
    }
}

state iddle {
    init {
        run "logger -t ifstated 'Switching to iddle because backup node'"
    }
    if $carp_master && $publicip_check {
        set-state primary
    }
    if $carp_master {
        set-state backup
    }
}

What This Does, Plain and Simple

start -> primary if CARP master and public IP OK
start -> backup if CARP master but public IP fails
start -> iddle otherwise
primary -> backup if both public IP and internet fail
primary -> iddle if not CARP master
backup -> primary if public IP becomes OK
backup -> iddle if not CARP master
iddle -> primary if CARP master + public IP OK
iddle -> backup if CARP master but public IP fails

To turn it on: Save the file, run a couple commands to start the service, and you're set. Check the logs to see it in action.

rcctl start ifstated

Note: Avoid to ping a public IP like 8.8.8.8 because you will have ping-pong effect. Indeed, once the 4G connection is setup, 8.8.8.8 will be reachable, so ifstated will try to restore the isp route.
Pinging the internal ISP router is neither a good idea because in case of link troubles, this IP remains valid.

How It Feels in Everyday Use

Normally, everything flies through my fast home internet. If there's an outage, the switch happens in a few seconds—you might notice a quick pause on a video, but that's it. My office stuff keeps chugging along because the firewall handles the handoff.

To test: Just unplug the main internet cable. You'll get an email saying it's on backup. Plug it back in, and it'll notify you of the switch. Uplinks on 4G are slower (around 10-20Mbps up), so it's perfect for backups, not full-time use. I also watch my data usage to stay under limits.

Final Thoughts: More Reliable Days Ahead

Thanks to OpenBSD's incredible flexibility, getting this failover up and running boiled down to just one simple ifconfig command to tweak the routes, with the built-in ifstated handling all the automation like a pro. It's a reminder of why I love this OS—powerful tools right out of the box, no extra software needed. Now my network feels unbreakable, and outages are just a minor blip. If you're dealing with unreliable internet and want to try something similar, dive in—it's rewarding and not as tricky as it seems. Start with the basics, and tweak as you go.

Got questions or your own tweaks? Drop them in the comments—I'd love to chat. Thanks for reading!



0, 0
displayed: 2910



What is the second letter of the word Python?