←back to thread

1895 points _l4jh | 6 comments | | HN request time: 0.731s | source | bottom
Show context
DyslexicAtheist ◴[] No.16728255[source]
TIL you can also use 1.1 and it will expand to 1.0.0.1

  $> ping 1.1

  PING 1.1 (1.0.0.1) 56(84) bytes of data.
  64 bytes from 1.0.0.1: icmp_seq=1 ttl=55 time=28.3 ms
  64 bytes from 1.0.0.1: icmp_seq=2 ttl=55 time=33.0 ms
  64 bytes from 1.0.0.1: icmp_seq=3 ttl=55 time=43.6 ms
  64 bytes from 1.0.0.1: icmp_seq=4 ttl=55 time=41.7 ms
  64 bytes from 1.0.0.1: icmp_seq=5 ttl=55 time=56.5 ms
  64 bytes from 1.0.0.1: icmp_seq=6 ttl=55 time=38.4 ms
  64 bytes from 1.0.0.1: icmp_seq=7 ttl=55 time=34.8 ms
  64 bytes from 1.0.0.1: icmp_seq=8 ttl=55 time=45.7 ms
  64 bytes from 1.0.0.1: icmp_seq=9 ttl=55 time=45.2 ms
  64 bytes from 1.0.0.1: icmp_seq=10 ttl=55 time=43.1 ms
replies(5): >>16728294 #>>16728342 #>>16728382 #>>16728420 #>>16729271 #
dieulot ◴[] No.16728382[source]
The most useful case for this shortcut is 127.1 -> 127.0.0.1
replies(3): >>16728626 #>>16728629 #>>16729229 #
1. aexaey ◴[] No.16729229[source]
0, which is a shorthand for 0.0.0.0 is likely the most code-golf-y way to write localhost, as many [EDIT: Linux] systems alias 0.0.0.0 to 127.0.0.1:

  $ ping 0
  PING 0 (127.0.0.1) 56(84) bytes of data.
  64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.032 ms
Of course, don't expect this to work universally. A lot of software will try to be clever with input validation, and fail.

Tangentially related: https://fosdem.org/2018/schedule/event/email_address_quiz/

replies(3): >>16729337 #>>16729709 #>>16730226 #
2. mrkstu ◴[] No.16729337[source]
Stays unaliased on macOS:

My-MacBook-Pro:bottle mrkstu$ ping 0 PING 0 (0.0.0.0): 56 data bytes ping: sendto: No route to host

replies(1): >>16731447 #
3. hartator ◴[] No.16729709[source]
It's not fully true that 127.0.0.1 is the same as 0.0.0.0. For example, binding a webserver to 0.0.0.0 make it on the public network while 127.0.0.1 is strictly localhost.
4. pishpash ◴[] No.16730226[source]
0.0.0.0 is not localhost. It's "any address".
replies(1): >>16730482 #
5. aexaey ◴[] No.16730482[source]
Yes, you're right.

What I was trying to say is - On Linux, INADDR_ANY (0.0.0.0) supplied to connect() or sendto() calls is treated as a synonym for INADDR_LOOPBACK (127.0.0.1) address.

Not so for bind() or course.

6. jamiek88 ◴[] No.16731447[source]
However ping to 127.1 works the same as localhost.