0

I'm trying to setup my own nameservers like ns1.example.com on my VPS

I already setup the nameservers of my domain in Namecheap.com (ns1 and ns2, pointing to the IP address of my VPS). I can't seem to make it working. Opening example.com doesn't show-up anything:

$ curl example.com
curl: (7) Failed to connect to example.com port 80: No route to host

Note that Apache is working fine, since I can open it using VPS IP. Here's my server configuration

/etc/hostname

ns1

/etc/hosts

127.0.0.1   localhost.localdomain localhost
172.31.1.100    ns1.example.com ns1
172.31.1.100    ns2.example.com ns2

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
2a01:4f8:c17:1eeb::2  ns1.example.com ns1
2a01:4f8:c17:1eeb::2  ns2.example.com ns2

/etc/bind/named.conf

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

/etc/bind/named.conf.options

options {
    directory "/var/cache/bind";
    recursion no;
    allow-transfer { none; };

    dnssec-validation auto;

    auth-nxdomain no;    # conform to RFC1035
    listen-on-v6 {
        any;
        };
};

/etc/bind/named.conf.local

zone "example.com" {
    type master;
    file "/var/lib/bind/example.com.hosts";
    allow-transfer {
        127.0.0.1;
        localnets;
        172.31.1.100;
        };
    };

/etc/bind/named.conf.default-zones;

zone "." {
    type hint;
    file "/etc/bind/db.root";
};

zone "localhost" {
    type master;
    file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
    type master;
    file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
    type master;
    file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
    type master;
    file "/etc/bind/db.255";
};

/var/lib/bind/example.com.hosts

$ttl 38400
@   IN  SOA example.com. root.example.com. (
            1486054499
            10800
            3600
            604800
            38400 )
example.com.        IN  NS  ns1.example.com.
example.com.        IN  NS  ns2.example.com.
ns1.example.com.    IN  A   172.31.1.100
ns2.example.com.    IN  A   172.31.1.100
example.com.        IN  A   172.31.1.100
www.example.com.    IN  A   172.31.1.100
ftp.example.com.    IN  A   172.31.1.100
m.example.com.      IN  A   172.31.1.100
localhost.example.com.  IN  A   127.0.0.1
mail.example.com.   IN  A   172.31.1.100
example.com.        IN  MX  5 mail.example.com.
example.com.        IN  TXT "v=spf1 a mx a:example.com ip4:172.31.1.100 ip6:2a01:4f8:c17:1eeb::2 ?all"
  • Question is too broad. What exactly are you trying to achieve and why? Exactly what is not working? Where are the logs that show error messages? Can you demonstrate the problem symptoms, maybe using a curl? – Tim Feb 02 '17 at 21:35
  • I'm trying to setup my own nameservers like ns1.example.com on my VPS. What is not working, is certainly the actual domain connected to this nameserver which is "example.com". When I open it, nothing shows up (it cannot find the server). Mind you Apache is running fine when using the IP to open the website. – Hossain Alhaidari Feb 03 '17 at 05:42
  • Please edit your question to include all the information I requested in your first post. If you supply enough information the question can be reopened. – Tim Feb 03 '17 at 06:07
  • I'm not sure what information you're looking for! I'll add the domain not working part, though its pretty obvious as I mentioned its not working. Regarding logs, you didn't mention what log! Virtualmin Log? Apache log?! Instead of closing, lets others read and maybe they'll have an answer... – Hossain Alhaidari Feb 03 '17 at 06:19
  • Why have you put RFC1918 IPv4 addresses in your DNS zone file? Is that what is actually in the file? That won't work on the global Internet, you know. – Michael Hampton Feb 03 '17 at 06:25
  • Well Virtualmin added this in my file and yes its what actually in the file! Should I put my global IP? – Hossain Alhaidari Feb 03 '17 at 06:29
  • Well, yes of course! Nobody can reach you on IPv4 otherwise. – Michael Hampton Feb 03 '17 at 06:30
  • Great, thank you! Just could you please let me know that should I change in all files, or its just one of the files you're mentioning, like "/etc/hosts" maybe? – Hossain Alhaidari Feb 03 '17 at 06:32

1 Answers1

0

Thanks to Michael Hampton

The problem was that I was using Private IPs instead of Public IPs.

Changed all private IPs to my VPS public IP and everything works fine now.