Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

From Wikipedia:

The most commonly used IP address on the loopback device is 127.0.0.1 for IPv4, although any address in the range 127.0.0.0 to 127.255.255.255 is mapped to it.

This is not true, at least on FreeBSD:

$ ping 127.1.1.1
PING 127.1.1.1 (127.1.1.1): 56 data bytes
ping: sendto: Can't assign requested address

Is this correct behaviour?

share|improve this question
1  
Please do not cross post! Question on U&L. –  Caleb Jul 25 '11 at 19:00
add comment

4 Answers 4

up vote 7 down vote accepted

FreeBSD (also OS X, and I believe NetBSD & OpenBSD) will respond to requests sent to configured addresses on the loopback interface, just as they would for addresses on any other interface -- If you want an answer you need to assign the address first:

mgraziano@monitor ~]$ ifconfig lo0
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 
    inet6 ::1 prefixlen 128 
    inet 127.0.0.1 netmask 0xff000000 
    nd6 options=3<PERFORMNUD,ACCEPT_RTADV>

[mgraziano@monitor ~]$ ping 127.1.1.1
PING 127.1.1.1 (127.1.1.1): 56 data bytes
ping: sendto: Can't assign requested address
^C

[mgraziano@monitor ~]$ sudo ifconfig lo0 alias 127.1.1.1 netmask 0xFFFFFFFF

[mgraziano@monitor ~]$ ifconfig lo0
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=3<RXCSUM,TXCSUM>
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 
    inet6 ::1 prefixlen 128 
    inet 127.0.0.1 netmask 0xff000000 
    inet 127.1.1.1 netmask 0xffffffff 
    nd6 options=3<PERFORMNUD,ACCEPT_RTADV>

[mgraziano@monitor ~]$ ping 127.1.1.1
PING 127.1.1.1 (127.1.1.1): 56 data bytes
64 bytes from 127.1.1.1: icmp_seq=0 ttl=64 time=0.020 ms
^C

On the logic behind this implementation, see RFC 3330:

127.0.0.0/8 - This block is assigned for use as the Internet host
loopback address. A datagram sent by a higher level protocol to an
address anywhere within this block should loop back inside the host.
This is ordinarily implemented using only 127.0.0.1/32 for loopback,
but no addresses within this block should ever appear on any network
anywhere [RFC1700, page 5].

(emphasis mine)
Linux and Windows are being "helpful" here, however from my chair answering a request that was sent to an address not assigned to this host is not correct behavior...

share|improve this answer
add comment

I see the same behavior you describe on FreeBSD 8.1. Mac OS X, which shares some DNA with FreeBSD, also only seems to map 127.0.0.1.

Windows 7 and Linux (debian with 2.6.26 kernel) both appear to map the full address range as you describe in the Wikipedia quote (and as prescribed in the RFC).

To quote from RFC 3330:

127.0.0.0/8 - This block is assigned for use as the Internet host loopback address. A datagram sent by a higher level protocol to an address anywhere within this block should loop back inside the host. This is ordinarily implemented using only 127.0.0.1/32 for loopback, but no addresses within this block should ever appear on any network anywhere [RFC1700, page 5].

Depending how strictly you interpret the word "should," some might make the case that the FreeBSD/MacOS behavior is wrong. But given the ubiquitous use of 127.0.0.1 as the loopback address, I doubt it's likely to matter.

share|improve this answer
3  
+1 By default only 127.0.0.1 is assigned to lo0. Though you can certainly add the rest; I can't imagine many situations where it would matter. –  Chris S Jul 25 '11 at 15:35
    
It also depends on how you interpret "loop back inside the host". Does that inherently mean the datagram will be delivered somewhere meaningful; or simply what follows in the RFC, that the datagram will not be delivered to another host on the network. (I would agree with FreeBSD and Darwin, the latter) –  Chris S Jul 25 '11 at 15:43
    
It also depends on how you view the "correctness" of answering requests on an address not explicitly assigned to you -- I've always felt that if the address isn't assigned to you you have no business sending responses as though it's yours, with the possible exception of broadcast requests. –  voretaq7 Jul 25 '11 at 15:46
    
Also +1 for quoting the same RFC I did :) –  voretaq7 Jul 25 '11 at 15:46
2  
@voretaq7 I totally quoted it first. :) –  eaj Jul 25 '11 at 15:59
show 2 more comments

Its bucking the trend. Don't have a FreeBSD box handy to confirm whether its FreeBSD or your configuration.

The RFC says 127.0.0.1/24 - so it should be responding.

share|improve this answer
1  
Actually the RFC says 127.0.0.0/8, but doesn't specify which specific address(es) in that range to use: by convention the first usable address in that range (127.0.0.1) is assigned as localhost, but you could use 127.32.194.75 in your own OS implementation if you wanted to. (Doing so may however get you lynched by angry sysadmins…) –  voretaq7 Jul 25 '11 at 16:07
add comment

Question is fully answered about a three time by now, so I wanted just add some cents.

Note that for quite a some time default ipfw config drops this kind packets:

./rc.firewall:  ${fwcmd} add 100 allow ip from any to any via lo0
./rc.firewall:  ${fwcmd} add 300 deny ip from 127.0.0.0/8 to any

so with enabled firewall instead of

ping: sendto: Can't assign requested address

you might get

[savetherbtz@PH34R ~]$ ping 127.0.0.2
PING 127.0.0.2 (127.0.0.2): 56 data bytes
ping: sendto: Permission denied

PS. Of cause there can be server built without INET (IPv4 support) and you won't have even 127.0.0.1 =)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.