I found the OP's comment/suggestion of using rinetd to be much easier than iptables.
rinetd can intercept connections on one interface and forward them to a different IP; so, to solve this problem of the emulator not being accessible to computers other than the host machine, you intercept the incoming connections to your host and forward them to 127.0.0.1
Here's how:
First, install rinetd (http://www.boutell.com/rinetd/)
- Linux: either download it from the link above, or, in a terminal in Ubuntu, enter "
sudo apt-get install rinetd
". The command could be different in other Linux distros...
- Windows: download from the link above (but it only says 95/98/NT..)
Next, set up a port redirection in the emulator:
- start your AVD
- in a terminal, enter "
telnet localhost 5554
" (or whatever the port for your avd is)
- once connected by telnet, enter "
redir add <protocol>:<host port>:<emu port>
" (e.g., "redir add tcp:5000:7000
" to forward tcp data sent to port 5000 on the host to port 7000 in the emulator)
Configure rinetd:
- Edit the file
/etc/rinetd.conf
and add the line "<host ip> <host port> 127.0.0.1 <localhost port>
". So if your host computer's IP address is 123.45.67.89 and you want to use port 5000 and then forward it to 127.0.0.1:5000, "123.45.67.89 5000 127.0.0.1 5000
"
I'm not sure if rinetd is launched automatically after you install it.. to run it:
To re-initialize rinetd after modifying the config file:
- "
cat /var/run/rinetd.pid
" shows you the pid of rinetd
- "
sudo kill -1 <pid>
" re-initializes it (e.g, "sudo kill -1 3225
")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…