网络资源测试

网络资源服务测试

image-20220719093856405

一、直连资源服务器

1
2
3
4
5
# 启动资源服务
python3 -m http.server 8081

# 访问资源服务  ->  成功
curl http://10.0.66.174:8081

二、访问 Server A

1. 访问 192 网段

1
2
3
4
5
6
7
8
# 配置 iptables 设置远程端口转发 10.0.66.96:8002  -> 10.0.66.174:8081
# DNAT:将目的地址替换为10.0.66.174:8081
iptables -t nat -A PREROUTING -d 10.0.66.96 -p tcp --dport 8002 -j DNAT --to-destination 10.0.66.174:8081
# SNAT:将源地址替换为10.0.66.96
iptables -t nat -A POSTROUTING -d 10.0.66.174 -p tcp --dport 8081 -j SNAT --to 10.0.66.96

# 访问服务器 A  -> 成功
curl http://10.0.66.96:8002

2. 访问 100 网段

1
2
3
4
5
6
# 配置 iptables 设置远程端口转发 100.93.105.24:8002  -> 10.0.66.174:8081
iptables -t nat -A PREROUTING -d 100.93.105.24 -p tcp --dport 8002 -j DNAT --to-destination 10.0.66.174:8081
iptables -t nat -A POSTROUTING -d 10.0.66.174 -p tcp --dport 8081 -j SNAT --to 100.93.105.24

# 访问服务器 A  -> 成功
curl http://100.93.105.24:8002

三、访问 Server B

1. Server A 和 B 通过物理网卡连接,访问192网段

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Server A:10.0.66.96:8002  -> 10.0.66.174:8081
iptables -t nat -A PREROUTING -d 10.0.66.96 -p tcp --dport 8002 -j DNAT --to-destination 10.0.66.174:8081
iptables -t nat -A POSTROUTING -d 10.0.66.174 -p tcp --dport 8081 -j SNAT --to 10.0.66.96

# Server B:10.0.66.247:8001  -> 10.0.66.96:8002
iptables -t nat -A PREROUTING -d 10.0.66.247 -p tcp --dport 8001 -j DNAT --to-destination 10.0.66.96:8002
iptables -t nat -A POSTROUTING -d 10.0.66.96 -p tcp --dport 8002 -j SNAT --to 10.0.66.247

# 访问服务器 B  -> 成功
curl http://10.0.66.247:8001

2. Server A 和 B 通过 VPN 连接,访问100网段

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Server A:100.93.105.24:8002  -> 10.0.66.174:8081
iptables -t nat -A PREROUTING -d 100.93.105.24 -p tcp --dport 8002 -j DNAT --to-destination 10.0.66.174:8081
iptables -t nat -A POSTROUTING -d 10.0.66.174 -p tcp --dport 8081 -j SNAT --to 100.93.105.24

# Server B:100.88.225.73:8001  -> 100.93.105.24:8002
iptables -t nat -A PREROUTING -d 100.88.225.73 -p tcp --dport 8001 -j DNAT --to-destination 100.93.105.24:8002
iptables -t nat -A POSTROUTING -d 100.93.105.24 -p tcp --dport 8002 -j SNAT --to 100.88.225.73

# 访问服务器 B  -> 成功
curl http://100.88.225.73:8001

3. Server A 和 B 通过 VPN 连接,访问 192 网段

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Server A:100.93.105.24:8002  -> 10.0.66.174:8081
iptables -t nat -A PREROUTING -d 100.93.105.24 -p tcp --dport 8002 -j DNAT --to-destination 10.0.66.174:8081
iptables -t nat -A POSTROUTING -d 10.0.66.174 -p tcp --dport 8081 -j SNAT --to 100.93.105.24

# Server B:
iptables -t nat -A PREROUTING -d 10.0.66.247 -p tcp --dport 8001 -j DNAT --to-destination 100.93.105.24:8002
# 自动转换源地址
iptables -t nat -A POSTROUTING -o tailscale0 -j MASQUERADE

# 访问服务器 B  -> 成功
curl http://10.0.66.247:8001
Licensed under CC BY-NC-SA 4.0
最后更新于 May 16, 2024 11:09 +0800
使用 Hugo 构建
主题 StackJimmy 设计