How to Enable IPv6 in Nginx and Apache (Step by Step). IPv6 stands for Internet Protocol version 6. It is the successor to Internet Protocol version 4 (IPv4).
It is faster and has a lot more features compared to IPv4. For example, it offers more addresses, better routing, and improved security. IPv6 was designed to solve many of the problems associated with IPv4.
This article discusses the IPv6 features and benefits and go over how to utilize and enable them on web servers like Apache and Nginx.
IPv6 is an internet protocol designed to replace the 32-bit IPv4. IPv4 was first introduced in the 1980s and has been widely used ever since. However, IPv4 does not caters to the ever growing users and devices on the internet, as it only offer 4 billion addresses.
Hence, IPv6 was developed as a solution to this problem, and it provides an almost infinite number of addresses for devices connected over the internet.
Besides the ample address space, IPv6 offers better performance regarding requests and page load times.
Currently, IPv4 and IPv6 addresses are in use but are not directly compatible. Most web servers use the IPv4 address by default but provide support for IPv6. But considering the advantages IPv6 has to offer, consider integrating IPv6 into your system.
How to Enable IPv6 in Nginx & Apache (Step by Step)
Prerequisites
You will need:
a non root user with sudo privileges
to make sure that IPv6 is turned on at the level of the operating system.
Find Out IPv6 address
You need to know the IPv6 address of your system before you go about enabling the IPv6 protocol in Apache or Nginx. Use multiple methods to find your IPv6 address on a Linux system.
Using ifconfig Command
The ifconfig command is used to assign, display, and configure addresses on the network interface. You can use this command to see the current network configuration information.
ifconfig |grep inet6
See the host/local and global IPv6 addresses against the keyword inet6 in the output.
Using IP Show Command
Alternatively, use the ip addr show command with the -6 option, which will give information about IPv6 instead of IPv4.
Open the port.conf file with the following command.
sudo nano /etc/apache2/ports.conf
Next, note your IPv6 address and open port number and insert the following Listen line into every module of your port.conf file.
Listen []:80
If you want Apache to listen to both IPv4 and IPv6, include both addresses in the file. Otherwise, add only the IPv6 configuration to restrict Apache from listening to only the address in IPv6 format.
Save the file and exit the editor. To verify that there is no error in the syntax, run the following command.
Verify the IPv6 Configuration Through the ss Command
The ss socket statistics command shows us the state of sockets. Run the following command to see whether the sockets are in Listen mode on the address and port that you have specified in the conf file.
sudo ss -ltpn
You can see that the addresses specified are working properly.
Verify the IPv6 Configuration Using the netstat Command
Use the following command with your port to see the network statistics and verify that IPv6 is enabled in Apache.
netstat -anlp | grep 80
You see the line with the keyword tcp6 with your IPv6 address in the output.
Before diving into the configuration, either stop any other service that is running on port 80 or choose another port for Nginx and change the default port along with the IPv6 address in the configuration.
Open the nginx.conf file with the nano editor using the following command.
sudo nano /etc/nginx/nginx.conf
Next, add the following lines of code with your IPv6 address and port number into the configuration files.
server {
listen 80 default_server;
listen []:80 default_server;
}
This configures Nginx to listen to both IPv4 and IPv6 addresses. If you want Nginx to listen exclusively for IPv6, then add the following server section instead.
server {
listen []:80 ipv6only=on default_server;
}
Nginx only listens to addresses formatted in IPv6 due to the ipv6only option.
Save the file and exit the editor. Verify that there is no error in the syntax with the following command.
sudo nginx -t
You should see the success message in the output.
Next, restart the Nginx service using the following command.
sudo systemctl restart nginx
Verify that the Nginx service has started successfully with the status check.
How to Enable IPv6 in Nginx & Apache (Step by Step) Conclusion
Although the migration from IPv4 to IPv6 is not very apparent at the moment, it is an inevitable change. The early migration makes your system more adaptable, and you can avail yourself of the benefits of IPv6 as a bonus.
In this article, you have learned how to enable IPv6 on your Apache and Nginx web servers.
Explore our Apache and Nginx sections to learn more.
Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.