-1

I'm wishing to simulate DNS for testing purposes, having decided to learn about it for if I was to go into webhosting.

I've considered BIND (and tried setting it up), but that wasn't suited to my purposes.

I wanted to use this to make a development ("dev") copy of my site.

I've had a look here but decided against this as it seemed slightly complex to use.

There's a reason I'm doing this, and it's solely to ensure I can test my site, and server load for it etc. without damaging the live site.

This is my current virtual host:

<VirtualHost 127.0.0.1>
              NameVirtualHost mywebsitedomain1.co.uk
    ServerName  mywebsitedomain1.co.uk
              ServerAlias   www.mywebsitedomain1.co.uk
    DocumentRoot /www/vhosts/mywebsitedomain1.co.uk
    ErrorLog /www/Apache22/logs/error.log

    <Directory "/www/vhosts/mywebsitedomain1.co.uk">
        Options All
        AllowOverride All
        order allow,deny
        allow from all
    </Directory>
</VirtualHost>

but I intend to do it like this (for testing):

<VirtualHost 12.345.678>
              NameVirtualHost mywebsitedomain1.co.uk
    ServerName  mywebsitedomain1.co.uk
              ServerAlias   www.mywebsitedomain1.co.uk
    DocumentRoot /www/vhosts/mywebsitedomain1.co.uk
    ErrorLog /www/Apache22/logs/error.log

    <Directory "/www/vhosts/mywebsitedomain1.co.uk">
        Options All
        AllowOverride All
        order allow,deny
        allow from all
    </Directory>
</VirtualHost>

(I don't think 12.345.678 would exist really, it's a placeholder here, in this context).

Note the 127.0.0.1 would be replaced with my website's IP, which I'm intending to simulate for testing purposes. I've already used HOSTS but am trying to go one step further.

Basically, what I'm trying to achieve is - a fake DNS server for testing without damaging the main site if my PHP scripts go wrong - it's set up for a client, and I'm wanting to get it right.

How would you recommend I go about this?

  • I think he's trying to do IP spoofing for DNS testing purposes, if my understanding is clear. I'm in a similar situation too, so this is useful for me. –  Apr 10 '11 at 11:18

2 Answers2

0

Not sure what you want to achieve exactly. The most trivial way to make sure that a specific box replies to a a certain DNS query with a certain IP is to edit the hosts file. If you want to see what sort of DNS queries your system makes, you can use wireshark or tcpdump. If you actually want to simulate DNS instability/delay/quirkiness, you need a trivial DNS server implementation, such as http://code.activestate.com/recipes/491264-mini-fake-dns-server/.

For hosts file location, see http://en.wikipedia.org/wiki/Hosts_%28file%29 (!).

EDIT: It seems like, for testing purposes you need only to trick the machine running your testing client(s) that your dev server is mywebsitedomain1.co.uk. Unless the testing clients runs its own dedicated DNS resolver (e.g. using libadns), editing the hosts files should be fine. Note the following example hack that I have in my /etc/hosts:

127.0.0.1       localhost repo.company.com
127.0.1.1       wonky.example.com     wonky

The second row is standard in most modern Linux distros. In the first row, I'm pretending that my localhost is our Subversion repository, so that I can then tunnel that traffic to my workplace network. The URL http://repo.company.com/projectsource will actually resolve to http://127.0.0.1/projectsource but still contain the HTTP host header Host: repo.company.com.

Does that sound like it addresses your need?

Bittrance
  • 2,970
  • 2
  • 21
  • 27
  • I'm actually using Windows 7, for the record. I'm trying to simulate an IP address and DNS before doing it on a live site. The HOSTS thing does work, though, thanks! –  Apr 10 '11 at 16:49
0

Not sure what you mean for "one step further" but let's have a stab in the dark. Asuming that you are using *nix box for your dev server and test your 'copy site' from your dev server. Every computer has 127.0.0.1 address (it's called loopback network address which mean no real traffic ever leave your computer) From your first apache virtualhost configuration. We can see that your apache is running on the loopback ip address. So basically you have to redirect dns query for mywebsitedomain1.co.uk to 127.0.0.1. This is achieved by adding one line on your /etc/hosts file like this: 127.0.0.1 mywebsitedomain1.co.uk And you are set for testing your script in this dev server

Now if you want to take this further I suggest you use different computer to test your script. We will call this computer as clientB and your dev server as devA.

You will need to setup real network connectivity between devA and clientB. We will stick with private ip address. My suggestion is like this devA IP: 192.168.12.34 subnet 255.255.255.0 and do not set gateway or dns server clientB IP: 192168.12.56 subnet 255.255.255.0 also do not set gateway but set dns server to devA IP

Next. Install dnsmasq on your devA. It is a simple dns, dhcp and tftp server. In the default configuration, dnsmasq will read your /etc/hosts file and populate its dns database. But you can configure it to not read /etc/hosts but to get the database from other file you specify. Dnsmasq use port udp 53 on your devA server so remember to unblock it from your dev server firewall (if there is). You must also change your apache configuration to reflect the change in IP address to 192.168.12.34

Now you must test dns resolution from clientB. If you ping mywebsitedomain1.co.uk you should get reply from 192.168.12.34 instead of your public ip address.

If everything is correct you should be able to test your script with confidence that it will work with your 'live' website

Good luck