How to Emulate Ethernet between two USB-C ports in Linux
If you have two devices with USB-C ports and want to establish an Ethernet connection between them in a Linux environment, you can easily achieve this by emulating Ethernet over USB. This allows you to use a USB-C cable to connect the devices and transfer data as if they were connected through a traditional Ethernet cable. In this guide, we will walk you through the steps to set up this emulation in Linux.
Prerequisites
Before we begin, make sure you have the following:
- Two devices with USB-C ports
- A USB-C cable
- A Linux distribution installed on both devices
- Root access or administrative privileges on both devices
Step 1: Install Required Packages
First, we need to install the necessary packages on both devices to enable USB Ethernet emulation. Open a terminal on each device and run the following command:
sudo apt-get install usbip
Step 2: Configure the Server
One of your devices will act as the USB Ethernet server, while the other will be the client. Let's start by configuring the server. Follow these steps:
- Connect the USB-C cable between the two devices.
- On the server device, open a terminal and run the following command to enable the USB/IP kernel module:
sudo modprobe usbip-core
- Next, list the available USB devices that can be shared over the network by running:
sudo usbip list -l
- Identify the USB device you want to share from the list. Note down the bus ID and device ID.
- Detach the USB device from the host system by running:
sudo usbip detach -p
Replace
- Now, bind the USB device to the USB/IP server by running:
sudo usbip bind -b -d
Again, replace
Step 3: Configure the Client
Now that the server is configured, let's set up the client device. Follow these steps:
- On the client device, open a terminal and run the following command to enable the USB/IP kernel module:
sudo modprobe vhci-hcd
- Discover the USB/IP devices available on the network by running:
sudo usbip list -r
Replace
- Identify the USB device you want to connect to from the list.
- Attach the USB device from the server to the client by running:
sudo usbip attach -r -b -d
Replace
Step 4: Configure Network Settings
At this point, the USB Ethernet emulation should be established between the two devices. However, we need to configure the network settings to enable communication. Follow these steps:
- On both the server and client devices, open the network settings.
- Create a new Ethernet connection or modify an existing one.
- Set the IP address, subnet mask, gateway, and DNS server according to your network configuration.
Make sure to use different IP addresses for the server and client devices within the same subnet.
Step 5: Test the Connection
Finally, it's time to test the USB Ethernet connection between the two devices. You can do this by pinging each other's IP addresses or transferring files over the network. If everything is set up correctly, you should be able to establish a stable connection and exchange data seamlessly.
Conclusion
By emulating Ethernet over USB-C ports in Linux, you can easily establish a network connection between two devices without the need for a physical Ethernet cable. This can be useful in various scenarios, such as sharing internet access, transferring files, or setting up a local network. With the step-by-step guide provided above, you should now be able to emulate Ethernet between two USB-C ports in Linux successfully.
References
| Source | Description |
|---|---|
| USB/IP Protocol Documentation | Official documentation on the USB/IP protocol. |
| usbip Man Page | Manual page for the usbip command-line tool. |