How to Disable IPv6 in Mailcow (Part 3)

mailcow disable ipv6docker compose ipv6mailcow ipv6natdisable ipv6 mailcowmailcow ipv4 only
Published·Modified·

This is the third tutorial in the self-hosted mailcow series. Friends interested in setting up their own mail server can refer to my previous articles:

When your server does not support IPv6 addresses, you can disable mailcow's IPv6 listening to reduce resource consumption (mailcow starts an IPv6 NAT container) and avoid strange issues. This article continues to share how to disable IPv6 in mailcow.

Disable mailcow IPv6

Modify docker-compose.yml, changing:

enable_ipv6: true

to:

enable_ipv6: false

At the same time, you need to disable the ipv6nat-mailcow container. In the mailcow directory, create a new file named docker-compose.override.yml and copy the following content to save it:

version: '2.1'
services:
  ipv6nat-mailcow:
    image: bash:latest
    restart: "no"
    entrypoint: ["echo", "ipv6nat disabled in compose.override.yml"]

Then restart the containers:

docker-compose down
docker-compose up -d

To disable IPv6 in unbound-mailcow, simply modify the configuration file data/conf/unbound/unbound.conf:

# Change
# do-ip6: yes
to
# do-ip6: no

Then restart the corresponding container:

docker-compose restart unbound-mailcow

Next, disable IPv6 for Postfix by modifying the configuration file data/conf/postfix/extra.cf to the following content:

smtp_address_preference = ipv4
inet_protocols = ipv4

Then restart the container:

docker-compose restart postfix-mailcow

Finally, you need to modify the Nginx listening configuration. Use the following sed commands to replace them:

sed -i '/::/d' data/conf/nginx/listen_*
sed -i '/::/d' data/conf/nginx/templates/listen*
sed -i 's/,\[:://g' data/conf/dovecot/dovecot.conf
sed -i 's/\[:://g' data/conf/nginx/dynmaps.conf
sed -i 's/\[:://g' data/conf/phpfpm/php-fpm.d/pools.conf

Other Notes

  1. If your server supports IPv6, there is no need to disable IPv6 addresses.
  2. Please back up the configuration files before modifying them.
  3. Some content in this article is referenced from: https://mailcow.github.io/mailcow-dockerized-docs/post_installation/firststeps-disable_ipv6/

If you need to build a self-hosted mail server, you can contact me via QQ: 446199062 or WeChat: xiaozme.