I'm developping an app for Android Things DP4 on Rpi3.

I need my Rpi to send packets with destination IP in the network with the interface wlan0 and packets with destination IP in the network with eth0.
For the moment, when I send a packet, I always have the error message : Network Unreachable. It looks like I need to specify rules in iptables, but my only experience from iptables is from linux : and there are MANY more chains in Android.
I must select the interface when I use ping (ping -I eth0 otherwise, I have the error message Network Unreachable...

So : Does someone know how to route on an interface after checking the IP address ?

2 Answers 2


Usually you should have a route for each interface similar to this, assuming your default gateway is (your internet router?) and the ip address from the wlan0 interface is

~$ sudo ip route
default via dev eth0 proto static dev wlan0 proto kernel scope link src dev eth0 proto kernel scope link src

You can add (del) a route with:

~$ sudo ip route add dev eth0 proto kernel scope link src

If your raspi should work as a router you also have to enable ip-forwarding in /etc/sysctl.conf and reboot.

~$ ~$ grep forward /etc/sysctl.conf 
# Uncomment the next line to enable packet forwarding for IPv4
# Uncomment the next line to enable packet forwarding for IPv6

or if you use systemd-networkd set IPForward=yes in your /etc/systemd/network/iface.network in section [Network]

  • Thanks for your answer ! The default keyword and the ip route works with 'add' before. Are we both under Android Things DP4 OS ?
    – Maskim
    Feb 1, 2018 at 14:26
  • @Maxime.D Oh sorry overseen that. I'm on Raspbian. But the principle should be the same.
    – Ingo
    Feb 1, 2018 at 15:00
  • I think so, but I can't find the syntax for Android Things, and I don't find any documentation about making ip routes on Android Things ...
    – Maskim
    Feb 1, 2018 at 15:05
  • As far as I know is Android a Linux derivate? Maybe you have to use the older version ~# route instead of ~# ip route. Is there a man page ~$ man ip or ~$ man route` or something else? What about ip help route or route --help or so?
    – Ingo
    Feb 1, 2018 at 15:19
  • ip route help returns infos about how to use this tool but I doesn't help me since I don't understand it... I would like to show the output of ip route help but I don't have enough space in the comment section
    – Maskim
    Feb 1, 2018 at 15:31

So, I chose to send only on eth0, and not connecting the Wi-Fi.
The interface we want to use must have an IP address, BUT if you set it manually with ifconfig wlan0/eth0 <yourIPaddress> the Android Things device won't use it AT ALL : not event on the same network.

The Android Things device, needs a DHCP service available on the network.
And, it doesn't seems to be able to handle two interfaces at the same time : It will use the first interface connnected. If both Wi-Fi and Ethernet are available, the priority seems to be on the Wi-Fi.

One last thing : if you connect Wi-Fi after Ethernet (So you can't send data with the Wi-Fi as Android Things handles only one interface), you can receive on the Wi-Fi !

This interfaces limitation is not due to the Android API for Java, but by the OS itself, you can try as much as you want to specify the interface you want in your app, but is won't work as apps use the OS to work

Don't hesitate to add détails if you know more, this is only the result of my experiments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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