IPv6 is a modern Internet Protocol with more features than the popular IPv4 protocol. Compared to IPv4, IPv6 uses 128-bit IP address so there is less private address collision, better quality to better flow control and faster authentication. It has a simple header format and efficient routing making it much faster than IPv4. But by default, it is disabled in Linux. In this article, we will learn how to enable IPv6 in Ubuntu.
How to Enable IPv6 in Ubuntu
Here are the steps to enable IPv6 in Ubuntu.
1. Edit sysctl.conf file
First of all, log into Ubuntu terminal as admin with root access. Then run the following command to open sysctl.conf file in vi editor.
$ vi /etc/sysctl.conf
Then add the following lines to your file.
net.ipv6.conf.default.disable_ipv6 = 0 net.ipv6.conf.all.disable_ipv6 = 0
Save and close the file.
2. Editing Interfaces File
Next, make a backup of /etc/network/interfaces file.
$ sudo mv /etc/network/interfaces /etc/network/interfaces-backup
Then open this file in text editor.
$ sudo vi /etc/network/interfaces
Add the following lines to it. Replace IPv7-IP-Address and IPv6-IP-Gateway-Address with Ubuntu IPv6 addresses that have been given to you.
iface eth0 inet6 static pre-up modprobe ipv6 address IPv6-IP-Address netmask 64 gateway IPv6-IP-Gateway-Address
3. Restart Network Service
Next restart networking service to apply the changes.
$ service networking restart
4. Verify IPv6 Setup
Finally, run the following command to verify that IPv6 has been enabled in your system.
$ ifconfig eth0
You will see multiple lines of information along with a line starting with inet6… which indicates that Ubuntu is showing IPv6 address.
... inet6 addr: ... ...
How to Disable IPv6 in Ubuntu
Here are the steps to disable IPv6 in Ubuntu.
1. Verify IPv6 in Ubuntu
First step is to check if IPv6 is enabled in Ubuntu using the following command.
ip a
In the above command, if IPv6 is enabled then will show you a line starting with inet6.
... inet6 ...
2. Using sysctl command
Next, use the following sysctl commands to disable IPv6 in Ubuntu.
$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 $ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 $ sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1
3. Verify Process of Disabling IPv6
Once again, we will run ‘ip a’ command to ensure it is disabled correctly.
$ ip a
This time you will not see a line starting with inet6…
4. Persistently Disable IPv6
The above changes last only till the next system reboot. To make the changes persistent, you need to modify sysctl.conf file.
$ vi /etc/sysctl.conf
Then add the following lines to this file.
net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1
Save and close the file. Run the following command to apply changes.
$ sudo sysctl -p
Run ‘ip a’ command. If you still see inet6 in the output, create the file /etc/rc.local
vi /etc/rc.local
and add the following lines to it.
#!/bin/bash # /etc/rc.local /etc/sysctl.d /etc/init.d/procps restart exit 0
Use chmod command to make the file executable.
$ sudo chmod 755 /etc/rc.local
The above command will ensure that the file is read at boot time. In this article, we have learnt how to enable IPv6 in Ubuntu.
Also read:
How to Concatenate Strings in Bash
How to Write to Existing Excel File in Python
How to Show Tables in PostgreSQL
How to Delete Exported Variable in Linux
How to Find Files With SUID and SGID Permissions in Linux
Related posts:
Sreeram Sreenivasan loves coding & writing tech articles. He has helped many Fortune 500 companies in the areas of BI & software development. He has more than 10 years of experience in web development, Python, Linux, SQL and database programming.