如何在任何接口的网络范围之外拥有一个默认网关?

网络工程 路由 IPv4 网关
2022-02-28 22:13:01

我一直认为默认网关必须与尝试连接到 Internet 的服务器/客户端位于同一网络上。但是今天我从 Hetzner 租了一台服务器,该服务器能够连接到互联网,尽管在我看来,默认网关肯定没有连接到同一个网络。网络掩码似乎也设置为 /32。

root@test:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 138.201.187.120  netmask 255.255.255.255  broadcast 138.201.187.120
        inet6 fe80::9400:ff:fe3b:eece  prefixlen 64  scopeid 0x20<link>
        inet6 2a01:4f8:c17:69b0::1  prefixlen 64  scopeid 0x0<global>
        ether 96:00:00:3b:ee:ce  txqueuelen 1000  (Ethernet)
        RX packets 1166  bytes 638244 (638.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 653  bytes 92539 (92.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 112  bytes 8824 (8.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 112  bytes 8824 (8.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@test:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.31.1.1      0.0.0.0         UG    0      0        0 eth0
172.31.1.1      0.0.0.0         255.255.255.255 UH    0      0        0 eth0
root@test:~# ip route
default via 172.31.1.1 dev eth0
172.31.1.1 dev eth0 scope link
root@test:~# ping ipv4.google.com
PING ipv4.l.google.com (172.217.21.238) 56(84) bytes of data.
64 bytes from fra16s13-in-f14.1e100.net (172.217.21.238): icmp_seq=1 ttl=54 time=4.83 ms
64 bytes from fra16s13-in-f14.1e100.net (172.217.21.238): icmp_seq=2 ttl=54 time=4.96 ms
64 bytes from fra16s13-in-f14.1e100.net (172.217.21.238): icmp_seq=3 ttl=54 time=5.01 ms
^C
--- ipv4.l.google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 4.837/4.938/5.010/0.073 ms
root@test:~#
root@test:~# traceroute ipv4.google.com
traceroute to ipv4.google.com (216.58.207.78), 30 hops max, 60 byte packets
 1  _gateway (172.31.1.1)  0.139 ms  0.091 ms  0.062 ms
 2  12643.your-cloud.host (136.243.182.17)  0.320 ms  0.103 ms  0.075 ms
 3  * * *
 4  213-239-251-233.clients.your-server.de (213.239.251.233)  1.479 ms 213-239-251-237.clients.your-server.de (213.239.251.237)  0.722 ms  1.320 ms
 5  core21.fsn1.hetzner.com (213.239.239.125)  0.417 ms  0.310 ms  0.278 ms
 6  core4.fra.hetzner.com (213.239.245.18)  5.536 ms core4.fra.hetzner.com (213.239.245.14)  4.880 ms core0.fra.hetzner.com (213.239.252.33)  5.539 ms
 7  72.14.218.94 (72.14.218.94)  5.094 ms  5.085 ms  5.113 ms
 8  108.170.251.193 (108.170.251.193)  5.018 ms * 108.170.252.65 (108.170.252.65)  6.311 ms
 9  108.170.235.246 (108.170.235.246)  7.428 ms 72.14.232.50 (72.14.232.50)  4.903 ms 72.14.234.227 (72.14.234.227)  4.951 ms
10  108.170.252.18 (108.170.252.18)  5.287 ms fra16s25-in-f14.1e100.net (216.58.207.78)  4.804 ms 108.170.251.145 (108.170.251.145)  5.646 ms
root@test:~#

谢谢

0个回答
没有发现任何回复~