When i try to use [nc -l] command with my private IP address,i am able to create a client server model.But it doesn't work when i try to use my public IP address with the same port number.It gives me the following error:-
nc: Can't assign requested address
Why??
Your problem is that your public IP is the IP of your router, not your computer.
Simplified, your network probably looks like this (IP addresses are only examples):
+--------------+ +-----------------+----------------+
| PC |-----|Router (internal)|Router(external)|---... Internet
| 192.168.0.10 | |192.168.0.1 |123.132.122.133 |
+--------------+ +-----------------+----------------+
Your PC's internal address is 192.168.0.10, and that's the only address it knows. The router routes traffic to other networks; for that it has two interfaces, the internal one with the address 192.168.0.1 and the internet-facing one (123.132.122.133). On your PC, you can't listen on the latter address, since that's the router's address, not the one of the PC.
So the solution is to listen on the internal IP, and setup the router to forward traffic of the respective port to the corresponding port on your PC. Beware of the security implications, though! (E.g. leaving a root shell open to the internet might not be the best idea.)
Related
If I type ipconfig in my system, I am getting an ip address which is different from what I get from google(what is my ip). Which IP address needs to be considered?
The ipconfig command on Windows provides the actual address used by the computer.
Address given by 'what-is-my-ip' tool is the publicly advertised address of either the Proxy server or the Gateway Router via which the computer connects to the Internet.
{ Internet } --> what-is-my-ip sees
+ all computers behind gateway
| as 54.102.3.209
|
|
| 54.102.3.209 --> Public address of Gateway
+------+------+ Advertised to the internet
| Gateway |
| Router | --> NAT is performed by Gateway
+------+------+
| 10.1.1.254 --> Internal address known to LAN
|
|
+-----------+----------+
| | |
+---+---+ +---+---+ +---+---+
| host 1| | ..... | | host n|
+-------+ +-------+ +-------+
10.1.1.15 10.1.1.101 10.1.1.4 --> Actual addresses of computers in LAN
(shown by ipconfig)
IP Address uniquely identifies the computer in a network.
There are 2 kinds of addresses:
Public (Globally unique and need to be purchased),
Private (Locally unique and free)
(10.x.x.x, 172.16.0.0 to 172.31.255.255, 192.168.x.x)
It is usual practice for LANs (local area networks) to have private addresses for all computers, and only one public address for the Gateway Router.
This method of using private addresses for all computers and only one public address for Gateway provides these 2 major benefits:
Cost of owning IP Addresses can be reduced (all private addresses are free)
Depletion of IP addresses can be controlled
(Every device on Internet cannot get a unique public address, as the number of addresses supported by IPv4 format is far lower than the number of devices connected to the Internet)
Gateway Router is the device that connects the LAN or groups of LANs to the Internet.
The Gateway needs to have a public address, in order to allow the internet hosts to reach it.
The Gateway router uses the technique of Network Address Translation (NAT) to allow the computers behind it, which have private addresses, to reach the internet, via the gateway.
The internet sees the address of Gateway Router as the IP address of all computers with private addresses that are behind it.
ipconfig returns your local ip address. May be you are in some local network and connected to ani switch or router or mikrotik.
Ip address is returned from "what is my ip" is the ip addres of this router/switch/mikrotik.
If you type ipconfig you get your local address, which is typically not the public address seen on the Internet.
Just to explain you that, take a look at this picture:
https://www.devadmin.it/wp-content/uploads/2018/07/072418_1033_Accessoremo1.png
What does it mean?
You have an address to talk to your router.
Your router has another address to talk to your Internet Service Provider.
Typically, there are different scenarios, based on how the Internet Service Provider manages the IPs on the public Internet.
You can have a dynamic IP assigned only to your router. Please, take a look at the following image: https://www.devadmin.it/wp-content/uploads/2018/07/072418_1033_Accessoremo3.png
You can have a dynamic IP shared with other routers. Please, take a look at this image: https://www.devadmin.it/wp-content/uploads/2018/07/072418_1033_Accessoremo4.png
You can have a static IP. It means that your Home network is always reachable from outside with that IP. This typically needs a special contract with you ISP and you may pay more money to have this contract. Please, take a look at this image:
https://www.devadmin.it/wp-content/uploads/2018/07/072418_1033_Accessoremo2.png
When I say Dynamic IP, it means that your ISP can dynamically assign an IP on the Internet every time you connect to the Internet.
You should think about your internal IP as the room in your house where you are located (bedroom or kitchen) and your ISP's IP assigned to you is the building where you live (a street address).
If you live in a condominium, different people can have your same address.
In that case, think about the IP between your ISP and your router as the apartment number.
Your ISP knows the number of your apartment and knows how to deliver messages to you, no matter if you are in the bedroom or in the kitchen.
It is your private router that knows in which room of the apartment you are. Think about rooms as the devices you have in your flat (Computer, Tablet, Smartphone, etc.).
Your device only returns by ipconfig its actual IP address, not the public IP.
Sites like "What is my IP" cannot read your device internal IP and they see your public IP on the Internet.
Sorry for the examples, but I think this is a good way to understand the topic.
Here is the scenario:
I have asked my ISP to give me public IP, which I can connect to my laptop and access from other outside network. They gave me following
IP : 103.51.2.198
subnet mask : 255.255.255.248
default Gateway : 103.51.2.193
preferred dns : 8.8.8.8
Alternate dns : 8.8.4.4
I have connected PPPoE connection in my laptop (not in router) and set these values at TCP/IP V4. My internet connection is fine.
But If I ping from other network by this IP (103.51.2.198), request is timed out.
Than I checked whatsmyrealip. and the IP is (103.51.2.102). this IP is a public IP of my ISP provider. And they are trying to give me an IP from that IP.
My ISP providers are not expert in networking nor am I. They are also not sure how they can give me a public IP.
I am not sure about what are they trying to do. and how will they give me another IP from a public IP. It will be very helpful, If anyone can explain the problem. and give a solution.
First of all, it's called public IP not "realIP".
Anyways, the answer for your question is:
You cannot access your home computer because it is behind NAT so it is unreachable from the outside of your network.
Quick example on how NAT works:
Scenario:
Private IP: 192.168.0.10
Public IP: 1.2.3.4
You are connecting to webserver on IP: 5.5.5.5
What happens:
You send data to your router, telling it that you want something from
5.5.5.5, your router assigns you a random port, let's say 11111,
sends the data with source IP 1.2.3.4 and port 11111. Stuff
happens on the webserver and the data comes back. Router reads it and
remembers that everything going to 1.2.3.4:11111 belongs to
192.168.0.10 so it sends you the data.
Here everything works because it's your computer the one starting the connection, otherwise, the webserver would never be able to connect to you.
What's the difference between these 2 local ip addresses? In terms of pro's , con's and usage?
Those a simply two separate IPv4 addresses.
The 172.0.0.1 address is a public address which should not be used unless you have been assigned the address block containing it by an RIR or your ISP (which was assigned the address block containing it).
The 192.168.0.1 address is a private address which anyone may use in a private network. This address cannot be routed on the public Internet.
I suppose you are talking about 172.16.0.0 because it makes no sense to compare 172.0.0.0 with 192.168.0.0 because 172.0.0.0 is a public IP address.
If you are talking about 172.16.0.0 instead of 172.0.0.0, then... both are private IP address. They are defined in the RFC1918
There is a good overview at the Wikipedia page but the main difference is the size of the segment.
The address 172.0.0.1 is not a local address, it is a web address.
If you instead meant 127.0.0.1 this is what is refereed to as the "Loop back" IP, and is often referred to as localhost. Connections to this IP target the computer of origin, and are intercepted by the network card in your computer and fed back into the same computer.
192.168.0.1 is an IP on your local network, this may or may not be your computer. This address is assigned by your DHCP server on your local network (usualy running on the router) and is subject to change unless you have configured your DHCP server to make it static
Which to use?
172.0.0.1 Use when you are trying to connect to a website/remote computer at that IP (most likely not you)
192.168.0.1 Use when you are trying to connect a computer/device on your local network that you know will be at 192.168.0.1
127.0.0.1 or localhost Use when you are trying to connect to a port on the same computer you are already on
I have a machine in my private network with IP 192.168.1.10
I have a DNS name, "toto.mydns.com", a DNS client is running on the machine.
I configured the router for Port forwarding.
I can access the machine when i am outside my home, when using a pulic IP address it works but when i am at home and i get a dynamic IP address trough DHCP from my router, i cannot use toto.mydns.com anymore, i must use 192.168.1.10 to access.
I would like to know if i need to configure something on the router for that ?
Thank you !
toto.mydns.com will resolve to your external public IP
There will almost certainly be nothing routing that IP through to your router, and thus through NAT to your internal address.
The easiest way to resolve this (Pun very much intended) is to have a hosts file entry on your computers running inside your network so that they resolve the same DNS address to the internal address.
A much harder, but more fun, way would be to set up your own DNS server inside your network, have the DHCP dish it out as the primary DNS server for your network and put in an entry for your internal address :D
Have fun...
Toto.mydns.com is accessible from outside,this DNS is assigned on a machine with a static IP address(sorry not dynamic),so the IP of this machine is 192.168.1.10.
Whrn i am at home in my private network i need to enter 192.168.1.10 and toto.mydns.com does not work.Any help???
Suppose that I am sharing a public ip 56.162.XXX.XXX with some other users. Now I have a local ip that I see if I type ipconfig in the command prompt. That is 192.168.2.3. Now I have a program running on port 3630 listening to any incoming connection. I can call myself with the help of loop back ip ie. telnet 127.0.0.1 3630, and i see that two programs are getting connected and can exchange data. I can also telnet and get connected with my laptop from another laptop which is sharing same public ip as mine by the command telnet 192.168.4.20 3630. But how should I do the same from a remote computer? I mean a computer which has a different public ip.
Actually I want something like "telnet public ip(local ip) port no". The other computer is also sharing a public ip with some other users.
You will need to setup some kind of NAT (Network Address Translation) or PAT (Port Address Translation) that will forward the requests for port 3630 to your local IP.
The actual configuration to use will depend on your firewall/router. If you have a standard ADSL router, there is likely to be a configuration page in there that will allow you to do this.
You will need to read up on port forwarding and NAT.
http://en.wikipedia.org/w/index.php?title=Port_forwarding