Routing external calls to api with out a domain name - asp.net

I have a client that does api calls to a owin server. When calling e.g. http://192.168.345.13:8000/api/status it works fine when doing this from a local machine on the same LAN as the server.
When using the same aurelia client from a remote machine e.g. a 4g smartphone then the client code is shown but the api calls don't work. My router forwards the port to the server machine so external ip a.b.c.d:8000 routes to the server.
This is ofcourse because the client has hardcode : http://192.168.345.13:8000/api/status.
My question is how do i support both local and remote via the same API? Can i detect this in the client code?
Can i detect a remote ip and switch to external ip (a.b.c.d:8000/api/status)?
Any sugestions are welcome!

Turns out that had some old ip filtering on. After disabeling this it works now. Using the external ip for the server the server ip calls.
When on the local network i use the local machine ip in the browser and when accesing from e.g. 4g Phone then i use the external ip.

Related

How to port forward external IP to websocket server hosted locally?

I have created a local websocket server using the ktor framework, which is available locally in the below IP.
[main] INFO Application - Responding at http://192.168.1.10:8080
And I'm able to access it locally from postman by hitting
ws://192.168.1.10:8080/chat
I would like to connect to this socket from the internet, But when I setup port forwarding (using NAT virtual server configuration), this doesn't seem to work. I get timed out error.
I tried this because, it is working fine for the http server (express app) I created in another port. From the below NAT virtual server configuration, I was able to do port forwarding and access the webservice from the internet.
I'm quite new to socket programming and networking. Kindly advice.
You can't have a single External Port mapped to two different Server ports. Each Server needs a distinct External Port mapped to it. Right now, you have External Port 80 mapped to both 192.168.1.10:3000 and 192.168.1.10:8080.
Once you fix that issue to use a separate External Port for each Server, then http://<externalIP>:<externalPort1> and ws://<externalIP>:<externalPort2> should work properly to reach the HTTP and WebSocket servers, respectively, from the outside world.

Access server in local network through domain

i have problem with access to server with domains.
Test url: testpage.example.com.
Server is in local network with port fowarding (80, 443), configured as web server using caddy server as reverse proxy.
Case 1 (using Asus router):
Connected on local network behind router. Server is in the same network as my computer. Everything works like a charm in and out of my network.
Case 2 (using internet provider router):
Connected on local network behind router. Can't access server with domain. Works with direct IP. Outside network, works as in case 1.
I used same server.
Does anyone know why this problem occured? How can i solve it?
Thanks,
David
Two options I can think of:
You could add a record to whatever DNS server you're using in Case 2.
You could write a short script that runs whenever you change network connections to modify your hosts file accordingly.
This happens when the server you are trying to reach "testpage.example.com" resolves to your router's external IP address. Because your public IP address is the same as server's IP address (even though inside your home network you have different private IP addresses) your requests are lost in the ether.
As a workaround you can resolve the testpage.example.com manually on your local machine.
For Windows c:\windows\system32\etc\hosts
For Linux /etc/hosts
testpage.example.com 192.168.1.102 -> private IP of the machine serving the site.

Ngrok for local network

Trying to share my local web server with only computers connected to our internal network.
If I run ngrok http 192.168.10.10:80 it loads and is public.
I thought running it without http might work but all i get is an unrecognizable command error.
Ideas?
In this case, you don't need to use ngrok while your local web server is connected with the computers in your internal network.
You can access your Web Server via the other computers using its local IP address.

How actually server ports work

Imagine we have a hosting containing:
a search engine running on port 5678 (it's required this port it's open in order to work).
nginx running on port 80.
When a user connects to our website and search something on it, he is only connecting through port 80, but never through 5678. We can check this running "netstat -an".
So my question is: If the client it's never connecting directly with the search engine's port, why we need to keep it open?
Normally client requests are coming to your web server (port 80 or 443), and your web server (your php,or your java code) has a logic to connect to your search engine and send back the result to the client via port 80/443 (local socket connection, if web server and search server running on the same server). so clients need not to connect directly to your search engine port (5678). (from external networks). may be your web server internal interface and search engines internal interface connect locally via local s socket connection.
I'm not sure how you run your web server and search engine, is it two different servers or nginx act as a load balancer and send the client request to your multiple search servers. i think your search engine port use internally to communicate with your web server hosted software. or may be you run both nginx and search server on the same server.
other guess is your firewall or router forwarding port 80 request to your search server port 5678 (port forwarding).
try this on your search server
netstat -pant
this will give your all connection details, like local address,foreign address,state, and PID/Program name
Hope that helps
You can connect to a webserver using a different port. Port 80 is the default for web servers. (port 443 for secure, https, connections) so it's not normally specified since it's 'understood'
But you can, actually, specify a different port to connect to. In your example, a user would specify which port they want to connect to in the URL
http://www.example.com:5678
The same reason why some services live on other ports, like 22, 3000, 3306, 8080, 9000, you might not access those ports directly but maybe some other apps/services/protocols connect to it internally, or could even be not on the same server, like if you have separate app/db/mail servers, they would contact each others by ports.

How do I connect to a local server run by Aptana from an outside network?

I have a rails server that i run from Aptana Studio. I normally connect to it via localhost:300, and everyone on the network connects to it via stonecrab:3000 (stonecrab is the name of my computer). However, how do I allow people from outside the local network to connect to the server? For instance, if the IP of my internet connection is 123.456.7.8, what URL can someone use in a web browser to connect to my server? I have a linksys e1000 router and i can access it if i need to change any settings.
Thanks
By default, your machine will not be accessible from behind the router. You need to enable port forwarding in your router. You need to tell your router to forward port 3000 to the IP of stonecrab. Then you will use 123.456.7.8:3000 to access stonecrabe:3000 from outside the LAN.

Resources