If I use DNSMasq in my router to set a fake address to an ip, then the Android phone can find it no problem.
Example:
DNSMasq
address=/fake.notreal/192.168.1.112
On the Android phone using chrome to go to the address or ConnectBot to ping the address fake.notreal works. It finds the correct server.
But if I use a real address, then it no longer works (I need this for testing of a website I'm developing). Example:
address=/mycompany.com/192.168.1.112
This address goes to the actual real server.
How to I make the android device listen to the router?
I was able to "fix" this by going into the Wi-Fi settings on the phone and:
Long press on the current wi-fi network
Choose "Modify"
Change to a static IP
Give it a static IP (this isn't the fix, but it's required to do the fix)
Under DNS, make the first one your router (e.g. 192.168.1.1)
Save
Turn off wifi
Turn wi-fi back on
At that point, it'll first ask your router and that'll return the local address.
On your Android phone, if you have root access, if you add
line 192.168.1.112 mycompany.com to your /etc/hosts I think that should work. You'll bypass the DNS query and go straight to 192.168.1.112.
If you don't have root access to the phone try applying that to your router's /etc/hosts but I don't think that would work then.
Related
I have my Laravel backend that I am trying to connect to from android app. my hosts file has
127.0.0.1 my.backend.test
the httpd conf file in my backend is
<VirtualHost *:80>
ServerName my.backend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog /var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
Header set Access-Control-Allow-Origin "http://localhost:4200"
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
I can access http://my.backend.test/api/some-route fine from google ARC but not from my phone. I seem to have to use my local ip address but I dont understand how to set that up.
I tried adding
<VirtualHost 192.168.my.ip:8080>
ServerName my.mobilebackend.test
DocumentRoot /var/www/mybackend.co.uk/code/public/
DirectoryIndex index.php
RewriteEngine On
ErrorLog
/var/www/mybackend.co.uk/code/storage/logs/apache_error.txt
<Directory /var/www/mybackend.co.uk/code/public/>
AllowOverride All
</Directory>
to httpd conf and
192.168.my.ip my.mobilebackend.test
to hosts
If I understand correctly : you can access your server from a different machine on the same network (so this is not a firewall problem) but only if you use the name (added in client's hosts file) and not the IP address.
Is your configuration the first virtualhost ? apache search for a ServerName matching the name provided in the query (e.g. the URL), then falls back to the first one, in your case the ubuntu home page.
As a test, what happens if you use
ServerName 192.168.0.1 (i.e. the IP used in the URL)
I think it will work if you access the server by IP address, but not anymore by name
Try this method
ip:port
Example
10.0.2.2:80
Note: Firewalls may cause problems with this. Windows has Microsoft Windows Firewall enabled by default. You may have to disable it
IP address
If you are using an emulator:
10.0.2.2
If you are using a real device:
Connect them into the same network. Either using a WiFi connection or using USB tethering option in your phone.
Find the IP address of your computer by typing ipconfig in cmd (if you are using Windows)
Port
Default port is 80. If you have changed it, use the new one.
OK, Let's first clarify the problem that you are encountering so that my solution will be clearer.
Your problem is that you are hosting a backend locally on your computer and although you are able to access it without a problem on your computer itself, when you try to connect to it from a different device you are unable to access it.
This problem comes from the fact that your website is hosted locally on your computer and is not accessible to the outside world, Therefore your phone which is presumebly on a mobile network, cannot access your backend since your backend is on your own private network and your phone cannot access this private network from its own network, This is due to the fact that generally your router/isp block incoming requests to port 80, so even if you would know your computers public ip address you still would be blocked.
Now that we discussed the problem, lets go through what a solution would entail.
A solution would entail that either both your phone and your computer are on the same network, or you expose your computer to the public internet.
Lets go through some ways to acheive this.
The first and arguably the simplest way to acheive this would be to put your computer and your phone on the same network. This can be acheived by connecting your phone to the same router that provides your computer with internet access. Once you are connected to the same network, all you have to do is instead of using this url http://my.backend.test/api/some-route, replace my.backend.test with the local ip address of your computer so if your computers local ip is 192.168.0.2 then it becomes this http://192.168.0.1/api/some-route and now you will be able to access your backend from your phone.
Note: You may be wondering how do I figure out my computers local ip address? On windows it can be found by going into network settings > right click on your network connection > click properties from the context menu and then look for the field that says ipv4 address, that is your local ip. On mac you can find it by going to System Preferences > Network > clicking on the connection that has a green dot next to it > Then underneath the status label you will see the current local ip address that you are connected to.
Solution #1 is great if you don't mind going through the hassle of connecting your phone to the same network as your computer, but lets say its a pain, or impracticle for various reasons like lack of wifi etc or its just that you want your phone to be able to access the computer from Anywhere and no matter what network it is on If this is the case, solution 2 is for you.
We will enable access to your computers localhost to the entire internet by using reverse tunneling software, in our case one of the most popular choices is Ngrok, available here. What Ngrok does is it creates a tunnel to your local host and assigns it a publicly accessible domain such as yourapp.ngrok.io which you can use in place of my.backend.test to access your application from anywhere. So once you enable Ngrok you just replace http://my.backend.test/api/some-route with http://yourNgrokAppDomainName.ngrok.io/api/some-route and you will then be able to access your backend from your phone from anywhere no matter which network you are on.
In summary these are two ways for you to access your backend that is on your computer from a phone. Hope it helps.
I wish to change the Ethernet IP Address of the Raspberry Pi3 board that is running Android Things OS. Currently it automatically fetches an IP Address available in the connected network. But I wish to assign a fixed/static IP to the device. Is it possible to set a static IP using ADB?
I don't know the solution based on Android-things.
But I usually try to prevent the use of fixed IP (unless the device runs forever) set in the device itself.
I prefer to use the DHCP of the modem to set the IP based on the MAC adress. This prevent some conflict.
You can see more information on this post
You can set a static IP usually through your router settings. Try accessing your router settings usually through the web browser at:
http://192.168.0.1/
Assuming you have never accessed this the username is usually admin, and the password is password. You can check the router name online to find the default username and password.
Navigate the menus to find a page which shows you he connected devices. See pic for an example.
Every routers interface is different.
If you have a setting that says DHCP see if you can change it to a reserved IP so that the IP address assigned doesn't change.
Remember different routers have different interfaces so you must do some searching about yours to find the setting.
You can do this from any computer connected to your internet, doesn't have to be on the raspberry to make the changes.
Maybe I'm typing the wrong words by google but I' totally lost and can't a solution.
On my work we all access our projects through server alias like project.company.local
But when I'm at home with my company notebook I can't reach my websites aliases from e.g. my smartphone or any other device at home. Although they are all in the same network.
I have Ubuntu and Apache on my notebook.
My etc/hosts has
127.0.0.1 projectA.company.local
What am I missing?
Your hosts file only works for the computer itself, not other machines on the network. Your work must have the appropriate entries set up on the DNS server. You could just access a site on your home computer, from other devices on the network, using the IP address of your computer, instead of a host name, if it's just one site. Otherwise perhaps your router will allow adding DNS entries for the local network. If you're going to do that, you'd also best set up a static IP address for your home computer so it doesn't change. Hope that is enough info for you to get it sorted.
volley is not working when i want to fetch data from a system on my local network.
where URL is like http://192.168.x.x/data.php
it works well on emulator but not on a real device. it show a time our error.
even i tried setting a maximum time our and retry policy. but in vain.
There are two ways to solve this:
a) keep your device connected to the PC which is connected to your local network either using lan or wifi. Keep debugging mode on. Use ipconfig to check your pcs ipv4 address and use that.
forward your server's port on your router and then use the ipv4 address found on your pc's ipconfig command.
c) Best option-> i use this. Forward your pc's server port on your router, Go to your router's DHCP configurations and give your pc mac a preferred DHCP ip to make sure your router always gives that local ip to your pc(global will still be dynamic if you dont have a static ip). Register to a DDNS and use the set ip above and you will be able to access your web service from anywhere in the world. (i use dynudns for the ddns part)
see How can I access my localhost from my Android device? for other ideas
In the first two steps, make sure that the mobile is connected via wifi so that the router can forward it requests. in third, it can be connected to the internet anyway it likes. Also in the first, you will have to change the url everytime your local ip changes.
In second option, the dns will give a tool for auto ip updation :)
I am trying to debug my visual studio 2012 asp.net project from my phone and have followed all steps here and here.
However none of them work, can't even connect from my other laptop. When I add my public IP or use * IISExpress doesnt even seem to pick up on it (Can't find it in IISExpress->show all applications). But When I used my local IP at least it showed up there and I could connect to it from my own computer, but no other computer/phone.
The cmd commands are successful, I add the extra binding, I open the firewall. Dont know what is wrong.
Which IP (local/public) should I use? what should I type in as URL when I want to test it? I am trying http://IP:port and http://IP:port/Default.aspx.
EDIT: Using this solution I got it to work on my laptop, however I still can not get it to work on my phone.
Basically, the points mentioned in the links you have cited are enough for enabling communication with the phone. But here is one point to make sure (since you have not mentioned it): You have to make sure that both the server and the clients (in your case, the machine that runs the visual studio and your phone and the other laptop) are on the same wireless network. To find out the IP that your server/development machine is currently using, you can issue ipconfig command in cmd and look at the Wireless Network Adapter IPV4 address. For example, if your laptop IP address is 192.168.1.2, you should use http://192.168.1.2:8080/Default.aspx (assuming that your site runs on the port 8080).
You use the local IP if you're on the same network as your server (for example, use WiFi on your phone and join the same network that your server is on).
You use the public IP if the device is outside your network, and you have to configure the firewall to forward the correct ports to the local IP. That's NAT traversal. This would be if you're using the phone's cellular data connection, or you're using a WiFi or wired network that's different from the one your server is on.
Your URL should always be of the format <protocol>://<IP or DNS name>:<port>/<path>. However, you can omit the IP (and the colon) if you're using HTTP on port 80, or HTTPS on port 443. And you can omit the path if you're accessing the root of the site, and your site has a page correctly configured for the root (either via default document in IIS, or route defaults if you're using routing features).