'ping' uses localhost instead of public IP address
Let's say my server has IP address 11.22.33.44 and hostname server1.mydomain.com.
When I ping server1.mydomain.com, it looks as if ping is actually using the public IP address:
# ping server1.mydomain.com
PING server1.mydomain.com (11.22.33.44) 56(84) bytes of data.
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=1 ttl=64 time=0.014 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=2 ttl=64 time=0.012 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=3 ttl=64 time=0.011 ms
But with tcpdump, I can see no ICMP traffic on eth0 and instead see the pings coming through lo:
# tcpdump -i lo
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
08:43:49.076918 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 1, length 64
08:43:49.076931 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 1, length 64
08:43:50.075913 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 2, length 64
08:43:50.075924 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 2, length 64
08:43:51.074911 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 3, length 64
08:43:51.074919 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 3, length 64
This behaviour is not limited to ping. I get the same with wget.
Why is this happening? Is this something caused by the configuration on my server?
I am using Debian 9 (Stretch).
networking routing wget ping tcpdump
|
show 8 more comments
Let's say my server has IP address 11.22.33.44 and hostname server1.mydomain.com.
When I ping server1.mydomain.com, it looks as if ping is actually using the public IP address:
# ping server1.mydomain.com
PING server1.mydomain.com (11.22.33.44) 56(84) bytes of data.
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=1 ttl=64 time=0.014 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=2 ttl=64 time=0.012 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=3 ttl=64 time=0.011 ms
But with tcpdump, I can see no ICMP traffic on eth0 and instead see the pings coming through lo:
# tcpdump -i lo
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
08:43:49.076918 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 1, length 64
08:43:49.076931 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 1, length 64
08:43:50.075913 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 2, length 64
08:43:50.075924 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 2, length 64
08:43:51.074911 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 3, length 64
08:43:51.074919 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 3, length 64
This behaviour is not limited to ping. I get the same with wget.
Why is this happening? Is this something caused by the configuration on my server?
I am using Debian 9 (Stretch).
networking routing wget ping tcpdump
1
This is correct behaviour. There's no need for the machine to send packets destined for itself via the Ethernet NIC, so it doesn't.
– roaima
15 hours ago
@roaima - I disagree. It is not up to the network stack to decide what is "needed". I have clearly specified I want to ping the IP address associated witheth0. If I had wanted to ping localhost, I would have used127.0.0.1instead.
– Martin Vegter
15 hours ago
4
You wanted to ping the machine at 11.22.33.44 (or server1.mydomain.com) and you did... The interface is irrelevant in your case because your packet does not need to be routed.
– std_unordered_map
13 hours ago
1
You may block all the exits in or out of your "room", but it won't stop you from reaching your "room" if you are already there...
– std_unordered_map
13 hours ago
8
Physically, if it actually went out oneth0it wouldn't be received, an Ethernet interface doesn't "hear" what it's sending. So in any case, there needs to be a shortcut somewhere that says "oh this is a local packet, it must be handled locally". Probably easier to redirect the packet tolo0than adding a "handle outbound traffic as inbound path", though one would have to check the relevant RFCs for correctness.
– jcaron
12 hours ago
|
show 8 more comments
Let's say my server has IP address 11.22.33.44 and hostname server1.mydomain.com.
When I ping server1.mydomain.com, it looks as if ping is actually using the public IP address:
# ping server1.mydomain.com
PING server1.mydomain.com (11.22.33.44) 56(84) bytes of data.
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=1 ttl=64 time=0.014 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=2 ttl=64 time=0.012 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=3 ttl=64 time=0.011 ms
But with tcpdump, I can see no ICMP traffic on eth0 and instead see the pings coming through lo:
# tcpdump -i lo
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
08:43:49.076918 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 1, length 64
08:43:49.076931 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 1, length 64
08:43:50.075913 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 2, length 64
08:43:50.075924 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 2, length 64
08:43:51.074911 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 3, length 64
08:43:51.074919 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 3, length 64
This behaviour is not limited to ping. I get the same with wget.
Why is this happening? Is this something caused by the configuration on my server?
I am using Debian 9 (Stretch).
networking routing wget ping tcpdump
Let's say my server has IP address 11.22.33.44 and hostname server1.mydomain.com.
When I ping server1.mydomain.com, it looks as if ping is actually using the public IP address:
# ping server1.mydomain.com
PING server1.mydomain.com (11.22.33.44) 56(84) bytes of data.
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=1 ttl=64 time=0.014 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=2 ttl=64 time=0.012 ms
64 bytes from server1.mydomain.com (11.22.33.44): icmp_seq=3 ttl=64 time=0.011 ms
But with tcpdump, I can see no ICMP traffic on eth0 and instead see the pings coming through lo:
# tcpdump -i lo
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
08:43:49.076918 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 1, length 64
08:43:49.076931 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 1, length 64
08:43:50.075913 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 2, length 64
08:43:50.075924 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 2, length 64
08:43:51.074911 IP server1.mydomain.com > server1.mydomain.com: ICMP echo request, id 8525, seq 3, length 64
08:43:51.074919 IP server1.mydomain.com > server1.mydomain.com: ICMP echo reply, id 8525, seq 3, length 64
This behaviour is not limited to ping. I get the same with wget.
Why is this happening? Is this something caused by the configuration on my server?
I am using Debian 9 (Stretch).
networking routing wget ping tcpdump
networking routing wget ping tcpdump
edited 4 mins ago
Peter Mortensen
87958
87958
asked 17 hours ago
Martin Vegter
31334120234
31334120234
1
This is correct behaviour. There's no need for the machine to send packets destined for itself via the Ethernet NIC, so it doesn't.
– roaima
15 hours ago
@roaima - I disagree. It is not up to the network stack to decide what is "needed". I have clearly specified I want to ping the IP address associated witheth0. If I had wanted to ping localhost, I would have used127.0.0.1instead.
– Martin Vegter
15 hours ago
4
You wanted to ping the machine at 11.22.33.44 (or server1.mydomain.com) and you did... The interface is irrelevant in your case because your packet does not need to be routed.
– std_unordered_map
13 hours ago
1
You may block all the exits in or out of your "room", but it won't stop you from reaching your "room" if you are already there...
– std_unordered_map
13 hours ago
8
Physically, if it actually went out oneth0it wouldn't be received, an Ethernet interface doesn't "hear" what it's sending. So in any case, there needs to be a shortcut somewhere that says "oh this is a local packet, it must be handled locally". Probably easier to redirect the packet tolo0than adding a "handle outbound traffic as inbound path", though one would have to check the relevant RFCs for correctness.
– jcaron
12 hours ago
|
show 8 more comments
1
This is correct behaviour. There's no need for the machine to send packets destined for itself via the Ethernet NIC, so it doesn't.
– roaima
15 hours ago
@roaima - I disagree. It is not up to the network stack to decide what is "needed". I have clearly specified I want to ping the IP address associated witheth0. If I had wanted to ping localhost, I would have used127.0.0.1instead.
– Martin Vegter
15 hours ago
4
You wanted to ping the machine at 11.22.33.44 (or server1.mydomain.com) and you did... The interface is irrelevant in your case because your packet does not need to be routed.
– std_unordered_map
13 hours ago
1
You may block all the exits in or out of your "room", but it won't stop you from reaching your "room" if you are already there...
– std_unordered_map
13 hours ago
8
Physically, if it actually went out oneth0it wouldn't be received, an Ethernet interface doesn't "hear" what it's sending. So in any case, there needs to be a shortcut somewhere that says "oh this is a local packet, it must be handled locally". Probably easier to redirect the packet tolo0than adding a "handle outbound traffic as inbound path", though one would have to check the relevant RFCs for correctness.
– jcaron
12 hours ago
1
1
This is correct behaviour. There's no need for the machine to send packets destined for itself via the Ethernet NIC, so it doesn't.
– roaima
15 hours ago
This is correct behaviour. There's no need for the machine to send packets destined for itself via the Ethernet NIC, so it doesn't.
– roaima
15 hours ago
@roaima - I disagree. It is not up to the network stack to decide what is "needed". I have clearly specified I want to ping the IP address associated with
eth0. If I had wanted to ping localhost, I would have used 127.0.0.1 instead.– Martin Vegter
15 hours ago
@roaima - I disagree. It is not up to the network stack to decide what is "needed". I have clearly specified I want to ping the IP address associated with
eth0. If I had wanted to ping localhost, I would have used 127.0.0.1 instead.– Martin Vegter
15 hours ago
4
4
You wanted to ping the machine at 11.22.33.44 (or server1.mydomain.com) and you did... The interface is irrelevant in your case because your packet does not need to be routed.
– std_unordered_map
13 hours ago
You wanted to ping the machine at 11.22.33.44 (or server1.mydomain.com) and you did... The interface is irrelevant in your case because your packet does not need to be routed.
– std_unordered_map
13 hours ago
1
1
You may block all the exits in or out of your "room", but it won't stop you from reaching your "room" if you are already there...
– std_unordered_map
13 hours ago
You may block all the exits in or out of your "room", but it won't stop you from reaching your "room" if you are already there...
– std_unordered_map
13 hours ago
8
8
Physically, if it actually went out on
eth0 it wouldn't be received, an Ethernet interface doesn't "hear" what it's sending. So in any case, there needs to be a shortcut somewhere that says "oh this is a local packet, it must be handled locally". Probably easier to redirect the packet to lo0 than adding a "handle outbound traffic as inbound path", though one would have to check the relevant RFCs for correctness.– jcaron
12 hours ago
Physically, if it actually went out on
eth0 it wouldn't be received, an Ethernet interface doesn't "hear" what it's sending. So in any case, there needs to be a shortcut somewhere that says "oh this is a local packet, it must be handled locally". Probably easier to redirect the packet to lo0 than adding a "handle outbound traffic as inbound path", though one would have to check the relevant RFCs for correctness.– jcaron
12 hours ago
|
show 8 more comments
1 Answer
1
active
oldest
votes
The kernel knows "it is already there" and therefore "optimizes" the sending of the ICMP-packets. Thats why you see them on the loopback-interface. Someone else may be able the fill in more details.
Nevertheless: I had a similar problem some ages ago and I was able the solve them by creating a new network-namespace with unshare like unshare -n /bin/bash. Then you have a shell with an entire new network-stack (I lack the correct term for that) and without a loopback-interface. You have to define a new IP, routes etc pp. in that, but from that shell you are able to send ICMP-packets to yourself out of the ethernet-interface.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
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',
autoActivateHeartbeat: false,
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%2f491859%2fping-uses-localhost-instead-of-public-ip-address%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The kernel knows "it is already there" and therefore "optimizes" the sending of the ICMP-packets. Thats why you see them on the loopback-interface. Someone else may be able the fill in more details.
Nevertheless: I had a similar problem some ages ago and I was able the solve them by creating a new network-namespace with unshare like unshare -n /bin/bash. Then you have a shell with an entire new network-stack (I lack the correct term for that) and without a loopback-interface. You have to define a new IP, routes etc pp. in that, but from that shell you are able to send ICMP-packets to yourself out of the ethernet-interface.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
add a comment |
The kernel knows "it is already there" and therefore "optimizes" the sending of the ICMP-packets. Thats why you see them on the loopback-interface. Someone else may be able the fill in more details.
Nevertheless: I had a similar problem some ages ago and I was able the solve them by creating a new network-namespace with unshare like unshare -n /bin/bash. Then you have a shell with an entire new network-stack (I lack the correct term for that) and without a loopback-interface. You have to define a new IP, routes etc pp. in that, but from that shell you are able to send ICMP-packets to yourself out of the ethernet-interface.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
add a comment |
The kernel knows "it is already there" and therefore "optimizes" the sending of the ICMP-packets. Thats why you see them on the loopback-interface. Someone else may be able the fill in more details.
Nevertheless: I had a similar problem some ages ago and I was able the solve them by creating a new network-namespace with unshare like unshare -n /bin/bash. Then you have a shell with an entire new network-stack (I lack the correct term for that) and without a loopback-interface. You have to define a new IP, routes etc pp. in that, but from that shell you are able to send ICMP-packets to yourself out of the ethernet-interface.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
The kernel knows "it is already there" and therefore "optimizes" the sending of the ICMP-packets. Thats why you see them on the loopback-interface. Someone else may be able the fill in more details.
Nevertheless: I had a similar problem some ages ago and I was able the solve them by creating a new network-namespace with unshare like unshare -n /bin/bash. Then you have a shell with an entire new network-stack (I lack the correct term for that) and without a loopback-interface. You have to define a new IP, routes etc pp. in that, but from that shell you are able to send ICMP-packets to yourself out of the ethernet-interface.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 16 hours ago
std_unordered_map
1115
1115
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
std_unordered_map is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
add a comment |
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
actually that new network namespace does have (only) a loopback interface, but it's down by default
– A.B
8 hours ago
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%2f491859%2fping-uses-localhost-instead-of-public-ip-address%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
1
This is correct behaviour. There's no need for the machine to send packets destined for itself via the Ethernet NIC, so it doesn't.
– roaima
15 hours ago
@roaima - I disagree. It is not up to the network stack to decide what is "needed". I have clearly specified I want to ping the IP address associated with
eth0. If I had wanted to ping localhost, I would have used127.0.0.1instead.– Martin Vegter
15 hours ago
4
You wanted to ping the machine at 11.22.33.44 (or server1.mydomain.com) and you did... The interface is irrelevant in your case because your packet does not need to be routed.
– std_unordered_map
13 hours ago
1
You may block all the exits in or out of your "room", but it won't stop you from reaching your "room" if you are already there...
– std_unordered_map
13 hours ago
8
Physically, if it actually went out on
eth0it wouldn't be received, an Ethernet interface doesn't "hear" what it's sending. So in any case, there needs to be a shortcut somewhere that says "oh this is a local packet, it must be handled locally". Probably easier to redirect the packet tolo0than adding a "handle outbound traffic as inbound path", though one would have to check the relevant RFCs for correctness.– jcaron
12 hours ago