I’m trying to setup a Vagrant box using generic/freebsd12 as the base image. I cannot get my Phoenix application to listen on IPv4 addresses inside the VM. It will respond to IPv6 as expected, so I know it works.
Managed to solve it. I’m in the process of migrating from Ubuntu Linux to FreeBSD and for some reason on Ubuntu Linux Phoenix did bind to the IPv4, but using the same code and configuration on FreeBSD did bind only on IPv6.
I tried all tricks on changing config/config.exs, config/prod.exs and config/prod.secret.exs, but it turned out that the problem was in the lib/my_app_web/endpoint.ex where in init function had the following line:
I’m pretty sure that this line has been on inet6 for the entire time of the project and it was generated by phx.new at the time of project creation. Just bear in mind that this is a legacy Phoenix application running version 1.5.1 and might not have the same generated file when creating a new Phoenix application today.
On Linux, by default, an “inet6” socket also accepts IPv4 (you can disable that with the sysctl option net.ipv6.bindv6only or by adding {ipv6_v6only: true} to your socket options). On FreeBSD, it is not the case by default. You can enable a similar behaviour by adding ipv6_ipv4mapping=YES in /etc/rc.conf. See rc.conf(5)