How to Enable IPv6 in Nginx and Apache (Step by Step)

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.

What is IPv6?

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.

Features and Benefits of IPv6

Here are some of the features and benefits of using IPv6:

  • Large address space
  • Provides better performance
  • More efficient because of the smaller header than the IPv4
  • Provides better routing
  • Have improved multicast capability
  • More secure due to IPsec

Follow this post to learn how to enable IPv6 on Apache and Nginx web servers.

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.

				
					ip -6 addr show
				
			

Take note of your IPv6 address for later use.

How to Enable IPv6 in Apache

Verify Apache installation

Before we enable IPv6, we need to make sure that Apache is installed properly on the system. Check the Apache version with the following command:

				
					apache2 -v
				
			

If Apache is already installed, move on to the next step of this tutorial. Otherwise, install it on your system using the following command:

				
					sudo apt install apache2
				
			

Further, verify the installation by checking the status of the Apache service.

				
					sudo systemctl status apache2
				
			

Firewall Configuration

Use the following commands to set up the firewall and configure it to allow HTTP, HTTPS, and OpenSSH connections:

				
					sudo ufw allow OpenSSH
sudo ufw allow in "Apache Full"
sudo ufw enable
sudo ufw status
				
			

Verify the configuration with a quick status check of the firewall.

Modify port.conf File

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.

				
					sudo apache2ctl configtest
				
			

You should see the OK message in the output.

Restart the Apache Service 

Once you are done with the IPv6 configuration, restart the services so that the changes made to the files are applied.

				
					sudo systemctl restart apache2
				
			

Check the status of the Apache service to see if everything is running smoothly after the configuration.

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.

Verify the IPv6 Configuration With the Browser

Go to the browser and go to your IPv6 address.

				
					http://[]/
				
			

You see the homepage of Apache as a result, which indicates that you have successfully enabled IPv6.

How to Enable IPv6 in Nginx

Verify Nginx installation

Run the following command to make sure that Nginx is appropriately installed on the system.

				
					nginx -v
				
			

Move on to the next step of this tutorial if the Nginx is already installed; otherwise, install it on your system using the following command:

				
					sudo apt install nginx
				
			

Verify the installation by checking the status of the Nginx service.

				
					sudo systemctl status nginx
				
			

Firewall Configuration

Secure your system and allow HTTP, HTTPS, and OpenSSH connections through the firewall.

				
					sudo ufw allow OpenSSH
sudo ufw allow in "Nginx Full"
sudo ufw enable
sudo ufw status
				
			

Make sure the configurations are applied with a firewall status check.

Modify nginx.conf File

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.

Verify the IPv6 Configuration Using the netstat Command

You can see your network statistics with the netstat command. IPv6 addresses in the records starts with the keyword tcp6.

				
					netstat -anlp | grep 80
				
			

You will see your IPv6 address and port within those tcp6 records.

Verify the IPv6 Configuration Through the ss Command

Use the ss command to see the status of new sockets to ensure that they are in Listen mode on the specified address and port.

				
					sudo ss -ltpn
				
			

Verify the IPv6 Configuration With the Browser

Go to the browser and enter your IPv6 address and port number in the following format.

				
					http://[]:
				
			

You see the Nginx welcome page pop up as a result, which shows that you have successfully configured Nginx with IPv6 addresses.

That’s it for enabling IPv6 on Nginx and Apache.

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.

Avatar for Sobia Arshad
Sobia Arshad

Information Security professional with 4+ years of experience. I am interested in learning about new technologies and loves working with all kinds of infrastructures.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x