ssh through tethered android phone to AWS EC2 server - android

Disclaimer: I don't know this is the actual problem, I just suspect it is.
I have set up an Amazon Web Services EC2 instance as a remote git server. I have had to configure it to only accept incoming traffic from a single IP address though I had wanted to make it open to all because I will be using it while I travel.
The complication here is that mobile phones cannot have a static IP address and I will be accessing the server using my android phone tethered to my laptop. This means I have to make a new rule to accept traffic from my current IP address before connecting to the server via ssh.
When setting this rule there is an option to use "My IP Address". Amazon automagically checks my current IP address and sets it in the rule. It looks like 123.123.123.123/32. The "/32" part there being the actual end of the address.
When testing the server from home I have no problem accessing the server from my desktop computer over the home network with static IP. Equally no problem accessing the server from my laptop computer over the home network. I then tethered my phone to my laptop and tried to access the server via the cellular network with the home static IP address rule still in place. As expected the connection was not made because the phone is allocated a different IP address.
BUT...then I go out for a day of coding in a nice location and try to connect to the server and it does not work. I went in to my EC2 console and set a new rule to accept traffic from my current IP address over my tethered phone using the automagic "My IP Address" setting. Then tried to connect to the server via ssh. No joy.
The connection is not made. Just times out in the same way it did when I originally tested trying to access from an IP address not specified in the rule.
So I was thinking it has something to do with ports. Is that what the "/32" above is? Or have I got that all out of whack?
What can I do to gather more information to help define what the actual problem here is?

I had this same problem connecting to a Postgres database in AWS. Here is what I did to solve it:
I opened up the server to everyone 0.0.0.0/0
I went into the server and determined my actual ip address that it was trying to connet with.
Went back and fixed my rule with that IP address.
My automatically populated IP address was different than the actual one.

Find an Android VPN provider that will sell you a static IP for every use. That might be a way to use a static IP as a security measure. If the VPN provider offers the service on PC as well you can set both to the same IP. Your really ambitious you could set up a VPN service on your virtual machine and then configure it to only except connections from it's self via SSH. You would have to Adjust your "security group" to except VPS connects from any where. The second method would mean that you wouldn't need two static addresses for and added layer of security.

Related

Run ASP.NET application on server and access from remote computer/phone

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).

ActionScript 3.0 How to properly connect? "localhost" or "192.168.XXX.XXX"?

I am struggling with this for three days now. It is an android client application that connects to the server AIR application through Wifi on local network.
I need my application to connect to the server every time it is launched without asking the user to enter local IP, in case it changed.
It seems there are many ways to make sure the connection is successful, but I want to make sure I can go without the help of RTMFP or PHP or SharedObject stuff.
I am able to get local IP using NetworkInterface and NetworkInfo ANE from Android client. Then I use the variable to
mySocket.connect(ipAddress, 8888);
But there is a problem:
1) When debugging on Android via Wifi
The detected IP 192.168.137.2
2) When debugging on Flash, on computer
The detected IP 192.168.137.3
So, the local IPs are not the same. So client fails to connect. Everything works perfect, if I manually set that IP, but I need a code that works, even if the IP on local network changed.
As I mentioned making a textInput field in case IP changed and ask the user manually enter IP is not an option.
My question is why using "localhost" as host parameter of socket.connect(host, port) does not work? If it did, there would be no need for detecting local IP at all. "localhost" works for me only if the client is running on computer, but not Android.
Is it the problem with Security Policy file? if so, I have no idea how to use that. I can't find any tutorial on that.
You have two devices
1. Android device running an app and acting as a client
2. Computer running an AIR app and acting as a server
Each of those devices will have it's own IP address on the network. In your case android device IP is 192.168.137.2, and computer IP is 192.168.137.3.
In order for client to connect to server there must to be some means of delivering server IP to the client. Normally for an app like this you enter server IP address manually in settings, or have one central place available on the net where server registers it's IP address and client fetches the address from there.
Since you don't want to use any of these options the last resort would be implementing local area network scanning. Where you scan all the segment 192.168.137.* and search for opened port reserved for server. That of course is not good implementation but could work if project is for your own use.
Lastly "localhost" is name mapped to loopback IP 127.0.0.1 which is special address and is used to connect to the same device app is running on. In your case if android app is connecting to localhost it is trying to connect to the android device itself.

Adding an android phon to a DNS server?

I want to know if it is possible and how to, make an application, that allows me to put my android phone in a DNS server, as we do in a Windows PC. I want to identify my android phone by a name in a DNS network, obviously in a network in which there is a DNS server.
Thanks in advance...
Generally, you have three options:
Static IP. Sometimes it's possible to get a fixed IP for your phone, in this case you need to setup a DNS record only once, and it requires no software nor configuration on the phone itself. All you need is just create a regular DNS address record. (Consult your DNS administrator (or ask on superuser.com if your need help))
Home/office network (DHCP). If you want to access your phone via LAN, and this LAN have a DHCP server under your control, DHCP server can be configured to update a DNS record whenever your phone connects. In this case too, the phone does not need any special configuration/software - it's a DHCP server which needs to be configured.
Dynamic DNS. Your phone can submit it's address via dynamic DNS. This will work for any case - LAN (including NAT) and cellular connection. You usually need to subscribe to some dynamic DNS service for this and yes, there are dynamic DNS clients for Android. Try net-me.net guide on setting up dynamic DNS under Android (I am affiliated).
(For what purpose you want access your phone, which software will listen to incoming connections, and if the phone IP will be accessible from anywhere - it's all a completely different story.)
If your DNS and DHCP servers support it, you can get the DHCP server to automatically update the DNS server. See http://technet.microsoft.com/en-us/library/cc787034(v=ws.10).aspx for a description of how to do it with Microsoft's servers.

Android: Using WiFi over LAN

For debugging purposes I set the IP address on my phone to 192.168.178.220 and this connects to my PC over a wireless router to access a web app I have running in IIS on my PC. The web app uses 192.168.178.201. I have to use the desktop app DnsSpeeder to act as my DNS server in order for my phone app to communicate with the web app using its domain name instead of its IP address. I need to do this because I use a subdomain that shares the same IP address with other web apps.
Normally this works but if I leave my phone untouched for a minute or so, the phone cannot resolve the domain name. I even tried a third party tool and just entered the IP address and it cannot connect to the web app. But after a few minutes the connection works fine with either just the IP address or domain name. If I use the third party tool to ping a site that is on the Internet, like google.com, there also appears to be a long delay.
My Internet connection appears to always be on and under my settings I have it set to never go off, so I can't see how it could be the WiFi radio itself.
Could the problem be with using a LAN IP address or is it something else?
Interesting! Sure sounds like something is going to sleep on the phone. Have you run a packet sniffer such as Wireshark on your PC to determine if the expected DNS requests are making it from the phone to DnsSpeeder?

How to communicate without prior knowledge of IP

Im developing an app which uses the tcp connection. currently im communicating using hard coded IP addresses as a sample, but in the real world this is not the case i think. We come across any mobile and start communicating/sharing etc without having any prior knowledge of other person's IP. In such a case how to get the IP address of those who are using my application. How can i communicate without the prior knowledge of the IP address. How to implement this. Help me in sorting it. Thanks in advance.
EDIT:
And in case if the user connects the internet thro' GPRS/3G connection then his IP address will be changing based on the service provider. How can i find that.
Given what you are commenting on other answers, if what you want are the IP addresses of other Android devices to do some kind of P2P game you should note that there is no reliable way to do that directly.
If the users are connected in the same LAN you could provide in your application some kind of discovery service using UDP broadcasts.
If the users are connected to the internet and have public IP addresses then you could use some intermediate server to register the users at startup and have them discover other users using that server.
But (and this is the most common case) if the users are connected to the Internet and have private IP addresses (like when they are connected with WIFI on their LAN) you need some kind of server that acts as a proxy for their requests because there is no way to make a direct TCP connection from a natted IP to another natted IP. There are a few solutions to solve this problem, you could start for example by learning something about XMPP and how it works.
Your app must use DNS. You will first need get your IP into the DNS system. You do this by signing up for a domain name & setting up A / AAAA records for hostnames with a hosting provider (or you could set up your own DNS server). You may even find some free DNS providers.
In your app, you can hard-code a fully qualified domain name that you previously set up, say - app.foo.com and use the android gethostbyname library call to fetch the IP address for you. The local DNS resolver will then go to its DNS server and fetch the IP address corresponding to app.foo.com.
Can you use DNS? You can still hard-code the domain name if you want, and the domain name can be configured to point to any IP addresses anytime later.

Categories

Resources