Wednesday, January 27, 2010

HOWTO Let lighttpd listen to both IPv4 and IPv6 on *BSD.

Okay, I've managed to let lighttpd listen to both IPv4 and IPv6 requests without using IPv4-mapped addresses. According to an Internet draft, IPv4 mapped addresses are considered harmful (R.I.P., itojun :). This has already been turned off in *BSDs by default but not in Linux.

Anyway, I've found out that if sysctl net.inet6.ip6.v6only is set to 1, enabling IPv6 in lighttpd would cause it to listen to IPv6 only. To solve this, you need to use these settings:
server.use-ipv6 = "enable"
$SERVER["socket"] == "0.0.0.0:80" {
}
If you need to use SSL, simply use:
server.use-ipv6 = "enable"
ssl.engine = "enable"
ssl.pemfile = "/var/etc/cert.pem"

$SERVER["socket"] == "0.0.0.0:443" {
ssl.engine = "enable"
ssl.pemfile = "/var/etc/cert.pem"
}
Tada! It works:
root@soulfury:/# sockstat | grep lighttpd
root lighttpd 23974 4 tcp6 *:443 *:*
root lighttpd 23974 5 tcp4 *:443 *:*
root@soulfury:/# sysctl -a | grep v6only
net.inet6.ip6.v6only: 1

No comments: