How to Disable IPv6 on Apache Server

Posted in how to on April 15, 2020 ‐ 1 min read

I often use .htaccess rules in Apache to limit website access to certain IP addresses. Sometimes this is done to lock the site down so only certain IPs can access it (whitelisting) and sometimes it’s done to block certain ranges (IPs). Either way, these rules are created using IPv4 addresses.

The problem is if the server and client both support IPv6 then Apache will use the IPv6 address by default which means the rules you created won’t apply to that connection.

Default Config

Your Apache config file listens for incoming connections using an option that will look similar to one of the following:

VirtualHost *:80

VirtualHost *:443

VirtualHost _default_:443

Yours may look slightly different, but it will be similar. The part before :port is the setting that needs changed. In our examples that would be * and _default_.

Disable IPv6

To prevent Apache from listening to IPv6 addresses you simply need to change the portion in front of :port to be Our examples from above would become:




This will force Apache to only bind to IPv4 addresses. Simply reload Apache after the change and you should be IPv6-free!