Commands.page Logo

Download File Using Specific Network Interface in Ubuntu

This article provides a quick guide on forcing file downloads to use a specific network interface on Ubuntu systems. When multiple connections exist, such as Ethernet and Wi-Fi, you may need to direct traffic through a particular adapter. We will demonstrate how to achieve this using standard command-line tools like wget and curl.

Identify Your Network Interface

Before downloading, you must know the name of the interface you want to use. Open a terminal and run the following command to list available interfaces:

ip addr

Look for names like eth0, enp3s0, or wlan0. Note the specific name you intend to use for the download.

Using wget to Specify Interface

The wget utility allows you to bind the download to a specific interface using the --interface flag. Replace INTERFACE_NAME with your actual interface name and URL with the file location:

wget --interface=INTERFACE_NAME URL

For example, to download a file using the eth0 interface:

wget --interface=eth0 https://example.com/file.zip

Using curl to Specify Interface

Similarly, curl supports binding to an interface with the --interface option. The syntax is nearly identical to wget:

curl --interface INTERFACE_NAME -O URL

Here is a practical example using the wlan0 interface:

curl --interface wlan0 -O https://example.com/file.zip

Verifying the Connection

To confirm the download used the correct interface, you can monitor network traffic during the process. Open a new terminal window and use iftop or nethogs filtered by the specific interface. Alternatively, check the source IP address of the outgoing connection if your interfaces have distinct IP assignments.

This method ensures your download traffic does not interfere with other network activities on different adapters. It is particularly useful for servers with multiple uplinks or distinct routing requirements.