I have a scenario where I need to start Android Emulator with a specific IP Address? Can I start the emulator like that?
I do not want to do IP forwarding or other stuff, because there is an Android program running in the Emulator which on boot will configure itself with Android Emulators IP address present during boot time.
As by default the ip address of emulator is 10.0.2.15 which I need to change. Also, this Ip is set in init.goldfish.rc and init.goldfish.sh. If I change them, still the ip of android is 10.0.2.15.
I made work by this way:
In Android Emulator if you do ifconfig then you will see bridge, eth0 & eth1 as network devices. Where bridge has the 10.0.2.15 as ip and eth0 is up but without any ip and eth1 is down without any ip.
Now create a TAP and Bridge devices on you host machine and bridge your TAP device with any of the working ethernet cards on you host machine.
The TAP device (tap1) and bridging (br1) it with eth0 can be created following below steps:
So now once your TAP is up and if your eth1 is connect to any dhcp server, start the dhcp server. Once the dhcp server is started, run the emulator with below command:
In your android emulator shell run below command:
You should be able to see eth1 down with ip 0.0.0.0, now run below command to bring up the eth1:
And voila!!! you have the eth1 with ip address assigned from dhcp server.
Let me know if it works!!!
Now if you have any program in android emulator opening port on external server ip address it would go through eth0 of host machine to the external server.