remote-android / redroid-doc

redroid (Remote-Android) is a multi-arch, GPU enabled, Android in Cloud solution. Track issues / docs here
4.36k stars 311 forks source link

Android network can't connect if container interface name changes #531

Open jpmorrison opened 11 months ago

jpmorrison commented 11 months ago

I created my own bridge with docker dhcp plugin - it works in an alpine container but not in Android. The container comes up with interface anbox00 - maybe because the parent bridge is anbox0 This seems to break ip rules and I don't see the Android network services in logcat.

Is there some android boot flag I can try to get around this?

zhouziyang commented 11 months ago

redroid container booted, but cannot connect to the network? eth0 is hardcoded, should possible auto-detect (do cause issues here).

jpmorrison commented 11 months ago

Still not sure if this is an Android boot problem, Docker or the Docker dhcp plugin but I have a workaround:

Simply create a bridge named eth and the container will start with eth0! This is working with apps that need local network access for broadcast/multicast like Tuya, Kasa etc.

My server has dual nics and I'm using the second nic eno2 connected to the local LAN.

I commented out the dhcpcd eth instructions from the original docs. I didn't need it and it would interface with my existing eno1 connection.

# Create the bridge
sudo ip link add eth type bridge
sudo ip link set eth up

# Assuming 'eth0' is connected to your LAN (where the DHCP server is)
sudo ip link set eth up
# Attach your network card to the bridge
sudo ip link set eno2 master eth

# If your firewall's policy for forwarding is to drop packets, you'll need to add an ACCEPT rule
sudo iptables -A FORWARD -i eth -j ACCEPT

# Get an IP for the host (will go out to the DHCP server since eth0 is attached to the bridge)
# Replace this step with whatever network configuration you were using for eth0
# sudo dhcpcd eth

Install the docker-net-dchp-plugin. This works for me but other forks like this are newer: https://github.com/vpaprots/docker-net-dhcp and it has some bug fixes. Unfortunately the install instructions don't work and it was too much trouble to figure out how to build myself,

This all worked for me in Ubuntu 20.04

# plugin install
docker plugin install ghcr.io/devplayer0/docker-net-dhcp:release-linux-amd64
# create the network
docker network create -d ghcr.io/devplayer0/docker-net-dhcp:release-linux-amd64 --ipam-driver null -o bridge=eth lantest
# start android
docker run -itd --rm --privileged     -v /data:/data       --network=lantest     redroid/redroid:11.0.0-latest
#
# check the container with a shell or inspect
docker container inspect decbf9bbced9 | grep IPAddress

            "SecondaryIPAddresses": null,
            "IPAddress": "",
                    "IPAddress": "192.168.0.123",

docker container exec -ti decbf9bbced9 sh

255|decbf9bbced9:/ # ip add show dev eth0
64: eth0@if65: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 8a:2a:88:53:7d:2f brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.0.123/24 brd 192.168.0.255 scope global eth0
       valid_lft forever preferred_lft forever

# 
# Now you can connect with adb
adb connect 192.168.0.123
# run adb or strcpy with -s 192.168.0.123:5555
scrcpy -s 192.168.0.123:5555

image