# Ipv6 connection attempted before ipv4

**URL:** <https://www.ruby-forum.com/t/ipv6-connection-attempted-before-ipv4/74439>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:44am UTC](https://www.ruby-forum.com/t/ipv6-connection-attempted-before-ipv4/74439 "2006-11-07T10:44:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 7, 2006, 10:44am UTC](https://www.ruby-forum.com/t/ipv6-connection-attempted-before-ipv4/74439/1 "2006-11-07T10:44:02Z")

</div>

I’ve noticed that when using net/http, and probably with any ip/udp  
socket connection, it attempts to connect via ipv6 and when that fails  
it falls back to ipv4. Is this due to the underlying socket library  
on freebsd, or is it a ruby issue? Both client and server are  
freebsd.

Chris

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 7, 2006, 10:44am UTC](https://www.ruby-forum.com/t/ipv6-connection-attempted-before-ipv4/74439/2 "2006-11-07T10:44:04Z")

</div>

On 10/29/06, snacktime [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve noticed that when using net/http, and probably with any ip/udp  
> socket connection, it attempts to connect via ipv6 and when that fails  
> it falls back to ipv4. Is this due to the underlying socket library  
> on freebsd, or is it a ruby issue? Both client and server are  
> freebsd.

Forgot to mention this was when using ‘localhost’ instead of  
127.0.0.1. For anyone else testing clients/servers on freebsd, don’t  
use ‘localhost’, use 127.0.0.1. Freebsd limits RST packets to so many  
per second, and it took me a little bit to figure out why my http  
connections were hanging for a second after every 200. Not sure if  
linux has the same behavior.

Chris

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 7, 2006, 10:44am UTC](https://www.ruby-forum.com/t/ipv6-connection-attempted-before-ipv4/74439/3 "2006-11-07T10:44:10Z")

</div>

On 10/29/06, snacktime [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On 10/29/06, snacktime [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’ve noticed that when using net/http, and probably with any ip/udp  
> > socket connection, it attempts to connect via ipv6 and when that fails  
> > it falls back to ipv4. Is this due to the underlying socket library  
> > on freebsd, or is it a ruby issue?
> 
> Forgot to mention this was when using ‘localhost’ instead of  
> 127.0.0.1. For anyone else testing clients/servers on freebsd, don’t  
> use ‘localhost’, use 127.0.0.1.

It has to do with the order of ‘localhost’ lines in the /etc/hosts file.

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 7, 2006, 10:44am UTC](https://www.ruby-forum.com/t/ipv6-connection-attempted-before-ipv4/74439/4 "2006-11-07T10:44:17Z")

</div>

On 10/29/06, Garance A Drosehn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It has to do with the order of ‘localhost’ lines in the /etc/hosts file.

Ah I didn’t even notice that. Makes sense now.
