对于Android模拟器设置IP地址模拟器、地址、Android、IP

由网友(//忘记、属于我们的回忆)分享简介:我有一种情况,我需要启动Android模拟器与特定的IP地址?我可以启动模拟器这样?I have a scenario where I need to start Android Emulator with a specific IP Address?Can I start the emulator like th...

我有一种情况,我需要启动Android模拟器与特定的IP地址?我可以启动模拟器这样?

I have a scenario where I need to start Android Emulator with a specific IP Address? Can I start the emulator like that?

我不想做IP转发或其他的东西,因为有一个Android程序在模拟器上运行的开机将在启动时与Android模拟器的IP地址present本身配置。

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.

由于默认仿真器的IP地址为10.0.2.15,我需要改变。此外,该IP是init.goldfish.rc和init.goldfish.sh设置。如果我改变他们,还是安卓的ip是10.0.2.15。

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:

在Android模拟器,如果你做的ifconfig然后你会看到桥,为eth0和放大器; eth1进行网络设备。凡桥有10.0.2.15 IP和eth0将上升,但没有任何IP和eth1下跌没有任何的IP。

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.

现在你的主机上创建一个TAP和桥梁设备,并与你主机上的任何工作以太网卡桥接您的TAP设备。

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.

的TAP设备(TAP1)和桥接(BR1),它以eth0可以通过以下步骤来创建:

The TAP device (tap1) and bridging (br1) it with eth0 can be created following below steps:

$sudo ip tuntap add dev tap1 mode tap
$sudo ip link show dev tap1
$sudo brctl addbr br1
$sudo brctl addif br1 tap1
$sudo brctl addif br1 eth0
$sudo ip link set eth0 up
$sudo ip link set br1 up
$sudo brctl show

所以现在一旦你的TAP到了,如果你的eth1的是连接到任何DHCP服务器,启动DHCP服务器。一旦DHCP服务器启动后,运行下面的命令模拟器:

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:

$sudo ./emulator -avd <avd_name> -qemu -net nic,vlan=1 -net user,vlan=1,hostname=<hostname_you_want> -net nic,vlan=2,macaddr=<mac_id_of_eth1_of_android_emulator> -net tap,ifname=tap1,script=no,vlan=2

在下面命令运行Android模拟器的shell:

In your android emulator shell run below command:

$netcfg

您应该能够看到eth1的打倒IP 0.0.0.0,现在下面的命令,运行,弹出的eth1:

You should be able to see eth1 down with ip 0.0.0.0, now run below command to bring up the eth1:

$netcfg eth1 dhcp

和瞧!你必须从DHCP服务器分配IP地址eth1的。

And voila!!! you have the eth1 with ip address assigned from dhcp server.

让我知道,如果它的工作原理!

Let me know if it works!!!

现在,如果你有在Android模拟器的任何程序上的外部服务器的IP地址打开端口将通过主机的eth0的外部服务器。

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.

阅读全文

相关推荐

最新文章