Skip to content

Instantly share code, notes, and snippets.

@ifnull
Created July 3, 2014 02:20
Show Gist options
  • Save ifnull/7bc36ddf4cdec8423d76 to your computer and use it in GitHub Desktop.
Save ifnull/7bc36ddf4cdec8423d76 to your computer and use it in GitHub Desktop.
Setting up a DNS server for the purposed of testing a production server prior to DNS change.

Requirements

Create AWS Security Group

aws ec2 create-security-group --group-name DnsServer --description "Simple DNS Server" --profile blitz
aws ec2 authorize-security-group-ingress --group-name DnsServer --protocol udp --port 53 --cidr 0.0.0.0/0 --profile blitz
aws ec2 authorize-security-group-ingress --group-name DnsServer --protocol tcp --port 22 --cidr 0.0.0.0/0 --profile blitz
  • DnsServer is arbitrary but will be referenced moving foward.

Create AWS EC2 Instance

aws ec2 run-instances --image-id ami-a49665cc --security-groups DnsServer --instance-type t1.micro --region us-east-1 --key blitz --profile blitz
  • ami-a49665cc is an Ubuntu AMI available only in the us-east-1 region. Another image and region can be used.
  • --key references the EC2 key pair.
  • DnsServer is the previously created security group

Setup DNS server

Get hostname

aws ec2 describe-instances --profile blitz 
  • Search for DnsServer or the name of your security group and copy the corresponding hostname. It should look like ec2-x-x-x-x.compute-x.amazonaws.com.

Connect

ssh -i ~/.ssh/blitz.pem [email protected]
  • Replace ec2-x-x-x-x.compute-x.amazonaws.com with hostname from above.

Install DNS service

sudo su -
apt-get update
tasksel install dns-server

Add new zone

vi /etc/bind/named.conf.local

Append the following content...

zone "foobar.com" {
	type master;
        file "/etc/bind/db.foobar.com";
};

Create new zone

cp /etc/bind/db.local /etc/bind/db.foobar.com
vi /etc/bind/db.foobar.com

Example ...

$TTL    604800
@       IN      SOA     ec2-x-x-x-x.compute-x.amazonaws.com. root.foobar.com. (
                              3         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ec2-x-x-x-x.compute-x.amazonaws.com.
@       IN      A       1.2.3.4
@       IN      AAAA    ::1
www     IN      A       1.2.3.4
store   IN      A       1.2.3.4
  • 1.2.3.4 should be the IP of your soon to be production server
  • ec2-x-x-x-x.compute-x.amazonaws.com should be the hostname from above

Restart

service bind9 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment