Software & AppsOperating SystemLinux

How To Share Internet via USB from Ubuntu 20.04 to Android 6.0.1 and 10

Ubuntu 18

In this in-depth guide, we will walk through the process of sharing an internet connection from an Ubuntu 20.04 system to Android devices running versions 6.0.1 and 10. This process, also known as “reverse tethering”, can be particularly useful when you have a wired internet connection on your Ubuntu system but no Wi-Fi network to share it with your Android devices.

Quick Answer

It is possible to share internet via USB from Ubuntu 20.04 to Android devices running versions 6.0.1 and 10 using a tool called gnirehtet. This process, also known as "reverse tethering", allows your Android devices to use the internet connection of your Ubuntu system.

Prerequisites

Before we begin, ensure that you have the following:

  • An Ubuntu 20.04 system with an active internet connection (preferably wired).
  • Android devices running versions 6.0.1 or 10.
  • USB cables to connect your Android devices to your Ubuntu system.

Step 1: Install Necessary Tools

Firstly, we need to install a tool called gnirehtet on our Ubuntu system. This tool provides reverse tethering for Android, allowing the Android device to use the internet connection of the host machine.

To download gnirehtet, visit the official GitHub repository here. Extract the downloaded file to a location of your choice.

Additionally, ensure that you have adb (Android Debug Bridge) installed on your Ubuntu system. If not, you can install it using the following command:

sudo apt-get install adb

The adb tool is a versatile command-line tool that lets you communicate with an emulator instance or connected Android device.

Also, enable USB debugging on your Android devices. You can do this by going to Settings > Developer options > USB debugging.

Step 2: Run Gnirehtet

Open a terminal and navigate to the directory where you downloaded gnirehtet. Run the following command to start the reverse tethering service:

./gnirehtet run

In this command, ./gnirehtet is the path to the gnirehtet executable, and run is the command to start the service.

Step 3: Configure Android Devices

On your Android devices, navigate to Settings > Network connection > Tethering and portable hotspot > USB-PC internet share. Choose the appropriate OS suggested (usually different Windows versions). This action will enable the USB internet sharing functionality on your devices.

Step 4: Retrieve Network Information

To complete the setup, you need to retrieve the subnet and default gateway information that your Android devices are using. You can use tools like tcpdump on your Ubuntu system to capture the traffic from the USB network interface.

To install tcpdump, use the following command:

sudo apt-get install tcpdump

Then, run tcpdump to capture traffic:

sudo tcpdump -i <usb_tethering_interface> -n

In this command, -i specifies the interface, and -n prevents tcpdump from resolving hostnames.

Look for the default gateway IP address in the captured traffic.

Step 5: Configure Ubuntu Network Interface

Once you have the default gateway IP address, add it to the tethering interface on your Ubuntu system using the following command:

sudo ip address add <gateway_ip> dev <tethering_interface>

In this command, <gateway_ip> is the default gateway IP address you retrieved earlier, and <tethering_interface> is the network interface used for tethering.

Alternatively, you can use Network Manager to configure the interface.

Step 6: Enable Masquerading

Enable masquerading with iptables to allow internet sharing. Run the following command to set up masquerading:

sudo iptables -A POSTROUTING -o <usb_tethering_interface> -j MASQUERADE

In this command, -A appends the rule to the POSTROUTING chain, -o specifies the output interface, and -j MASQUERADE sets the target of the rule to MASQUERADE.

Step 7: Set Up DNS Server

Finally, make sure you have a DNS server set up on your Ubuntu system. You can use a lightweight DNS server like dnsmasq for quick setup.

To install dnsmasq, use the following command:

sudo apt-get install dnsmasq

Then, configure dnsmasq to use your preferred DNS servers.

That’s it! You should now be able to share your Ubuntu system’s internet connection with your Android devices via USB.

Please note that there may be additional driver requirements for your specific Android devices. Ensure that the necessary drivers are installed and compatible with Ubuntu.

For more detailed instructions and troubleshooting tips, you can refer to the comprehensive guide at https://www.ubuntubuzz.com/2019/09/android-reverse-tethering-with-ubuntu-1804.html.

Can I share internet via USB from Ubuntu 20.04 to an Android device running a version other than 6.0.1 or 10?

Yes, you can share internet via USB from Ubuntu 20.04 to Android devices running different versions. However, the steps mentioned in this guide specifically target Android versions 6.0.1 and 10. You may need to modify the steps accordingly for other Android versions.

Do I need a wired internet connection on my Ubuntu system to share internet via USB?

Yes, it is recommended to have a wired internet connection on your Ubuntu system to share internet via USB. This guide assumes that you have an active wired internet connection. However, you can try using alternative methods like a mobile broadband connection or Wi-Fi hotspot on your Ubuntu system, but the steps may vary.

Can I use a different tool for reverse tethering instead of gnirehtet?

Yes, there are other tools available for reverse tethering on Android devices. However, this guide specifically focuses on using the gnirehtet tool. You can explore other tools and their documentation for alternative options.

Can I share internet from my Android device to Ubuntu 20.04 via USB?

This guide specifically explains how to share internet from Ubuntu 20.04 to Android devices. If you want to share internet from your Android device to Ubuntu, you may need to explore different methods or tools that support reverse tethering in that direction.

Can I use a different DNS server instead of dnsmasq?

Yes, you can use a different DNS server instead of dnsmasq. This guide suggests using dnsmasq as a lightweight DNS server for quick setup. If you prefer to use a different DNS server, you can install and configure it according to its documentation.

Are there any risks involved in sharing internet via USB from Ubuntu to Android?

Sharing internet via USB from Ubuntu to Android devices should generally be safe. However, it is important to ensure that you download the necessary tools and files from trusted sources to minimize security risks. Additionally, it is recommended to have antivirus software installed on your Ubuntu system to protect against any potential threats.

Will this method work with all Android devices?

This method should work with most Android devices. However, there may be some devices that require additional drivers or have specific compatibility issues. It is recommended to check the documentation or support forums for your specific Android device to ensure compatibility with Ubuntu and the reverse tethering process.

Leave a Comment

Your email address will not be published. Required fields are marked *