简体   繁体   English

将辅助私有IP地址分配给AWS EC2实例后无法访问RDS MySQL

[英]Cannot access RDS MySQL after assigning secondary private IP address to AWS EC2 instance

The instances are set up on a common VPC as follows: 实例是在通用VPC上设置的,如下所示:

  • EC2 instance running Ubuntu Server 16.04 LTS on a public subnet 在公共子网中运行Ubuntu Server 16.04 LTS的EC2实例
  • RDS MySQL on a private subnet 专用子网上的RDS MySQL
  • Both EC2 and RDS on common security group allowing inbound traffic on port 3306 通用安全组上的EC2和RDS都允许端口3306上的入站流量

The connection works fine when on the primary private IP address. 在主专用IP地址上时,连接工作正常。

After assigning a secondary private IP address to the EC2 instance, I perform the following: 在为EC2实例分配辅助私有IP地址后,我将执行以下操作:

  • Add the static IP to the /etc/network/interfaces.d/*.cfg file: 将静态IP添加到/etc/network/interfaces.d/*.cfg文件:

    Default file content: 默认文件内容:

    auto lo iface lo inet loopback

    auto eth0 iface eth0 inet dhcp

    Add static IP address: 添加静态IP地址:

    auto eth0:0 iface eth0:0 inet static address xx.xx.xx.xx

  • Run sudo ifup eth0:0 运行sudo ifup eth0:0

After this, MySQL refuses the connection and returns this error message: 之后,MySQL拒绝连接并返回以下错误消息:

Cannot access the database: No route to host (DNS_OF_RDS) 无法访问数据库:没有到主机的路由(DNS_OF_RDS)

The connection is re-established when I run sudo ifdown eth0:0 . 当我运行sudo ifdown eth0:0时,连接重新建立。

What am I missing out on? 我错过了什么?

我可以通过在文件/etc/network/interfaces.d/*.cfg末尾添加网络掩码地址( netmask 255.255.xx.xx )来使其工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM