ungleich-staticcms/content/u/blog/how-to-enable-ipv6-in-applications/contents.lr

181 lines
4 KiB
Text
Raw Normal View History

title: How to enable IPv6 in applications
---
pub_date: 2019-09-26
---
author: Team ungleich
---
twitter_handle: ungleich
---
abstract:
New to IPv6? Wondering how to enable IPv6 in your favorite
application? Then this blog entry is for you.
---
body:
In this blog article you'll find some hints on how to enable IPv6 for
various applications.
## How to enable IPv6 in nginx
2019-09-25 12:26:29 +00:00
The web server [nginx](https://nginx.org/) by default only listens to IPv4 if you use
the standard `listen *:80;` directive. To enable IPv6, use
`listen [::]:80;`. So for a dual stack server, your configuration
could look as follows:
```
server {
listen *:80;
listen [::]:80;
...
}
```
## How to enable IPv6 in HAProxy
2019-09-25 12:26:29 +00:00
There are various interesting configuration options in
[HAProxy](https://www.haproxy.org/) related
to IPv6. Let's have a look at each of them!
To enable IPv6 transport for the local logging, use `log [::1]` in the
global section:
```
global
log [::1] local2
...
```
If you want a frontend to listen to either IPv6 or IPv4 only, you can
use the `ipv6@` prefix as follows:
```
# IPv6 http frontend
frontend httpipv6
bind ipv6@:80
mode http
# IPv4 http frontend
frontend httpipv4
bind ipv4@:80
mode http
...
```
If you want to connect to the backends only via a specific protocol,
we can use the prefix syntax there as well:
```
backend httpipv4
mode http
use-server ungleich.ch if { hdr(host) -i ungleich.ch }
server ungleich.ch ipv6@ungleich.ch
...
```
To proxy IPv6 requests to IPv4 only [twitter](https://twitter.com), you could
use the following configuration:
```
# ipv6 https
frontend httpsipv6
bind ipv6@:443
mode tcp
option tcplog
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
default_backend httpsipv6
backend httpsipv6
mode tcp
use-server twitter.com if { req_ssl_sni -i twitter.com }
server twitter.com ipv4@twitter.com
```
## How to enable IPv6 in Lektor
2019-09-25 12:26:29 +00:00
The static CMS [lektor](https://www.getlektor.com/)
by default serves on IPv4. To serve on IPv6
2019-09-25 12:26:29 +00:00
localhost use `-h ::1`, to be globally reachable use `-h ::`.
```
# Serve on IPv6 localhost
% lektor serve -h ::1
# Serve on IPv6 (globally reachable)
% lektor serve -h ::
```
2019-09-26 17:04:37 +00:00
## How to use IPv6 in keepalived
[Keepalived](https://keepalived.org/), the VRRP daemon for Linux,
supports IPv6 for a while. However newer versions (wikipedia: citation
needed) of keepalived require to have two different instances, if you
are running dual stack VRRP messages. So your keepalived.conf for use
with IPv6 might look as follows:
```
vrrp_instance router_internal {
state BACKUP
interface bond0.10
virtual_router_id 1
virtual_ipaddress {
2a0a:e5c0:2:0::7/64 dev bond0.10
}
}
vrrp_instance router_internal_ipv4 {
state BACKUP
interface bond0.10
virtual_router_id 2
virtual_ipaddress {
10.3.0.7/22 dev bond0.10
}
}
```
## How to enable IPv6 in the Python HTTP Server
If you are coding in python and you want your HTTP server to listen on
IPv6, you can inherit from HTTPServer and set the address family to
*AF_INET6* as follows:
```
from http.server import HTTPServer
class HTTPServerV6(HTTPServer):
address_family = socket.AF_INET6
if __name__ == '__main__':
myv6server = HTTPServerV6
```
For more details on how to use the HTTPServer in general,
checkout
[this stackoverflow post](https://stackoverflow.com/questions/23264569/python-3-x-basehttpserver-or-http-server).
Thanks to cvmiller for this hint!
2019-09-26 02:45:50 +00:00
## How to enable IPv6 in Redhat Linux
While Red Hat is not specifically an application, we still wanted
to list [the article from Valentin
Bajrami](https://www.redhat.com/sysadmin/configuring-ipv6-rhel-7-8)
which describes how to configure IPv6 on Red Hat. Thanks for the
pointer to [IndieLab](https://twitter.com/omnidelic)!
## Other applications
If you know about other applications or want to enhance one of our
configuration, we invite you to join the [IPv6
chat](https://IPv6.chat) or [write to us on
Twitter](https://twitter.com/ungleich).