(For Ubuntu 22.04 / 24.04 / 24.10 / 24.04 LTS “Noble”)
In many enterprise or internal environments, IPv6 is not yet supported.
This often causes apt to fail when trying to download packages, showing messages like:
Cannot initiate the connection to archive.ubuntu.com:80 (2620:2d:4000:1::102).
Network is unreachable
This means Ubuntu tried to connect over IPv6, but the network doesn’t support it.
🔍 Problem Description
By default, Ubuntu:
- Enables IPv6 globally
- Prefers IPv6 in DNS resolution
- Lets
aptconnect using IPv6 first
When your network or firewall does not allow IPv6 traffic, apt fails with connection errors.
🧰 Step-by-Step Solution
Step 1: Permanently Disable IPv6
Edit the sysctl configuration:
sudo nano /etc/sysctl.conf
Add these lines at the end:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
Apply changes:
sudo sysctl -p
Check the status:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
If you see 1, IPv6 is disabled.
Step 2: Force APT to Use IPv4
Create a config file:
sudo nano /etc/apt/apt.conf.d/99force-ipv4
Insert:
Acquire::ForceIPv4 "true";
Save and run:
sudo apt clean
sudo apt update
Now apt will connect via IPv4 only:
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Step 3 (Optional): Prefer IPv4 for All Connections
Edit /etc/gai.conf:
sudo nano /etc/gai.conf
Uncomment this line:
precedence ::ffff:0:0/96 100
This forces the system to prefer IPv4 over IPv6 globally.
✅ Verification
- Check IPv6 status:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6Should return1. - Verify DNS uses IPv4 only:
getent ahosts archive.ubuntu.comNo2620:entries = IPv6 disabled. - Run update test:
sudo apt updateShould complete without “Network is unreachable”.
📘 Summary
| Task | File / Command |
|---|---|
| Disable IPv6 | /etc/sysctl.conf |
| Force APT IPv4 | /etc/apt/apt.conf.d/99force-ipv4 |
| System IPv4 Priority | /etc/gai.conf |
| Verify | getent ahosts, apt update |
💡 Recommendation for IT Admins
In enterprise environments where IPv6 is not supported:
- Disable IPv6 in system images
- Add
99force-ipv4to default configuration - Include these steps in your internal Ubuntu deployment SOP