Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DKrepsky/7defcb4e177f5e3f456d0b5f9748aa7e to your computer and use it in GitHub Desktop.
Save DKrepsky/7defcb4e177f5e3f456d0b5f9748aa7e to your computer and use it in GitHub Desktop.
Enable bridge network Android Studio Emulator

sudo ip tuntap add dev tap0 mode tap group kvm sudo brctl addif br0 tap0 sudo ip link set dev tap0 up promisc on #sudo sysctl -w net.ipv4.ip_forward=1

emulator -avd Pixel_3a_API_30_x86 -netfast -accel auto -qemu -device virtio-net,netdev=net0,mac=52:55:00:d1:55:51 -netdev tap,id=net0,ifname=tap0,script=no,downscript=no

adb root adb shell "dhcpclient -i eth1 &" adb# ctrl+z adb# bg adb shell "ip rule add from all lookup main pref 1" adb shell "ip route add default via 172.16.106.254 dev eth1"

@neilyoung
Copy link

Crappy format, isn't it?

@DKrepsky
Copy link
Author

Hi @neilyoung

You mean this gist? I can make it better if it will help you.

Thanks

@neilyoung
Copy link

No thanks. Not necessary anymore. I found Genymotion, which is a far better alternative than the inbuilt emulator and allows bridge configuration by default.

@spurgeonbj
Copy link

@DKrepsky Thanks for the nice info. On a Windows machine with Android Studio, where / how should we type in these commands? Sorry, am a newbie to Android world...

@DKrepsky
Copy link
Author

DKrepsky commented Aug 5, 2022

Dear @spurgeonbj, these commands are intended for Linux only. I really don't know how to create a network bridge in Windows.

@forlayo
Copy link

forlayo commented Oct 31, 2022

I've seen here how to create a bridge in Windows for qemu -> https://wonghoi.humgar.com/blog/2021/05/03/qemu-for-windows-host-quirks/

I've tried to follow that tutorial and then running my emulator with the following:
.\emulator -avd Nexus_6P_API_24 -qemu -device virtio-net-pci,netdev=hn0,mac=52:55:00:d1:55:51 -netdev tap,id=hn0,ifname=TAP,script=no,downscript=no

It runs, and I've a new device under eth1 in which I can use dhcptool to obtain IP..

generic_x86_64:/ # dhcptool eth1
generic_x86_64:/ # ifconfig
eth1      Link encap:Ethernet  HWaddr 52:55:00:d1:55:51
          inet addr:192.168.0.34  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::5055:ff:fed1:5551/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:549 errors:0 dropped:174 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:79282 TX bytes:764

And it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment