Reputation: 65
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??
Upvotes: 1
Views: 9059
Reputation: 5844
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.)
Upvotes: 4