{"id":6396,"date":"2026-01-03T19:41:27","date_gmt":"2026-01-03T19:41:27","guid":{"rendered":"https:\/\/cybersecurityinfocus.com\/?p=6396"},"modified":"2026-01-03T19:41:27","modified_gmt":"2026-01-03T19:41:27","slug":"router-auto-config-after-reset","status":"publish","type":"post","link":"https:\/\/cybersecurityinfocus.com\/?p=6396","title":{"rendered":"Router Auto-Config After Reset"},"content":{"rendered":"<h2>TL;DR<\/h2>\n<p>This guide shows you how to automatically reconfigure your router after a factory reset using Dynamic DNS (DDNS) and a script that runs on startup. This means you don\u2019t have to manually update settings every time.<\/p>\n<h2>Steps<\/h2>\n<p><strong>Understand the Problem<\/strong><\/p>\n<p>When a router resets, it loses its configuration, including your port forwarding rules and any custom DNS settings. This guide automates restoring those settings.<\/p>\n<p><strong>Choose a Dynamic DNS (DDNS) Provider<\/strong><\/p>\n<p>DDNS services give you a consistent domain name even if your IP address changes. Popular options include No-IP, DynDNS, and DuckDNS. For this example, we\u2019ll assume you\u2019ve chosen DuckDNS as it\u2019s free.<\/p>\n<p>Create an account on <a href=\"https:\/\/www.duckdns.org\/\">DuckDNS<\/a>.<br \/>\nAdd a domain name (e.g., myrouter.duckdns.org).<br \/>\nNote your token and domain name \u2013 you\u2019ll need these later.<\/p>\n<p><strong>Configure Your Router for DDNS<\/strong><\/p>\n<p>Most routers have built-in DDNS support. The exact steps vary by router model, but generally:<\/p>\n<p>Log in to your router\u2019s web interface (usually 192.168.1.1 or 192.168.0.1).<br \/>\nFind the DDNS settings section (often under Advanced Settings, WAN, or Dynamic DNS).<br \/>\nEnter your DuckDNS domain name and token.<br \/>\nSave the changes.  Your router should now automatically update its IP address with DuckDNS.<\/p>\n<p><strong>Create a Configuration Script<\/strong><\/p>\n<p>This script will run after each reboot to restore your desired settings.<\/p>\n<p>The script language depends on your router\u2019s firmware. Many routers support shell scripts (.sh) or Lua. We\u2019ll use a shell script for this example.<br \/>\nCreate a file named router_config.sh with the following content, replacing placeholders with your actual values:<\/p>\n<p>#!\/bin\/sh<\/p>\n<p># Your DuckDNS token and domain name<br \/>\nTOKEN=&#8221;YOUR_DUCKDNS_TOKEN&#8221;<br \/>\nDOMAIN=&#8221;myrouter.duckdns.org&#8221;<\/p>\n<p># Get the current public IP address<br \/>\nIP=$(curl -s https:\/\/api.ipify.org)<\/p>\n<p># Update DuckDNS record<br \/>\ncurl -s &#8220;https:\/\/www.duckdns.org\/update?domains=$DOMAIN&amp;token=$TOKEN&amp;ip=$IP&#8221; &gt; \/dev\/null<\/p>\n<p># Restore port forwarding rules (example for port 80 to internal IP 192.168.1.10)<br \/>\npfctl -a &#8220;rdr pass on eth0 proto tcp from any to any port 80 -&gt; 192.168.1.10 port 80&#8221; <\/p>\n<p># Restore custom DNS settings (example using nsupdate, requires configuration in \/etc\/nsupdate.conf)<br \/>\n# nsupdate -f \/etc\/nsupdate.conf<\/p>\n<p>echo &#8220;Router config updated successfully!&#8221;<\/p>\n<p><strong>Important:<\/strong> The pfctl command is specific to OpenBSD-based routers (like some ASUS models). Adjust this part of the script based on your router\u2019s firewall configuration.<\/p>\n<p><strong>Configure Router Startup Script Execution<\/strong><\/p>\n<p>This step tells your router to run the router_config.sh script automatically after each reboot.<\/p>\n<p>Again, this varies by router model. Look for a section in the web interface called \u201cStartup Scripts\u201d, \u201cCustom Commands\u201d, or similar.<br \/>\nAdd the following command:<\/p>\n<p>\/path\/to\/router_config.sh<\/p>\n<p>Replace \/path\/to\/router_config.sh with the actual location of your script on the router\u2019s filesystem.<\/p>\n<p><strong>Test Your Configuration<\/strong><\/p>\n<p>Reboot your router.<br \/>\nCheck that your DDNS record is updated correctly on DuckDNS (or your chosen provider).<br \/>\nVerify that port forwarding rules are working as expected.<br \/>\nIf there are errors, check the script\u2019s output (if available) or examine the router\u2019s system logs for clues.<\/p>\n<h2>Troubleshooting<\/h2>\n<p><strong>Script Permissions:<\/strong> Ensure the script has execute permissions. You might need to use SSH to connect to your router and run chmod +x \/path\/to\/router_config.sh.<br \/>\n<strong>Firewall Rules:<\/strong> Double-check that your firewall rules allow outbound connections for DDNS updates (usually port 80 or 443).<br \/>\n<strong>Script Errors:<\/strong> Carefully review the script for typos and incorrect commands. Use SSH to connect to the router and run the script manually to see any error messages.<\/p>\n<p>The post <a href=\"https:\/\/blog.g5cybersecurity.com\/router-auto-config-after-reset\/\">Router Auto-Config After Reset<\/a> appeared first on <a href=\"https:\/\/blog.g5cybersecurity.com\/\">Blog | G5 Cyber Security<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>TL;DR This guide shows you how to automatically reconfigure your router after a factory reset using Dynamic DNS (DDNS) and a script that runs on startup. This means you don\u2019t have to manually update settings every time. Steps Understand the Problem When a router resets, it loses its configuration, including your port forwarding rules and [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-6396","post","type-post","status-publish","format-standard","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts\/6396"}],"collection":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6396"}],"version-history":[{"count":0,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=\/wp\/v2\/posts\/6396\/revisions"}],"wp:attachment":[{"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cybersecurityinfocus.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}