Ubuntu 服务器 - 无法连接到 github

use*_*332 6 ubuntu github

我根本无法从新安装的 Ubuntu 服务器上的命令行访问 github。Ping 和 curl github 失败,但对其他主机工作正常。

操作系统:Ubuntu 22.04.1 LTS

Ping 测试

# google
ping -c3 google.com
PING google.com(ord37s32-in-x0e.1e100.net (2607:f8b0:4009:808::200e)) 56 data bytes
64 bytes from ord31s21-in-x0e.1e100.net (2607:f8b0:4009:808::200e): icmp_seq=1 ttl=115 time=16.6 ms
64 bytes from ord37s32-in-x0e.1e100.net (2607:f8b0:4009:808::200e): icmp_seq=2 ttl=115 time=15.2 ms
64 bytes from ord37s32-in-x0e.1e100.net (2607:f8b0:4009:808::200e): icmp_seq=3 ttl=115 time=10.9 ms

--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 10.914/14.210/16.553/2.398 ms

# github - fails with 'Destination Host Unreachable'
ping -c3 github.com
PING github.com (140.82.113.3) 56(84) bytes of data.
From ubuntu (192.168.0.38) icmp_seq=1 Destination Host Unreachable
From ubuntu (192.168.0.38) icmp_seq=2 Destination Host Unreachable
From ubuntu (192.168.0.38) icmp_seq=3 Destination Host Unreachable

--- github.com ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2026ms
pipe 3

# github ping -4
ping -c3 github.com
PING github.com (140.82.112.4) 56(84) bytes of data.
From ubuntu (192.168.0.38) icmp_seq=1 Destination Host Unreachable
From ubuntu (192.168.0.38) icmp_seq=2 Destination Host Unreachable
From ubuntu (192.168.0.38) icmp_seq=3 Destination Host Unreachable

--- github.com ping statistics ---
3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2020ms
pipe 2

Run Code Online (Sandbox Code Playgroud)

卷曲测试

# google
curl -s --head --request GET google.com > /dev/null; echo $?
0

# github
curl -s --head --request GET github.com > /dev/null; echo $?
7
Run Code Online (Sandbox Code Playgroud)

git克隆测试

# Fails with 'no route to host'.
git clone https://github.com/pi-hole/pi-hole.git
Cloning into 'pi-hole'...
fatal: unable to access 'https://github.com/pi-hole/pi-hole.git/': Failed to connect to github.com port 443 after 18534 ms: No route to host
Run Code Online (Sandbox Code Playgroud)

查找

# google
nslookup google.com
Server:     127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
Name:   google.com
Address: 142.250.191.206
Name:   google.com
Address: 2607:f8b0:4009:803::200e

# github
nslookup github.com
Server:     127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
Name:   github.com
Address: 140.82.112.4
Run Code Online (Sandbox Code Playgroud)

IP地址

ip r s
default via 192.168.0.1 dev enp0s31f6 proto dhcp src 192.168.0.38 metric 100 
1.1.1.3 via 192.168.0.1 dev enp0s31f6 proto dhcp src 192.168.0.38 metric 100 
192.168.0.0/24 dev enp0s31f6 proto kernel scope link src 192.168.0.38 metric 100 
192.168.0.1 dev enp0s31f6 proto dhcp scope link src 192.168.0.38 metric 100 
192.168.0.38 dev enp0s31f6 proto dhcp scope host src 192.168.0.38 metric 100 
Run Code Online (Sandbox Code Playgroud)

如果配置

ifconfig
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.38  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 2601:246:4d7f:8361:d681:d7ff:fe8d:637b  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::d681:d7ff:fe8d:637b  prefixlen 64  scopeid 0x20<link>
        ether d4:81:d7:8d:63:7b  txqueuelen 1000  (Ethernet)
        RX packets 231023  bytes 191591697 (191.5 MB)
        RX errors 0  dropped 8  overruns 0  frame 0
        TX packets 174168  bytes 16427225 (16.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xef200000-ef220000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 10709  bytes 1034079 (1.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10709  bytes 1034079 (1.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Run Code Online (Sandbox Code Playgroud)

跟踪路由

# google
traceroute to google.com (172.217.1.110), 30 hops max, 60 byte packets
 1  ubuntu (192.168.0.38)  3060.551 ms !H  3060.478 ms !H  3060.429 ms !H

# github
traceroute to github.com (140.82.114.4), 30 hops max, 60 byte packets
 1  ubuntu (192.168.0.38)  3049.846 ms !H  3049.774 ms !H  3049.725 ms !H
Run Code Online (Sandbox Code Playgroud)

据我所知,我不处理任何代理或异常的防火墙设置。

感谢您的任何建议。

小智 0

对于 IPv4/6 相关问题:

看来你只能从 IPv6 ip 得到答案,遗憾的是 GitHub 还没有提供 IPv6 地址,有关该主题的更多信息可以在这里找到

他们最近开始内部测试对其的支持。

ip r s请提供和/或ifconfigtraceroute google.com以及的输出traceroute github.com

进一步尝试ping -c3 -4 github.com- 如果他们经历过,最简单的方法是停用正在使用的 NIC 的 IPv6。

要暂时禁用 IPv6:

$ sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.all.disable_ipv6 = 1
$ sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6 = 1
Run Code Online (Sandbox Code Playgroud)

并再次测试 - 如果有效,请随时通过调整行以读取来永久禁用 IPv6(如果GRUB_CMDLINE_LINUX_DEFAULT需要/etc/default/grubGRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1"

最后运行sudo update-grub以永久禁用 ipv6 禁用

对于 DNS 相关问题(在本例中不太可能):

你可以检查一下systemd-resolve --status吗 ?如果它使用“正确的”DNS 服务器(例如 Google 8.8.8.8)或实际上来自您的提供商/路由器的 DNS?

如果它使用您的提供商/路由器的 DNS 服务器,我建议将其更改为 8.8.8.8。可能最好检查一下如何实现这一点,因为我们不知道您是否启用了 GUI,因此很难提供完整的工作答案。

对于 CLI 设置(使用 Google DNS): sudo nano /etc/netplan/01-network-manager.yaml并添加名称服务器以用于所需的接口

    nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
Run Code Online (Sandbox Code Playgroud)

保存并退出文件并运行sudo netplan try以验证配置文件是否有效。如果是这样应用它sudo netplan apply