我有两个虚拟服务器,都安装了 ubuntu 20.04,到目前为止,它们都运行正常。但我的问题是,Server1 无法 ping Server2,反之亦然。我收到错误“目标主机无法访问”。这与域名和 IP 有关。据我所知,这是这些服务器之间的错误或缺失的路由,我找到了这个教程https://contabo.com/blog/creating-static-routes/
但它对我来说不起作用,并且我的配置似乎有所不同。
我的 /etc/netplan/01-netcfg.yaml 如下所示:
network:
version: 2
renderer: networkd
ethernets:
ens18:
match:
macaddress: 00:50:56:46:a3:de
addresses:
- 38.242.229.xx/19
#- 2a02:c206:3009:2902:0000:0000:0000:0001/64
#gateway6: fe80::1
routes:
- to: 0.0.0.0/0
via: 38.242.224.1
on-link: true
nameservers:
search: [ invalid ]
addresses:
- 161.97.189.52
- 161.97.189.51
#- 2a02:c206:5028::2:53
#- 2a02:c206:5028::1:53
也许有人可以帮助我通过这个实例访问另一台(第二台)服务器。我对 Linux 联网的了解不太好,所以我可以根据自己的需要修改教程。谢谢。
IP地址:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:46:a3:de brd ff:ff:ff:ff:ff:ff
inet 38.242.229.72/19 brd 38.242.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe46:a3de/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:e1:f9:bb:15 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
IP路由:
default via 38.242.224.1 dev eth0 proto static onlink
38.242.224.0/19 dev eth0 proto kernel scope link src 38.242.229.72
第二台服务器的 ip 地址:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:50:56:46:a3:dd brd ff:ff:ff:ff:ff:ff
inet 38.242.229.63/19 brd 38.242.255.255 scope global eth0
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:5f:77:59:e9 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
55: br-195a84347f94: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:a6:46:7a:27 brd ff:ff:ff:ff:ff:ff
inet 172.25.0.1/16 brd 172.25.255.255 scope global br-195a84347f94
valid_lft forever preferred_lft forever
57: vethb13ec38@if56: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-195a84347f94 state UP group default
link/ether 92:e8:8a:e0:f1:7c brd ff:ff:ff:ff:ff:ff link-netnsid 1
59: veth21971c4@if58: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-195a84347f94 state UP group default
link/ether 4e:95:40:7d:78:93 brd ff:ff:ff:ff:ff:ff link-netnsid 2
68: br-d0ad0289f7c7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ef:83:ac:3e brd ff:ff:ff:ff:ff:ff
inet 172.28.0.1/16 brd 172.28.255.255 scope global br-d0ad0289f7c7
valid_lft forever preferred_lft forever
70: veth07b736d@if69: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-d0ad0289f7c7 state UP group default
link/ether f6:85:f1:48:45:8e brd ff:ff:ff:ff:ff:ff link-netnsid 3
74: br-c2c3481624b2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:e8:3c:59:c0 brd ff:ff:ff:ff:ff:ff
inet 172.30.0.1/16 brd 172.30.255.255 scope global br-c2c3481624b2
valid_lft forever preferred_lft forever
76: veth98745d8@if75: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-c2c3481624b2 state UP group default
link/ether 2a:70:8d:58:de:e8 brd ff:ff:ff:ff:ff:ff link-netnsid 0
enter code here
第二台服务器的 ip 路由:
default via 38.242.224.1 dev eth0 proto static onlink
38.242.224.0/19 dev eth0 proto kernel scope link src 38.242.229.63
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
172.25.0.0/16 dev br-195a84347f94 proto kernel scope link src 172.25.0.1
172.28.0.0/16 dev br-d0ad0289f7c7 proto kernel scope link src 172.28.0.1
172.30.0.0/16 dev br-c2c3481624b2 proto kernel scope link src 172.30.0.1
ping 网关成功,ping yahoo.com 也成功。
我的目标是第一台服务器能够从第二台服务器上运行的 gitlab 克隆/拉取 git 存储库。
每台服务器都可以 ping 所有东西,但不能 ping 另一台。主机提供商告诉我,这是因为两个 IP 地址都在同一个子网中,所以我必须创建一个静态根来解决这个问题。但我无法按照上面链接中针对 ubunto 20.04 的说明成功操作。
答案1
每https://contabo.com/blog/creating-static-routes/,尽管其他服务器通告位于同一子网中,但如果不经过路由器,则无法访问它们。因此,正确的配置应如下所示:
network:
version: 2
renderer: networkd
ethernets:
ens18:
match:
macaddress: 00:50:56:46:a3:de
addresses:
- 38.242.229.xx/32
#- 2a02:c206:3009:2902:0000:0000:0000:0001/64
#gateway6: fe80::1
routes:
- to: 38.242.224.1/32
on-link: true
- to: 0.0.0.0/0
via: 38.242.224.1
nameservers:
search: [ invalid ]
addresses:
- 161.97.189.52
- 161.97.189.51
#- 2a02:c206:5028::2:53
#- 2a02:c206:5028::1:53
请注意主机网络掩码(/32)的使用,它代表您的真实网络拓扑。