本篇文章教大家NAT网关如何配置,NAT网关配置相当于路由器,如果服务器ECS没有公网IP只有私网IP,也可以依靠NAT去上网。话不多说,直接开始!
购买NAT网关并配置弹性公网IP
立即购买,确认订单,签署并下单,资源创建完毕后进入控制台。
配置DNAT管理
配置好后,我们可以通过xshell连通,但是依旧无法上网
[c:\~]$ ssh 8.130.74.161 6666 Connecting to 8.130.74.161:6666... Connection established. To escape to local shell, press Ctrl+Alt+]. Last login: Tue Apr 25 22:29:54 2023 from 123.112.19.205 Welcome to Alibaba Cloud Elastic Compute Service ! [root@web02 ~]# ping www.baidu.com PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data.
SNAT配置
创建好后,web1和web2皆可联网
[root@web02 ~]# ping www.baidu.com PING www.a.shifen.com (110.242.68.3) 56(84) bytes of data. 64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=1 ttl=49 time=20.1 ms 64 bytes from 110.242.68.3 (110.242.68.3): icmp_seq=2 ttl=49 time=20.0 ms ^C --- www.a.shifen.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 20.010/20.081/20.153/0.158 ms [root@web01 ~]# ping www.koten.vip PING www.koten.vip (101.200.45.134) 56(84) bytes of data. 64 bytes from 101.200.45.134 (101.200.45.134): icmp_seq=1 ttl=120 time=9.13 ms 64 bytes from 101.200.45.134 (101.200.45.134): icmp_seq=2 ttl=120 time=8.74 ms ^C --- www.koten.vip ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1000ms rtt min/avg/max/mdev = 8.743/8.937/9.131/0.194 ms
大功告成!
我是koten,10年运维经验,持续分享运维干货,感谢大家的阅读和关注!