Troubleshooting Ubuntu or Debian apt-get IPv6: How to Set Up to Use IPv4 Only


ubuntu_debian_apt_ipv4_ipv6

Troubleshooting Ubuntu or Debian apt-get IPv6: How to Set Up to Use IPv4 Only

Background :

In Ubuntu 22.04 (including 20.04 18.04 and other versions) or Debian (10, 11, 12) systems, when you use the apt updateor apt installcommand, the system will give priority to using the IPv6 network by default. But sometimes, although IPv6 is enabled in the system, the IPv6 network is actually not available, which causes the apt command to fail to work properly. To solve this problem, we can set apt-get to only use IPv4.

Step 1: Temporary setup method

  • Scenario : You just want to try it out or temporarily change the settings.

    Open your terminal, and if you want apt-get to use only IPv4 this time, type:

apt-get -o Acquire::ForceIPv4=true update

Or, when you want to install a certain package, you can do this:

apt-get -o Acquire::ForceIPv4=true install [软件包名]

Step 2: Long-Term Setup Method

  • Scenario : You want to apt-getuse IPv4 by default instead of IPv6 every time you use a command.

    First, open a terminal and type:

sudoedit /etc/apt/apt.conf.d/99force-ipv4

Then write in the file:

Acquire::ForceIPv4 "true";

Save and exit. In this way, apt-getonly IPv4 will be used every time the command is used, thereby avoiding problems caused by unreachable IPv6.

Guess you like

Origin blog.csdn.net/weixin_43846408/article/details/132644173