1

This is a follow up to Static IP Address for USB Screencast in Raspbian Stretch. Concisely, I want to use USB Tethering to connect VNC on my smartphone to the RPi for use as a remote desktop-type connection.

I've found that connecting my Android Phone via USB to my Raspberry Pi 3 B+ (Raspbian Stretch OS) and enabling Smartphone Tethering creates a new eth1 interface, as shown in row 4 of my networkctl outputs:

IDX LINK             TYPE               OPERATIONAL SETUP
  1 lo               loopback           carrier     unmanaged
  2 eth0             ether              no-carrier  unmanaged
  3 wlan0            wlan               routable    unmanaged
  4 eth1             ether              off         unmanaged

However, as you can see, eth1 is "off and unmanaged". I want to be able to give the Raspberry Pi an IP address on the eth1 connection, so that I can use VNC to control the screen of the RPi via a USB cable. How do I "enable" the eth1 connection and use it?

1

Seems you want to use USB tethering mode with your Android phone. With a fresh flashed Raspbian image it works out of the box with my Android phone. I don't know what's different to your setup but I will show my setup.

First I connect my smartphone to my RPi 3B+ with an USB cord. It is the only device connected to it. Then I enable USB-Tethering in the settings of my phone. Now I will see that the RasPi has an usb0 interface configured:

rpi ~$ ip -4 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    inet 192.168.42.236/24 brd 192.168.42.255 scope global usb0
       valid_lft forever preferred_lft forever

usb0 has got the ip address 192.168.42.236 from the phone. Looking at the routing table I can find the ip address from the phone:

rpi ~$ ip route
default via 192.168.42.129 dev usb0 src 192.168.42.236 metric 204
192.168.42.0/24 dev usb0 proto kernel scope link src 192.168.42.236 metric 204

The default gateway 192.168.42.129 is the ip address from the phone. That means all ip packets not belonging to 192.168.42.0/24 will be send to the gateway and it knows where to send them to the internet. This way you will get into the internet. Check it step by step:

# Check android phone/gateway
rpi ~$ ping -c3 192.168.42.129
PING 192.168.42.129 (192.168.42.129) 56(84) bytes of data.
64 bytes from 192.168.42.129: icmp_seq=1 ttl=64 time=0.709 ms
64 bytes from 192.168.42.129: icmp_seq=2 ttl=64 time=0.582 ms
64 bytes from 192.168.42.129: icmp_seq=3 ttl=64 time=0.341 ms
[..]

# Check internet connection without name resolution
rpi ~$ ping -c3 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=120 time=25.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=120 time=23.7 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=120 time=22.1 ms
[..]

# Check internet connection with name resolution
rpi ~$ ping -c3 google.com
PING google.com (172.217.168.206) 56(84) bytes of data.
64 bytes from ams16s32-in-f14.1e100.net (172.217.168.206): icmp_seq=1 ttl=54 time=20.6 ms
64 bytes from ams16s32-in-f14.1e100.net (172.217.168.206): icmp_seq=2 ttl=54 time=21.8 ms
64 bytes from ams16s32-in-f14.1e100.net (172.217.168.206): icmp_seq=3 ttl=54 time=29.3 ms
[..]

Now I'm able to start the internet browser and go to Googles home page by putting this into the browsers address line:

https://google.com

On the command line you can check html connection with curl. Of course you will only see the raw html data because there is no browser:

rpi ~$ curl https://google.com
<HTML>
  <HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>301 Moved</TITLE>
  </HEAD>
  <BODY>
    <H1>301 Moved</H1>
    The document has moved
    <A HREF="https://www.google.com/">here</A>.
  </BODY>
</HTML>

Yes, this site has moved and you see this because automatic redirection (as done by the browser) isn't set with this simple curl call.

  • This is interesting -- thanks for the response. So, you didn't have to do anything to /etc/network/interfaces or /etc/dhcpcd.conf? The usb0 just simply showed up? – kmeng01 Apr 17 at 4:32
  • Whoo, it looks like it finally worked! Apparently, the type of Android phone affects this process significantly... Thanks for your help along the way, @Ingo! – kmeng01 Apr 17 at 5:08
  • @kmeng01 If does it help you but doesn't solve the question direct, you may consider to upvote the answer ;-) – Ingo Apr 17 at 7:33
0

It seems like the issue was the specific Android phone I was using: a Samsung Galaxy S7 Edge. The eth1 interface had no MAC address attributed to it; therefore, there was no way for an IP address to be assigned. The final solution is as follows:

First, add the following lines code code to /etc/dhcpcd.conf. This is standard:

interface eth1
static ip_address=192.168.42.42/24
static routers=192.168.42.1
static domain_name_servers=192.168.42.1

Then, run the following commands to give the eth1 interface a MAC:

ip link set dev eth1 down
ip link set dev eth1 address $MAC_ADR
ip link set dev eth1 up

where $MAC_ADR's first three (3) bytes are consistent with your hardware (check the other eth0 or wlan0 interfaces for these bytes), and the rest are random numbers (could be 00:00:00).

That's it! On my Samsung Galaxy S7 Edge, I could use VNC to remote desktop into the RPi's GUI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.