Why does the user's IP is a local one when accessing the page using the global URL? - asp.net

I am logging every user's IP when they access the company's page.
There are two ways to access the page from inside the local network:
http://company/webpage
and
https://webpage.company.com
What bugs me is that even when the users use the https global IP, their accesses are still recorded on database with their IP as 10.50.1.12 or 10.50.1.100.
Does that means that the browser or something else is redirecting the https://webpage.company.com to company/webpage? Or does that mean that I'm using a flawed method to log the users IP?
Another way to ask my question (just to make sure I'm being clear): if I'm accessing my Internet web page from inside the LAN network, am I effectively going outside my network and then back? If not, where am I going wrong with my logging?
Code used to log user's IP:
user.LastIP = HttpContext.Current.Request.UserHostAddress;
I'm curious about this because I want to make sure the users inside the company will access the page using exclusively the LAN Network. The goal is to save bandwidth usage, which is scarce.
Edit:
Pinging the https://webpage.company.com from inside the LAN network will result in a reply from a global IP address like 194.xxx.xxx.xxx. So I'm clearly getting the user's IP wrongly. What would be the ideal way of retrieving the IP from the page accessing entity?

Access to http://company/webpage will result in a DNS lookup of the host name "company". To resolve this, DNS will need a fully qualified domain name (fqdn), so it will add a top level domain (according to the configured search list in the client). In this example, it seems fair to assume that the fqdn will be "company.com". This, in turn, may very well resolve to the same IP address as the "webpage.company.com". You can check this by using dns lookup utilities like 'nslookup' and 'dig', or simply by using 'ping company' and 'ping webpage.company.com'.
The users IP addresses you mention, 10.50.1.12 and 10.50.1.100, seems to be the local IP addresses of the client hosts. I base this assumption on the fact that these IP addresses come from the RFC-1918 address range which is used for internal addresses. My guess is that these are the correct IP addresses, and that your logging works fine.
The users IP address you will log from accessing 'http://company/webpage' and 'https://webpage.company.com' should in most cases be the same. You can see it this way: it doesn't matter what the target URL is, traffic is still coming from the same host, the same IP address.
In any case, you most probably don't need to worry about any traffic leaving your local network.

Related

Is there a way to access a server from a different device in the same LAN, if device2 doesn't know device1's private IP?

I'm serving an app that I want to be accessible from different devices in the same network. From what I've seen, I can do that by accessing the server's private IP. But the other devices have no way of knowing that. Is there a way to setup something like an internal domain?
For the purposes of this answer I'll refer to HTTP as the protocol, which is by far the widest and most frequently used. If it's something else, the principles are the same.
The first option to consider is 'just' using the IP address. https://192.168.0.3/ isn't so bad to remember; IPv6 is worse, being longer. You could email, chat, or otherwise link your users to the address so you wouldn't have to remember it. Most home networks use DHCP by default, but usually give the same address to the same MAC address unless there's so much device turnover that the ip pool is depleted, so the addresses rarely change in practice. Additionally, most routers leave IP space that is not part of the DHCP pool and you can statically configure that on your server to take any IP changes out of the equation.
The appeal of the IP address method is that it's low investment. It's ready to work now. The downside is that if your IP address does change, your clients now can't reach the service as currently configured. Enter DNS. DNS comes into the equation when the DHCP-provided DNS servers are used by clients to query for the record of names such as stackoverflow.com.
The DNS servers on a home network are usually ones provided by the ISP (or hopefully, because ISPs are typically bad at providing good DNS, you'd point at cloudflare (1.1.1.1) or Google (8.8.8.8, 8.8.4.4) or some other decent DNS provider for public DNS. Either way, the point is, your currently configured DNS servers are probably not able to be configured to serve records of your devising.
That leaves you with 4 options: public DNS, private DNS server, "borrowed" DNS domains, or /etc/hosts.
Public DNS can serve a private IP address, and this is probably the next easiest solution. You'll have to pay to register a domain and buy dns hosting (many dns registrars provide dns service for free). You can then own a name like myhouse.net and add an "A" (address) record for app.myhouse.net with a value of your local IP address. Any public query for the name will look up to your internal IP address, but that's not much of a disclosure (they knew you were on one of the RFC 1918 address spaces) and they could spearfish and xss you just as easily with a domain name, so for home use, I'd call publishing a private ipv4 address to public DNS can essentially be done with impunity. Note these address spaces are non routable - they can't be accessed from the internet and conflict with many other folks' home network IP space as well.
Private DNS. As we've discussed, you probably don't have a DNS server in your network, or you wouldn't be asking this question. You're using public DNS servers for resolution. So there's nowhere for you to define a domain and records like app.myhouse.local. The first step to private DNS would be to create or acquire a server which you can provide via DHCP to your local clients, and can be configured with your private domain records. This server would be configured to also do public queries recursively, so it could be used for all DNS traffic on the network. This way, you get to "invent" your own "private" domain that's not part of public knowledge. This is obviously heavy touch. You might be able to find some sort of service that would allow you to do a thing like this online, otherwise you'll need to install software like Bind or equivalent. On the plus side, it's free, and knowing more about DNS is always a good investment.
"Borowed" DNS - by this I refer to services like https://www.noip.com/ which will allow you to create a host record under one of their domains. They often also include software and an API by means of which you can update the record to point to your dynamic IP address. I do not know whether you could store a private IP address in these services. The domain name would be one of theirs, not one of your choosing (something like myhouse.noip.com) But they're often cheap or free, and they do solve the immediate problem of creating a DNS record. Again, the record would be a private address in public dns and could be queried from anywhere in the world.
/etc/hosts: this file (which also exists in windows, interestingly enough) provides a local system an alternative name resolution system to DNS. It typically takes precedence over DNS (ie it's checked first) and could be used to define a record on most of your hosts. I don't know how you'd do it on tablets or phones, and it's obviously something you'd have to set up in advance - not a great fit for your use case.
Looking at these options, I'd recommend you consider one of the borrowed dns domain providers first. IF that seems good, you're done. If you can't justify putting your private IP address into public DNS, that will force you to go that route. Maybe just using the IP address will work fine.

Google router IP vs Google public IP

I am trying to get the big picture although my primary domain is not networking.
Some question's narrowed down for which I'm not getting enough/proper answers online
Is the IP that is resolved by the DNS server when I hit www.google.com is same as any of the Google router's Gateway IP?
Do bigger companies like Amazon do port forwarding?
If point 2 is true, I suppose they must be port forwarding with only 443 (https) port which means, to use multiple static IP across different data centers, they need to have that many routers. So, if they have N static IP address which resolves to a website, then they must be having N routers right? Is this a fair assumption?
A gateway IP refers to a device on a network which sends local
network traffic to other networks. it sits between you and internet,or other network . its like a watchman.
Question 1 : google.com has multiple ip addresses lets say then , Yes, that is possible, and will need to be two A records. This is called Round-Robin DNS. Clients will semi-randomly use one of the two addresses.
question2: yes port forwarding happens more often than we think. ALL VPC's (virtual private clouds like AWS , GCP , Azure etc) use this as they dont want to expose servers/internal resources to the internet.
depending on the port number , particular service is exposed to requesting client. lets say we want to make a website public , then we explicitly expose port 80(http) 443(https) so that web crawlers and users can see them.
Port forwarding, sometimes called port mapping, allows computers or
services in private networks to connect over the internet with other
public or private computers or services.
google https://www.google.com:444/ wont work because they did not expose port 444 on their cloud router
but https://www.google.com:443/ will work because the server corresponding to google.com has explicitly left it open.
How IP is resolved:
Step 1 - Send a Request to Resolve a Domain Name
When you type www.google.com into a browser, in order to load the webpage, your computer asks for the IP address. Computers do not know in advance where they can find the necessary information, so they try searching through the DNS cache and for available external source. proceed from lower level caches to root/main servers.
Step 2+3 - Try to resolve an IP Locally
Before going externally, your computer loads the local DNS cache database to see if you already requested the IP for that domain name. Every computer has a temporary cache with the most recent DNS requests and attempts to connect to online sources. if required record is present locally its called "CACHE HIT" and query stops.
However A computer’s local DNS cache database does not always contain the necessary data to resolve a domain name this is called a "CACHE MISS" . In that case, the request goes further to your Internet Service Provider (ISP) and its DNS server.
Step 4 - ISPs Ask Outside DNS Servers to Provide an IP Address iff Cache miss
ISP DNS resolvers are configured to ask other DNS servers for correct IP address mapping until they can provide data back to the requester. These are iterative DNS queries.
When a DNS client sends such a request, the first responding server does not provide the needed IP address. Instead, it directs the request to another server that is lower in the DNS hierarchy, and that one to another until the IP address is fully resolved. There are a few stops in this process.
hierarchy looks like this (just for reference):
Root domain nameservers. Root servers themselves do not map IP addresses to domain names. Instead, they hold the information about all top-level domain (TLD) nameservers and point to their location. TLD is the rightmost section of a domain name... Root servers are critical since they are the first stop for all DNS lookup requests.
TLD nameservers. These servers contain the data for second-level domains, such as ‘phoenixnap’ in phoenixnap.com. Previously, the root server pointed to the location of the TLD server. Then, the TLD server needs to direct the request toward the server that contains the necessary data for the website we are trying to reach.
Authoritative nameserver. Authoritative servers are the final destination for DNS lookup requests. They provide the website’s IP address back to the recursive DNS servers. If the site has subdomains, the local DNS server will keep sending requests to the authoritative server until it finally resolves the IP address.
Step 5 - Receive the IP Address
Once the ISP’s recursive DNS server obtains the IP address by sending multiple iterative DNS queries, it finally returns it to your computer. The record for this request now stays cached on the hard drive. The browser can then fetch this IP from the cache and connect it to the website’s server.
ALL this happens in less than 1 second, most of the times. if you just registered a new domain it might take few hours to propagate this DNS cache globally hence newly registered websites do not show up sometimes.
About companies owning multiple IPs
Big companies have pool of IPs reserved for example 123.234.xxx.xxx which means a company has reserved 255*255 ips. they are mapped on a VPC(virtual private cloud)
and accessible vis a subnet masking and CIDR feature, like your EC2 instances on AWS
Is the IP that is resolved by the DNS server when I hit www.google.com is same as any of the Google router's Gateway IP?
For sure it should, but it is mostly a Google management question that only they will be able to answer right. The thing is that we must understand how DNS query's work for this.
Let's take a look of it:
Device A requests the IP address through a DNS query of the device B.
To do this, it uses the network port 53 (Domain) on which it will ask, depending on which DNS server is being used at the time, which is usually the home router. Then the router will ask the ISP's DNS server, which will respond with a cached response, or the query with another server on top of it if it does not have one; All this process is followed until a reliable cache response is reached or until the authoritative response server is reached, that is, the name server that manages the domain in question.
Only the authoritative response server contains the reliable information of which IP of the domain which is going to be reached.
I suppose that within Google's servers and its network they use Google's own DNS servers, which are 8.8.8.8 and 8.8.4.4 where the DNS records are obtained and consulted by caching from many sites.
In general terms Google's IP will change depending on where you are, I made a DIG query to Google's authoritative servers, however, I received a result based on location to improve the route and loading time of the site which was 142.250.73.238.
Do bigger companies like Amazon do port forwarding?
Yes, they do. To handle queries with load balancers or similar and even for caching dns requests.
If point 2 is true, I suppose they must be port forwarding with only 443 (https) port which means, to use multiple static IP across different data centers, they need to have that many routers. So, if they have N static IP address which resolves to a website, then they must be having N routers right? Is this a fair assumption?
This has multiple answers. By the way, they actually can do a secure DNS query.
if they have N static IP address which resolves to a website, then they must be having N routers right?
They don't have to, but if they want to they can.
"Is this a fair assumption?"
No, the IP's doesn't depend on a router, the router only routes to a computer/server which can have multiple IP's. By the other hand, each thing (computer, server, etc... must have an IP which can be also a WAN IP).

FTP to external address from server on internal network

I am at a large University, with servers set up on the Univeristy network. The network has internal (10...) IP addresses, and external (129...) IP addresses. I have a ColdFusion-based business process which FTP's data from an external server.
The server on which the ColdFusion instance is based has several (about 10) IP addresses associated with it, both internal and external. It has one primary address, which has been, until recently, external.
Using Wireshark, we have been able see which IP is used, and it is never the primary, but other than that, does not seem to follow any logic.
We recently changed the primary IP for the server to an internal address, to comply with new University-wide security policies, and the FTP connection from Coldfusion stopped working. Using Wireshark, we've confirmed it is going out on one of the internal (10...*) IP addresses (not the primary).
Is there a way to control which IP ColdFusion uses for an FTP connection, either through system configuration, or programmatically?
Code for the FTP call:
var ftpService= new ftp(
username = partnerConfig.sftpLogin,
connection = "MyConnection",
password = partnerConfig.sftpPw,
fingerprint = partnerConfig.sftpFingerprint,
server = partnerConfig.sftpServer,
secure = "yes"
);
var result=ftpService.open();
var result2=ftpService.listdir(directory = partnerConfig.inFolder, name="dirlist");
var result3=result2.getResult();
EDIT: My server guy tells me that this University is fairly unique in how it configures the subnets. NO firewall exceptions are allowed from the 10.* subnet. The "Public" IP's are not public by default, simply the ones which are capable of having exceptions.
FURTHER EXPLANATION: It comes down to the Rules and IP addresses the main IT org at the university set up. the 10.x.x.x IPs are never allowed access outside the university ("internal"). 129.x.x.x IP, may have firewall exceptions ("external"). If I type ipconfig (it's Windows), I see about 10 static IP addresses, half of which are 10.x.x.x, and half of which are 129.x.x.x. When the "primary" IP for the machine was a 129.x.x.x address, Coldfusion chose one of the OTHER 129.x.x.x addresses for the outgoing IP for the connection. With the "primary" IP switched to a 10.x.x.x IP, ColdFusion is choosing one of the OTHER 10.x.x.x addresses for the outgoing connection. My choices, as far as I can tell are 1) Switch the primary back to a 129.x.x.x for the server; 2) Move the site to a different server with a primary of 129.x.x.x, and keep other sites on the server in compliance with the new policy; 3)See if I can figure out how to control which IP Coldfusion chooses from the 10 static IPs on the server.
Our admin figured it out. We needed to add a static route to the server, so that whenever ColdFusion (or any application) tries to connect to the specific destination we were FTPing to, it goes through a specific outgoing IP address.
This was not something I was familiar with, but a quick search gives the basics: http://technet.microsoft.com/en-us/library/dd469825.aspx
You have an internal IP address and you are not sure what the external is? This sound like a network bridge issue. What you are looking for is FTP proxy or some tool that associates an externally assigned IP to an internally assigned IP for port 22 (or whatever you set your port to). Look at: http://wiki.squid-cache.org/Features/FtpGateway
FTP reverse proxy
It sounds like your IPs (even internally may not be static)...or maybe it just feels that way. Make sure your internal IP is static.
Read about FTP port forwarding: Here are some port forwarding guides.
Other keywords FTP bridge, FTP one-to-one mapping, among others.
Good luck.
I had a similar question regarding the cfmail tag:
Force cfmail tag to send from a specfic server IP address
Unfortunately, I didn't get an answer that worked. ColdFusion seems to pick (seemingly at random) which source IP address is used.

How to stop redirect to default website when IP address is entered in the address bar of the browser?

I have multiple websites hosted on our server. When someone types the IP address in the address bar of the Browser It redirects to one of the websites hosted on the server. Is there any way by which I can set the default website which is opened when some one types the IP address. Same IP address is being shared by multiple websites.
1 IP address can only bind to 1 IIS Entry. So what you need to do is to pick the IIS entry you want, go the "Binding" section and bind your IP as the binding header.
ex: If your IP is 1.1.1.1 , then in binding header, you put 1.1.1.1, in IP address, you also choose 1.1.1.1.
After you setup this binding, you can browse to 1.1.1.1 and it'll open your site.
Remember to make sure all other sites doesn't have this binding. Otherwise, it'll have an conflict.
All you have to do is leave off the IP address and host name entries, and provided you have only a single website matching that, that site will become the 'default', while your other sites will have specific host name(s) they respond to.
I am not sure, but you may have to add a specific host in the C:\\Windows\System32\drivers\etc\hosts file, giving IP address and its corresponding address, this definitely works from logging into the website where it is hosted, i.e on the hosting server.
For logging from different IP machines, try the same logic - in this case make sure that the gateway is same for LAN.
Let's see what happens in this case ??

Access localhost from another computer not on network

Before you say that it is a dupe, this is not the same as this, this, this or this.
My question is how do you do it globally.
For instance, consider this. I have EasyPHP running in my computer. At present my ip address (global) is 223.231.178.118
Now, let's say there is someone else (maybe in a different country altogether) who wants to access my ip (223.231.178.118). I do know how to access 192.168.x.x from the same network. I just want to know how you can do this globally, if possible.
P.S 1 : The computer running EasyPHP is behind a router.
P.S 2 : My IP (local IP is, but global one is not) is not static. But let us assume the person who wants to access my localhost does know my Dynamic IP. For example, let us assume I tell the person who wants to access my localhost is my friend and I tell him over phone what my IP is.
You can use tools just like ngrok or Forward
more tools are in this post Accessing localhost From Anywhere
Your local IP address "192.168.x.x" is only known to your router and unknown to everyone outside your LAN. The global IP address (223.231.178.118 in your example) is the global address of your router.
To be able to access the EasyPHP server on your local computer you need to forward the corresponding port (for http webservers the default is 80 but it might be different for EasyPHP) from your router to your local IP. You need to check your routers manual on how to do this.
After you have done that you can just tell the person who wants to access your local computer the global ip address of your router and he will see your EasyPHP response by browsing to that global address.

Resources