How to connect to outside world from amazon vpc?

后端 未结 11 1198
甜味超标
甜味超标 2020-12-22 15:38

I have amazon VPC set through wizard as \"public only network\", so all my instances are in public subnet.

Instances within VPC that have Elastic IP assigned connect

11条回答
  •  臣服心动
    2020-12-22 16:33

    This works for me with :

    • VPC subnet 172.20.0.0/16
    • EC2 "nat" gateway 172.20.10.10 with EIP

    To do :

    • Set disabled source/dest. check on your "nat gw"
    • create a new "nat-sub" subnet ex: 172.20.222.0/24
    • modify route 0.0.0.0/0 to 172.20.10.10 (my nat gw) for "nat-sub"
    • create a EC2 using "nat-sub"
    • on your nat gateway as root, try :

    root@gw:~# sysctl -q -w net.ipv4.ip_forward=1 net.ipv4.conf.eth0.send_redirects=0

    root@gw:~# iptables -t nat -C POSTROUTING -o eth0 -s 172.20.222.0/24 -j MASQUERADE 2> /dev/null || iptables -t nat -A POSTROUTING -o eth0 -s 172.20.222.0/24 -j MASQUERADE

    if it works, add this 2 lines in /etc/rc.local

提交回复
热议问题