1

I am trying to automate the creation of an EC2 instance with CloudFormation but am running into issues with DNS.

Once the instance is created it can't seem to resolve any hostnames. I try to ping a hostname, such as google.com, and it can't be resolved. However, it can ping IP addresses.

My template is below and I understand that there are some unused parameters which I intend to use later on:

{  "Description": "Create an EC2 instance by AWS CloudFormation",  "Parameters": {
"KeyName": {
  "MinLength": 1,
  "Type": "AWS::EC2::KeyPair::KeyName"
},
"BaseAmiId": {
  "Default": "ami-bd3ba0aa",
  "Type": "String"
},
"DomainAdminUser": {
  "Description": "User name for the account that will be added as Domain Administrator. This is separate from the default \"Administrator\" account",
  "Type": "String",
  "Default": "installer"
},
"DomainUserPassword": {
  "NoEcho": "true",
  "Description": "The Windows administrator account password",
  "Type": "String",
  "MinLength": "8",
  "MaxLength": "41"
},
"DomainDNSName": {
  "Description": "Fully qualified domain name (FQDN) of the forest root domain",
  "Type": "String",
  "Default": "test.com"
},
"DomainNetBiosName": {
  "Description": "Netbios name for the domain",
  "Type": "String",
  "Default": "test"
}  },  "Resources": {
"SecurityGroupDemoSvrTraffic": {
  "Type": "AWS::EC2::SecurityGroup",
  "Properties": {
    "GroupName": "sgDemoSvr",
    "SecurityGroupIngress": [
      {
        "IpProtocol": "tcp",
        "FromPort": 3389,
        "ToPort": 3389,
        "CidrIp": "0.0.0.0/0",
        "Description": "For traffic from Internet"
      }
    ],
    "GroupDescription": "Security Group for demo server",
    "VpcId": "vpc-05eabde4dbadsf09"
  }
},
"EC2Instance": {
  "Type": "AWS::EC2::Instance",
  "Properties": {
    "AvailabilityZone": "eu-west-2b",
    "BlockDeviceMappings": [
      {
        "DeviceName": "/dev/sda1",
        "Ebs": {
          "DeleteOnTermination": "true",
          "VolumeSize": "32",
          "VolumeType": "gp2"
        }
      }
    ],
    "ImageId": "ami-029c4f36a959979a7",
    "InstanceType": "t2.micro",
    "KeyName": {
        "Ref": "KeyName"
    },
    "NetworkInterfaces": [
      {
        "Description": "Primary network interface",
        "DeviceIndex": "0",
        "SubnetId": "subnet-0b3f36d19eb3sdfda",
        "AssociatePublicIpAddress": true,
        "GroupSet": [
          {
            "Ref": "SecurityGroupDemoSvrTraffic"
          }
        ]
      }
    ]
  }
}  }}

2 Answers 2

1

Which flavor of Linux are you using? (eg Ubuntu/Debian, RHEL/CentOS etc) Also which version? (eg Ubuntu started using the "netplan" configuration by default in 20.04)

At first glance, it looks like your DNS nameservers are hosed somehow.

And can you post the results for doing a: netstat -nutpl?

Look at which PID/Program Name is listening on port 53 (systemd-resolve? dnsmasq?) and check its nameserver configuration.

Maybe check here: sudo cat /etc/resolv.conf and make sure the nameserver(s) listed there are what you think you should have them.

or check the DNS-related services are even running with something like:

Ubuntu: sudo service systemd-resolved status (NOTE BOTH of the 'd' endings)

CentOS/RHEL: sudo service dnsmasq status

(or whatever is using port 53, which is the default DNS port on most OSes)

0

The issue was due to the DNS ports not being configured properly. I had to configure port 53 in my security groups to get this to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.