What's the difference between a machine's IP address and localhost
up vote
10
down vote
favorite
Doubt has raised from my another question Where if i give localhost to my path, it works. But it doesn't work if i give my system ip.
127.0.0.1 is mapped to localhost in my /etc/hosts. Do i need to map my ip to localhost? Doesn't change?
Aren't they same?
ip
add a comment |
up vote
10
down vote
favorite
Doubt has raised from my another question Where if i give localhost to my path, it works. But it doesn't work if i give my system ip.
127.0.0.1 is mapped to localhost in my /etc/hosts. Do i need to map my ip to localhost? Doesn't change?
Aren't they same?
ip
add a comment |
up vote
10
down vote
favorite
up vote
10
down vote
favorite
Doubt has raised from my another question Where if i give localhost to my path, it works. But it doesn't work if i give my system ip.
127.0.0.1 is mapped to localhost in my /etc/hosts. Do i need to map my ip to localhost? Doesn't change?
Aren't they same?
ip
Doubt has raised from my another question Where if i give localhost to my path, it works. But it doesn't work if i give my system ip.
127.0.0.1 is mapped to localhost in my /etc/hosts. Do i need to map my ip to localhost? Doesn't change?
Aren't they same?
ip
ip
edited yesterday
Rui F Ribeiro
38.6k1479128
38.6k1479128
asked Feb 12 '15 at 12:44
Gops AB
2081312
2081312
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
12
down vote
accepted
Some services are configured to only listen on the localhost IP address.
An example would be a MySQL database - you want your PHP application running on the same server to connect to it, but don't want any external services or even hackers from the outside to connect. By configuring MySQL to only accept localhost addresses (127.0.0.1
for example) and not your server's real IP address (10.x.x.x
for example) you are reducing the chance of being compromised.
So, to answer your question - yes, they are different.
localhost
is given an ip address in the 127.0.0.0
network and given to a virtual loopback network device lo
. This device is present on all systems, regardless of whether they have a physical network device fitted (WiFi or Ethernet, for example). A system that is not connected to any network will have this loopback device and hence a 127.0.0.0
address. The name localhost
is simply a name that resolves to this IP address and is configured in /etc/hosts
.
Your real IP address (10.x.x.x for example) is allocated to a network device. This is usually a physical network device (WiFi or Ethernet) although advanced setups using tun
or tap
devices can use them too. Again, the name resolution (for example www.example.org
to 10.0.1.1
) can be configured in /etc/hosts
or can be set up to use DNS.
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
add a comment |
up vote
4
down vote
When you access localhost
, your /etc/hosts
file will tell your computer not to look any further and redirects you to your own computer. When you access the local IP adress, your computer will ask the router to fetch the data, and your router will then point back to your computer.
3
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
add a comment |
up vote
4
down vote
127.0.0.1
is localhost
, it's the address of the current machine, accessed through a loopback interface (not through the network adapter - this works even if there is no network chips in the system).
The ip that you get from the router is a different story: it's the address that allows other computer on the network to find you. Well, you can use that ip on the same machine too, but it works differently as before: it's going out to the router and in again (I'm simplifying here, but that's the general idea).
And if you are connected to the internet, you also get another ip from your ISP - the ip by which other computer all over the world find you. However, these two at least refer to the same network adapter (eth0
or the wireless card or whatever). localhost
is different.
The operating system, the servers and so on... can behave differently when accessed from localhost
. You usually don't have a firewall for that, and many local services have a localhost
interface that is meant simply to communicate with an application. Many times, you will want to test your web server by first hooking it up to listen on localhost
only, so you can check if it works, but other people can't. Then, you can reconfigure to listen on your external ip address and start serving the website (and test again if everything still works).
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
You need a connection to the router, otherwise you will getnetwork is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.
– orion
Feb 12 '15 at 14:44
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f184447%2fwhats-the-difference-between-a-machines-ip-address-and-localhost%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
12
down vote
accepted
Some services are configured to only listen on the localhost IP address.
An example would be a MySQL database - you want your PHP application running on the same server to connect to it, but don't want any external services or even hackers from the outside to connect. By configuring MySQL to only accept localhost addresses (127.0.0.1
for example) and not your server's real IP address (10.x.x.x
for example) you are reducing the chance of being compromised.
So, to answer your question - yes, they are different.
localhost
is given an ip address in the 127.0.0.0
network and given to a virtual loopback network device lo
. This device is present on all systems, regardless of whether they have a physical network device fitted (WiFi or Ethernet, for example). A system that is not connected to any network will have this loopback device and hence a 127.0.0.0
address. The name localhost
is simply a name that resolves to this IP address and is configured in /etc/hosts
.
Your real IP address (10.x.x.x for example) is allocated to a network device. This is usually a physical network device (WiFi or Ethernet) although advanced setups using tun
or tap
devices can use them too. Again, the name resolution (for example www.example.org
to 10.0.1.1
) can be configured in /etc/hosts
or can be set up to use DNS.
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
add a comment |
up vote
12
down vote
accepted
Some services are configured to only listen on the localhost IP address.
An example would be a MySQL database - you want your PHP application running on the same server to connect to it, but don't want any external services or even hackers from the outside to connect. By configuring MySQL to only accept localhost addresses (127.0.0.1
for example) and not your server's real IP address (10.x.x.x
for example) you are reducing the chance of being compromised.
So, to answer your question - yes, they are different.
localhost
is given an ip address in the 127.0.0.0
network and given to a virtual loopback network device lo
. This device is present on all systems, regardless of whether they have a physical network device fitted (WiFi or Ethernet, for example). A system that is not connected to any network will have this loopback device and hence a 127.0.0.0
address. The name localhost
is simply a name that resolves to this IP address and is configured in /etc/hosts
.
Your real IP address (10.x.x.x for example) is allocated to a network device. This is usually a physical network device (WiFi or Ethernet) although advanced setups using tun
or tap
devices can use them too. Again, the name resolution (for example www.example.org
to 10.0.1.1
) can be configured in /etc/hosts
or can be set up to use DNS.
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
add a comment |
up vote
12
down vote
accepted
up vote
12
down vote
accepted
Some services are configured to only listen on the localhost IP address.
An example would be a MySQL database - you want your PHP application running on the same server to connect to it, but don't want any external services or even hackers from the outside to connect. By configuring MySQL to only accept localhost addresses (127.0.0.1
for example) and not your server's real IP address (10.x.x.x
for example) you are reducing the chance of being compromised.
So, to answer your question - yes, they are different.
localhost
is given an ip address in the 127.0.0.0
network and given to a virtual loopback network device lo
. This device is present on all systems, regardless of whether they have a physical network device fitted (WiFi or Ethernet, for example). A system that is not connected to any network will have this loopback device and hence a 127.0.0.0
address. The name localhost
is simply a name that resolves to this IP address and is configured in /etc/hosts
.
Your real IP address (10.x.x.x for example) is allocated to a network device. This is usually a physical network device (WiFi or Ethernet) although advanced setups using tun
or tap
devices can use them too. Again, the name resolution (for example www.example.org
to 10.0.1.1
) can be configured in /etc/hosts
or can be set up to use DNS.
Some services are configured to only listen on the localhost IP address.
An example would be a MySQL database - you want your PHP application running on the same server to connect to it, but don't want any external services or even hackers from the outside to connect. By configuring MySQL to only accept localhost addresses (127.0.0.1
for example) and not your server's real IP address (10.x.x.x
for example) you are reducing the chance of being compromised.
So, to answer your question - yes, they are different.
localhost
is given an ip address in the 127.0.0.0
network and given to a virtual loopback network device lo
. This device is present on all systems, regardless of whether they have a physical network device fitted (WiFi or Ethernet, for example). A system that is not connected to any network will have this loopback device and hence a 127.0.0.0
address. The name localhost
is simply a name that resolves to this IP address and is configured in /etc/hosts
.
Your real IP address (10.x.x.x for example) is allocated to a network device. This is usually a physical network device (WiFi or Ethernet) although advanced setups using tun
or tap
devices can use them too. Again, the name resolution (for example www.example.org
to 10.0.1.1
) can be configured in /etc/hosts
or can be set up to use DNS.
edited Feb 12 '15 at 14:49
answered Feb 12 '15 at 13:08
garethTheRed
23.9k36079
23.9k36079
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
add a comment |
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
Explains with security example. Thanks
– Gops AB
Feb 12 '15 at 14:19
add a comment |
up vote
4
down vote
When you access localhost
, your /etc/hosts
file will tell your computer not to look any further and redirects you to your own computer. When you access the local IP adress, your computer will ask the router to fetch the data, and your router will then point back to your computer.
3
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
add a comment |
up vote
4
down vote
When you access localhost
, your /etc/hosts
file will tell your computer not to look any further and redirects you to your own computer. When you access the local IP adress, your computer will ask the router to fetch the data, and your router will then point back to your computer.
3
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
add a comment |
up vote
4
down vote
up vote
4
down vote
When you access localhost
, your /etc/hosts
file will tell your computer not to look any further and redirects you to your own computer. When you access the local IP adress, your computer will ask the router to fetch the data, and your router will then point back to your computer.
When you access localhost
, your /etc/hosts
file will tell your computer not to look any further and redirects you to your own computer. When you access the local IP adress, your computer will ask the router to fetch the data, and your router will then point back to your computer.
answered Feb 12 '15 at 13:19
serenesat
9201519
9201519
3
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
add a comment |
3
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
3
3
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
@serenesat - No. When you access your 'real' IP address, you will not go as far as the router - you won't even leave that machine. Trying pinging your local IP address and look at the round trip times...
– garethTheRed
Feb 12 '15 at 14:38
add a comment |
up vote
4
down vote
127.0.0.1
is localhost
, it's the address of the current machine, accessed through a loopback interface (not through the network adapter - this works even if there is no network chips in the system).
The ip that you get from the router is a different story: it's the address that allows other computer on the network to find you. Well, you can use that ip on the same machine too, but it works differently as before: it's going out to the router and in again (I'm simplifying here, but that's the general idea).
And if you are connected to the internet, you also get another ip from your ISP - the ip by which other computer all over the world find you. However, these two at least refer to the same network adapter (eth0
or the wireless card or whatever). localhost
is different.
The operating system, the servers and so on... can behave differently when accessed from localhost
. You usually don't have a firewall for that, and many local services have a localhost
interface that is meant simply to communicate with an application. Many times, you will want to test your web server by first hooking it up to listen on localhost
only, so you can check if it works, but other people can't. Then, you can reconfigure to listen on your external ip address and start serving the website (and test again if everything still works).
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
You need a connection to the router, otherwise you will getnetwork is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.
– orion
Feb 12 '15 at 14:44
add a comment |
up vote
4
down vote
127.0.0.1
is localhost
, it's the address of the current machine, accessed through a loopback interface (not through the network adapter - this works even if there is no network chips in the system).
The ip that you get from the router is a different story: it's the address that allows other computer on the network to find you. Well, you can use that ip on the same machine too, but it works differently as before: it's going out to the router and in again (I'm simplifying here, but that's the general idea).
And if you are connected to the internet, you also get another ip from your ISP - the ip by which other computer all over the world find you. However, these two at least refer to the same network adapter (eth0
or the wireless card or whatever). localhost
is different.
The operating system, the servers and so on... can behave differently when accessed from localhost
. You usually don't have a firewall for that, and many local services have a localhost
interface that is meant simply to communicate with an application. Many times, you will want to test your web server by first hooking it up to listen on localhost
only, so you can check if it works, but other people can't. Then, you can reconfigure to listen on your external ip address and start serving the website (and test again if everything still works).
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
You need a connection to the router, otherwise you will getnetwork is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.
– orion
Feb 12 '15 at 14:44
add a comment |
up vote
4
down vote
up vote
4
down vote
127.0.0.1
is localhost
, it's the address of the current machine, accessed through a loopback interface (not through the network adapter - this works even if there is no network chips in the system).
The ip that you get from the router is a different story: it's the address that allows other computer on the network to find you. Well, you can use that ip on the same machine too, but it works differently as before: it's going out to the router and in again (I'm simplifying here, but that's the general idea).
And if you are connected to the internet, you also get another ip from your ISP - the ip by which other computer all over the world find you. However, these two at least refer to the same network adapter (eth0
or the wireless card or whatever). localhost
is different.
The operating system, the servers and so on... can behave differently when accessed from localhost
. You usually don't have a firewall for that, and many local services have a localhost
interface that is meant simply to communicate with an application. Many times, you will want to test your web server by first hooking it up to listen on localhost
only, so you can check if it works, but other people can't. Then, you can reconfigure to listen on your external ip address and start serving the website (and test again if everything still works).
127.0.0.1
is localhost
, it's the address of the current machine, accessed through a loopback interface (not through the network adapter - this works even if there is no network chips in the system).
The ip that you get from the router is a different story: it's the address that allows other computer on the network to find you. Well, you can use that ip on the same machine too, but it works differently as before: it's going out to the router and in again (I'm simplifying here, but that's the general idea).
And if you are connected to the internet, you also get another ip from your ISP - the ip by which other computer all over the world find you. However, these two at least refer to the same network adapter (eth0
or the wireless card or whatever). localhost
is different.
The operating system, the servers and so on... can behave differently when accessed from localhost
. You usually don't have a firewall for that, and many local services have a localhost
interface that is meant simply to communicate with an application. Many times, you will want to test your web server by first hooking it up to listen on localhost
only, so you can check if it works, but other people can't. Then, you can reconfigure to listen on your external ip address and start serving the website (and test again if everything still works).
edited Feb 12 '15 at 15:41
somethingSomething
1,744103158
1,744103158
answered Feb 12 '15 at 13:24
orion
9,0831833
9,0831833
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
You need a connection to the router, otherwise you will getnetwork is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.
– orion
Feb 12 '15 at 14:44
add a comment |
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
You need a connection to the router, otherwise you will getnetwork is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.
– orion
Feb 12 '15 at 14:44
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
Thanks for long explanation. Another doubt raised: If i say my service to localhost, it ll not go to router. But if i specify ip, it ll b redirected by router. So i must have internet connection in my second case. Not with the localhost. Please let me know
– Gops AB
Feb 12 '15 at 14:19
You need a connection to the router, otherwise you will get
network is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.– orion
Feb 12 '15 at 14:44
You need a connection to the router, otherwise you will get
network is unreachable
or something similar. The trick is that (at least with dhcp) it's the router that gives you a LAN ip in the first place. It's possible that this varies in some cases if the route persists, but in essence, for LAN ip, you need LAN, and for external ip, you need a connection to ISP.– orion
Feb 12 '15 at 14:44
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f184447%2fwhats-the-difference-between-a-machines-ip-address-and-localhost%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown