1月6日 强制ubuntu使用ipv4.Force Apt-Get to IPv4 or IPv6 on Ubuntu or Debian

本文指导如何配置Ubuntu14.04和DebianJessie系统中的apt-get,使其仅使用IPv4或IPv6进行更新。适用于一次性操作及持久设置的方法均有介绍。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Force Apt-Get to IPv4 or IPv6 on Ubuntu or Debian

Published on: Tue, Mar 10, 2015 at 6:47 pm EST

Debian Linux Guides Ubuntu

Here on Vultr, we have the option to enable IPv6 on all deployable VPSes. But with this, some programs and commands may prefer one or the other with unpredictable results.

In this guide, we will configure apt-get to use only IPv4 or IPv6. This guide targets Ubuntu 14.04 and Debian Jessie, but may work for newer versions as well.

Fast command line option

If you want to force the apt-get to use IPv4 or IPv6 only one time, follow these steps. This feature is available after the 0.9.7.9~exp1 version of apt-get. First, make sure your version of apt-get is newer than 0.9.7.9~exp1 by running the following command:

apt-get --version

The result will be something like this:

apt 1.0.1ubuntu2 for amd64 compiled on Oct 28 2014 20:55:14

If the version checks out, then you can force IPv4 with:

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

or IPv6:

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

This will update the repositories resolving the URLs in sources.list to IPv4 only.

Persistent option

To make the setting persistent, create the file 99force-ipv4 in /etc/apt/apt.conf.d/.

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

Put the following contents in it:

Acquire::ForceIPv4 "true";

Save the file, and you're good to go. If you want to force IPv6 instead, change the 4 to 6 in the file name and settings. To choose between one of them, test with the fast method and see which works better.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值