On my Ubuntu PC, I need to use 10.0.2.2 instead of 127.0.0.1 to be able to let Android emulator to connect to web server running on localhost. So wondering how can I define the new IP?
I edited /etc/hosts and added
10.0.2.2 localhost
10.0.2.2 subdomain.localhostInstead and restarted the hosts using /etc/init.d/hostname.sh. But ifconfig still does not show the new ip. How can I fix this?
1 Answer
You don't need to change /etc/hosts or machine hostname. These are just for name resolution. You need to bring up a loopback interface with this ip. So we will bring a copy of loopback (lo:1) with this ip:
$ sudo ifconfig lo:1 10.0.2.2 upThen you can use ifconfig to see if its up. It will appear like:
lo:1 Link encap:Local Loopback inet addr:10.0.2.2 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1You can use ssh to this ip.
To make this permanent you can add it to /etc/rc.local .