我们有一个[S]SRV_GATEWAY服务器,带有两个 NIC([I]WAN/INT_LAN和[I]PRIV_LAN),配置为专用网络([N]PRIV_LAN)的 GATEWAY、DNS 和 DHCP。
服务器[S]SRV_GATEWAY访问互联网(它使用自己作为 DNS),所有其他服务器([S]PRIV_SRV_X )使用服务器[S]SRV_GATEWAY提供的 DHCP、DNS 和 GATEWAY 。
- 网络布局...
[N]WAN/INT_LAN (10.2.0.0/24)
↕
[I]WAN/INT_LAN
[S]SRV_GATEWAY
[I]PRIV_LAN
↕
[N]PRIV_LAN (10.3.0.0/24)
↕
...............................
↕ ↕ ↕
[S]PRIV_SRV_0 [S]PRIV_SRV_1 [S]PRIV_SRV_0
[S]PRIV_SRV_2 [S]PRIV_SRV_0
[S]PRIV_SRV_3
_ [N] - Network;
_ [I] - Network Interface;
_ [S] - Server.
_ [N]WAN/INT_LAN - Has internet access;
_ [N]PRIV_LAN - Private network.
问题:为什么我们可以ping
在 Internet 上成功运行服务器,但无法使用curl
服务器[S]PRIV_SRV_0访问相同的服务器(请参阅下面的输出)?
[root@okd4-bootstrap core]# ping -c 2 www.google.com
PING www.google.com (172.217.18.196) 56(84) bytes of data.
64 bytes from ham02s14-in-f196.1e100.net (172.217.18.196): icmp_seq=1 ttl=113 time=10.5 ms
64 bytes from par10s38-in-f4.1e100.net (172.217.18.196): icmp_seq=2 ttl=113 time=10.6 ms
--- www.google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 10.500/10.548/10.597/0.048 ms
[root@okd4-bootstrap core]# curl http://www.google.com
curl: (7) Failed to connect to www.google.com port 80: No route to host
额外的:
- SRV_GATEWAY如何设置为 GATEWAY:
服务器SRV_GATEWAY已通过命令配置为 GATEWAY...
启用IP 转发...
tee "/etc/sysctl.d/ip_forward.conf" << EOF
net.ipv4.ip_forward=1
EOF
sysctl -w net.ipv4.ip_forward=1
在 NIC ens3 ( [I]WAN/INT_LAN ) 上设置一个出站 NAT 网关,目标是在 CIDR 10.3.0.0/24 中配置的屏蔽设备...
firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o ens3 -j MASQUERADE -s 10.3.0.0/24
firewall-cmd --reload
- 从服务器[S]PRIV_SRV_0获得的一些信息:
[root@okd4-bootstrap core]# cat /etc/resolv.conf | grep -i '^nameserver' | head -n1 | cut -d ' ' -f2
10.3.0.14
[root@okd4-bootstrap core]# ip r
default via 10.3.0.14 dev ens3 proto dhcp metric 100
10.3.0.0/24 dev ens3 proto kernel scope link src 10.3.0.4 metric 100
[root@okd4-bootstrap core]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.3.0.14 0.0.0.0 UG 100 0 0 ens3
10.3.0.0 0.0.0.0 255.255.255.0 U 100 0 0 ens3
[root@okd4-bootstrap core]# netstat -r -n
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.3.0.14 0.0.0.0 UG 0 0 0 ens3
10.3.0.0 0.0.0.0 255.255.255.0 U 0 0 0 ens3
[root@okd4-bootstrap core]# ping -c 2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=113 time=10.8 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=113 time=11.0 ms
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 10.769/10.891/11.013/0.122 ms
[root@okd4-bootstrap core]# cat /etc/resolv.conf
# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 10.3.0.14
search okd.local
[root@okd4-bootstrap core]# tracepath 8.8.8.8
1?: [LOCALHOST] pmtu 1500
1: api-int.mbr.okd.local 0.526ms
1: api-int.mbr.okd.local 0.855ms
2: okd4-services.okd.local 1.842ms !H
Resume: pmtu 1500
[root@okd4-bootstrap core]# tracepath www.google.com
1?: [LOCALHOST] pmtu 1500
1: api.mbr.okd.local 0.481ms
1: api-int.mbr.okd.local 0.562ms
2: api.mbr.okd.local 0.553ms !H
Resume: pmtu 1500
[root@okd4-bootstrap core]# ip route show
default via 10.3.0.14 dev ens3 proto dhcp metric 100
10.3.0.0/24 dev ens3 proto kernel scope link src 10.3.0.4 metric 100
[root@okd4-bootstrap core]# nslookup www.google.com
Server: 10.3.0.14
Address: 10.3.0.14#53
Non-authoritative answer:
Name: www.google.com
Address: 172.217.18.196
Name: www.google.com
Address: 2a00:1450:4007:805::2004
[root@okd4-bootstrap core]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
谢谢!=D