Ubuntu, fake DNS Server or setting up a local DNS server for a web developer

    Why is this necessary.
    There are NN locally raised projects on the developer's workstation. This developer for each project does the following:
    1. To work with a local copy of the project, edit the config of its web server (apache, lighttpd etc.) and specify in the config the host name for this local project.
    2. Then restarts the web server.
    3. Then he goes to edit / etc / hosts. He writes the name of the new host and local ip there.
    4. Then he finds out that this registered host is blocked by the one that is suddenly needed on the Internet, or he was mistaken when he registered the name in the web server config or in hosts.
    As a result of all this tediousness, precious nervous energy is usually spent which can be spent more efficiently on something more interesting.

    What I propose to do.
    I suggest making a local domain (in the .mydev example) and shortening the procedure above to two steps:
    1. We write in the web server config a new host with the name projectname.mydev
    2. We restart the web server
    And that’s it. We are gladly starting to finish our project by the given name.

    What we will do, TODO

    1. Install the DNS server.
    sudo apt-get install bind9

    2. We go to examine actually configs. The principle of this thing is that at the moment when accessing a host (this is a rough scheme), our machine goes to a DNS server issued to it by the provider or registered manually, in accordance with the settings. Obtains the actual host IP from the DNS and goes for data in the direction of this IP. Further we are not interested. How will it be.And it will be like this: when referring to any host, we will contact the local DNS server, which will check our rules and if the request does not fall under our rules, then our local DNS goes and asks the same provider DNS. And it already gives us actually its (provider) answer. So, we go to the
    cd /etc/bind

    REM configs : I use mc. We will need superuser rights, so either sudo mc or sudo mcedit filename when editing each file, I won’t touch upon the rights issue further.

    3. Open named.conf.options for editing.
    Here we are interested in the forwarders section, we need to uncomment it and specify the IP address (s) of the provider's DNS server (or maybe a router, depending on how the Internet connection is organized). Save, exit.

    4. Open named.conf.default-zones for editing.
    Here we need to add a new zone down. The new section will look like this: 5. On the specified path, create a file That is, just make a copy of the local zone description. We will need to edit something in it. So we made a copy, now: 6. Open db.mydev for editing. There we need to fix just a few lines. As a result, our db.mydev will look like this: Compare with the original db.local in order to understand what happened. Essentially nothing special. 7. Now it remains only to restart our DNS 8. Well, now we check how it works.
    zone "mydev" {
    type master;
    file "/etc/bind/db.mydev";
    };



    sudo cp /etc/bind/db.local /etc/bind/db.mydev




    $TTL 604800
    @ IN SOA mydev. root.mydev. (
    2 ; Serial
    604800 ; Refresh
    86400 ; Retry
    2419200 ; Expire
    604800 ) ; Negative Cache TTL

    @ IN NS mydev.

    @ IN A 127.0.0.1
    * IN A 127.0.0.1
    @ IN AAAA ::1




    sudo /etc/init.d/bind9 restart


    ping 11.mydev
    ping 22.mydev

    If it works, then the IP should be the one you specified (in the example 127.0.0.1), but now nothing works. Because ...

    9. I forgot to talk about the rake. NetworkManager automatically writes the DNS provider address in /etc/resolv.conf. If external DNS is registered there, then our craft will not work. Appeals to the network just go past her. To fix this, you need to go into the properties of the current Internet connection, go to:
    “Change connections” => Choose our connection => “IPv4 settings”
    Here we indicate the IP of our local DNS (in the example 127.0.0.1), you can do this by selecting the "DHCP, only address" method. That should be enough. After that, through the NetworkManager, we disconnect the connection and establish it again. If everything is ok, then in /etc/resolv.conf we should see our desired IP, the one that was registered as DNS in NetworkManager.

    10. Now we check the result.

    That's all. Now you can not touch / etc / hosts

    Also popular now: