<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[zainras]]></title><description><![CDATA[zainras]]></description><link>https://blog.zainras.com</link><generator>RSS for Node</generator><lastBuildDate>Mon, 25 May 2026 03:06:25 GMT</lastBuildDate><atom:link href="https://blog.zainras.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Turn On Mobile Broadband Data Connection on Ubuntu 22.04 from the Terminal]]></title><description><![CDATA[In a nutshell, I have an older laptop equipped with a built-in mobile data connection. Currently, I've repurposed this laptop as a home lab and installed Ubuntu 22.04 LTS as the operating system. However, I've encountered an issue where the mobile da...]]></description><link>https://blog.zainras.com/how-to-turn-on-mobile-broadband-data-connection-on-ubuntu-2204-from-the-terminal</link><guid isPermaLink="true">https://blog.zainras.com/how-to-turn-on-mobile-broadband-data-connection-on-ubuntu-2204-from-the-terminal</guid><category><![CDATA[Ubuntu]]></category><dc:creator><![CDATA[Zain Rasyid]]></dc:creator><pubDate>Thu, 07 Sep 2023 10:34:42 GMT</pubDate><content:encoded><![CDATA[<p>In a nutshell, I have an older laptop equipped with a built-in mobile data connection. Currently, I've repurposed this laptop as a home lab and installed Ubuntu 22.04 LTS as the operating system. However, I've encountered an issue where the mobile data connection occasionally turns off on its own. To ensure a more reliable connection, I've been actively exploring ways to control the toggling of the mobile data, both on and off, through scripts or the terminal.</p>
<p>After conducting several internet searches, I discovered a solution using the <code>nmcli</code> command. <code>nmcli</code> is a powerful command-line tool designed for managing NetworkManager and providing detailed network status reports. It serves as a versatile alternative to graphical clients like 'nm-applet.' With <code>nmcli</code>, you can effortlessly create, display, edit, delete, activate, and deactivate network connections. Additionally, it provides comprehensive control and status information for network devices.</p>
<h3 id="heading-step-1-identify-your-mobile-broadband-interface">Step 1: Identify Your Mobile Broadband Interface</h3>
<p>Before you proceed with configuring the mobile data connection, it's crucial to pinpoint the name of your mobile data connection interface. Keep in mind that this interface name may vary depending on your specific system and hardware configuration. To locate it, open a terminal and execute the following command:</p>
<pre><code class="lang-bash">nmcli connection show
</code></pre>
<p>This will display a list of all the network connections configured on your system.</p>
<p>Look for the active mobile broadband connection in the list. It will typically have a name like "Default" or something similar. To quickly identify it, look for "gsm" in the "TYPE" column of the output.</p>
<p>For example:</p>
<pre><code class="lang-plaintext">NAME               UUID                                  TYPE      DEVICE
Wired connection 1  12345678-1234-1234-1234-1234567890ab  ethernet  eth0
Default             98765432-5678-5678-5678-0987654321cd  gsm       wwan0  activated
</code></pre>
<p>In the above example, "Default" is the active mobile broadband connection. To ensure that the indicator you plan to use can successfully toggle your connection, you can test it with the following commands:</p>
<p>To turn off the connection:</p>
<pre><code class="lang-plaintext">nmcli connection down Default
</code></pre>
<p>And to turn it back on:</p>
<pre><code class="lang-plaintext">nmcli connection up Default
</code></pre>
<p>Remember that "Default" is the interface name associated with your mobile broadband connection. These commands should help you verify if your indicator is working correctly.</p>
<p>If the commands mentioned earlier are effective, the next step involves creating automated scripts to monitor and promptly reestablish the mobile data connection if it happens to turn off. This approach ensures that your laptop maintains a consistent and reliable internet connection.</p>
<h3 id="heading-step-2-create-a-reconnection-script">Step 2: Create a Reconnection Script</h3>
<p>To automate the process of checking and reconnecting your mobile broadband data connection, we'll create a simple shell script. Open your favorite text editor and create a new file. For example:</p>
<pre><code class="lang-bash">nano reconnect_mobile.sh
</code></pre>
<p>Now, paste the following code into the script:</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>

CONNECTION_NAME=<span class="hljs-string">"YOUR_INTERFACE_NAME"</span>

<span class="hljs-comment"># Check if the mobile data connection is active</span>
<span class="hljs-keyword">if</span> nmcli connection show --active | grep -q <span class="hljs-string">"<span class="hljs-variable">$CONNECTION_NAME</span>"</span>; <span class="hljs-keyword">then</span>
    <span class="hljs-comment"># Mobile data connection is already active, no need to log anything</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Mobile data connection is already active"</span>
    <span class="hljs-built_in">exit</span> 0
<span class="hljs-keyword">else</span>
    <span class="hljs-comment"># Mobile data connection is not active. Reconnecting...</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Mobile data connection is not active. Reconnecting..."</span>
    nmcli connection up <span class="hljs-string">"<span class="hljs-variable">$CONNECTION_NAME</span>"</span>

    <span class="hljs-comment"># Check if the connection was successfully established</span>
    <span class="hljs-keyword">if</span> [ $? -eq 0 ]; <span class="hljs-keyword">then</span>
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Mobile data connection reestablished successfully."</span>
    <span class="hljs-keyword">else</span>
        <span class="hljs-built_in">echo</span> <span class="hljs-string">"Failed to reconnect mobile data connection."</span>
    <span class="hljs-keyword">fi</span>
<span class="hljs-keyword">fi</span>
</code></pre>
<p>Replace <code>YOUR_INTERFACE_NAME</code> with the actual name of your mobile broadband interface that you noted down in Step 1. Save the file and make it executable with the following command:</p>
<pre><code class="lang-bash">chmod +x reconnect_mobile.sh
</code></pre>
<h3 id="heading-step-3-run-the-script">Step 3: Run the Script</h3>
<p>To manually run the script and reconnect your mobile broadband, execute:</p>
<pre><code class="lang-bash">sudo ./reconnect_mobile.sh
</code></pre>
<p>If your mobile data connection is down, the script will attempt to bring it back up and restore your internet access. You'll receive status messages indicating whether the process was successful or not</p>
<p>To wrap things up, these steps give you more power over your mobile broadband connection in Ubuntu 22.04. By using the command line and setting up scheduled tasks with <code>cron</code>, you can keep your internet running like a charm. No more interruptions while you're in the zone. Now you can just get on with your stuff and stay seamlessly connected wherever you take your Mobile broadband Ubuntu 22.04 setup!"</p>
]]></content:encoded></item></channel></rss>