LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   DNS setup (https://www.linuxquestions.org/questions/linux-newbie-8/dns-setup-714623/)

dils 03-26-2009 12:39 PM

DNS setup
 
hello there
well i have been deploying a linux box as a router for a private network. i have been using Fedora Core 9 as linux distribution. My NAT and DHCP server is already working fine. but now i have a problem setting up a DNS which should point to the actual DNS server of my ISP. the thing is that i don't know how to set up a DNS server. Anyone out there could help me with this. i would be very grateful to u.

cheers
dils

oldtincup 03-26-2009 02:41 PM

I don't know how much help I'll be. I have only setup a DNS server in SuSE, and that was years ago.

I am not sure why you want a DNS server. Usually when you connect to your ISP it should setup resolv.conf with the ISP's DNS info.

Although, maybe you want to setup a caching DNS server? This would speed up name resolution for frequently visited sites.

Or do you have a home network that you want to resolve names for and just pass the rest to your ISP?

vikas027 03-26-2009 02:59 PM

Quote:

Originally Posted by dils (Post 3488627)
hello there
well i have been deploying a linux box as a router for a private network. i have been using Fedora Core 9 as linux distribution. My NAT and DHCP server is already working fine. but now i have a problem setting up a DNS which should point to the actual DNS server of my ISP. the thing is that i don't know how to set up a DNS server. Anyone out there could help me with this. i would be very grateful to u.

cheers
dils

Hey,

I have made this script to configure DNS on RHEL machines, may be it works for others too. I am not very sure about this. I have tested it, works fine.

Anyways, here is it. You just need to given a hostname to your linux box like server.vikas.com, and everything else will be handled by the script.

After running the script, run these commands :--
Code:

bind-chroot-admin -d; bind-chroot-admin -e; service named restart

SCRIPT

Code:

mkdir /tmp/my_logs/
exec 2>/tmp/my_logs/dns_error_logs

IP=$(ifconfig eth0 | grep "inet addr" | sed -e 's/^[ \t]*//' | awk -F"Bcast" '{print $1}' | awk -F":" '{print $2}')

IP1=$( echo $IP |  awk -F "." '{print $1}' )
IP2=$( echo $IP |  awk -F "." '{print $2}' )
IP3=$( echo $IP |  awk -F "." '{print $3}' )
IP4=$( echo $IP |  awk -F "." '{print $4}' )

echo -n "Please enter your desired hostname (in format like server.example.com) - "
read hname

hname1=$( echo $hname |  awk -F "." '{print $1}' )
hname2=$( echo $hname |  awk -F "." '{print $2}' )
hname3=$( echo $hname |  awk -F "." '{print $3}' )

cp -p /etc/sysconfig/network        /etc/sysconfig/network.BACKUP
cp -p /etc/resolv.conf                /etc/resolv.conf.BACKUP

sed -i '/HOSTNAME/d' /etc/sysconfig/network
echo "HOSTNAME=$hname" >> /etc/sysconfig/network
hostname $hname

grep $IP /etc/resolv.conf > /dev/null
if [ $? -eq 1 ]
then
echo "nameserver $IP" >> /etc/resolv.conf
fi

# Install needed packages with dependecies
yum -y remove bind* caching-nameserver* system-config-bind*
rm -rf /var/named rm -f /etc/named*
yum -y install bind* caching-nameserver* system-config-bind*
chkconfig named on

# MAKING SKELETON /etc/named.conf
echo "options {" >> /etc/named.conf
echo "listen-on port 53 { 127.0.0.1; };" >> /etc/named.conf
echo "listen-on-v6 port 53 { ::1; };" >> /etc/named.conf
echo "directory      "/var/named";" >> /etc/named.conf
echo "dump-file      "/var/named/data/cache_dump.db";" >> /etc/named.conf
echo "statistics-file "/var/named/data/named_stats.txt";" >> /etc/named.conf
echo "memstatistics-file "/var/named/data/named_mem_stats.txt";" >> /etc/named.conf
echo "query-source    port 53;" >> /etc/named.conf
echo "query-source-v6 port 53;" >> /etc/named.conf
echo "allow-query    { localhost; };" >> /etc/named.conf
echo "};" >> /etc/named.conf
echo -e -n "\n" >> /etc/named.conf
echo -e -n "\n" >> /etc/named.conf
echo "zone "localhost" IN {" >> /etc/named.conf
echo "type master;" >> /etc/named.conf
echo "file "localhost.zone";" >> /etc/named.conf
echo "allow-update { none; };" >> /etc/named.conf
echo "};" >> /etc/named.conf
echo -e -n "\n" >> /etc/named.conf
echo "zone "0.0.127.in-addr.arpa" IN {" >> /etc/named.conf
echo "type master;" >> /etc/named.conf
echo "file "named.local";" >> /etc/named.conf
echo "allow-update { none; };" >> /etc/named.conf
echo "};" >> /etc/named.conf

# Correcting entries in /etc/named.conf where double quotes (") are not inserted
sed -i 's/localhost IN/"localhost" IN/' /etc/named.conf
sed -i 's/localhost.zone/"localhost.zone"/' /etc/named.conf
sed -i 's/0.0.127.in-addr.arpa/"0.0.127.in-addr.arpa"/' /etc/named.conf
sed -i 's/named.local/"named.local"/' /etc/named.conf
sed -i 4's|/var/named|"/var/named"|' /etc/named.conf
sed -i 5's|/var/named/data/cache_dump.db|"/var/named/data/cache_dump.db"|' /etc/named.conf
sed -i 6's|/var/named/data/named_stats.txt|"/var/named/data/named_stats.txt"|' /etc/named.conf
sed -i 7's|/var/named/data/named_mem_stats.txt|"/var/named/data/named_mem_stats.txt"|' /etc/named.conf


cp -p /etc/named.conf /etc/named.conf_skel

# Putting new entries in /etc/named.conf
sed -i 2's/127.0.0.1/'$IP1'.'$IP2'.'$IP3'.'$IP4'/' /etc/named.conf
sed -i '/allow-query/d' /etc/named.conf
sed -i '10i\allow-query    { IP1.IP2.IP3.0/24; };' /etc/named.conf
sed -i 's/IP1/'$IP1'/' /etc/named.conf
sed -i 's/IP2/'$IP2'/' /etc/named.conf
sed -i 's/IP3/'$IP3'/' /etc/named.conf
sed -i 14's/localhost/'$hname2'.'$hname3'/' /etc/named.conf
sed -i 's/localhost.zone/'$hname2'.fwd/' /etc/named.conf
sed -i 's/0.0.127.in-addr.arpa/'$IP2'.'$IP1'.in-addr.arpa/' /etc/named.conf
sed -i 's/named.local/'$hname2'.rev/' /etc/named.conf

# Copy sample files
cp -p /var/named/localhost.zone /var/named/$hname2.fwd       
cp -p /var/named/named.local /var/named/$hname2.rev

# New Reverse Lookup file
sed -i 's/localhost/'$hname'/'    /var/named/$hname2.rev
sed -i 2's/localhost/'$hname'/'    /var/named/$hname2.rev
sed -i 9's/1/'$IP4'.'$IP3'/'      /var/named/$hname2.rev
sed -i 9's/'$hname'./'$hname1'/'  /var/named/$hname2.rev

# New Forward Lookup file
head -2 /var/named/$hname2.rev > /var/named/$hname2.fwd.tmp1
cat /var/named/$hname2.fwd.tmp1 /var/named/$hname2.fwd > /var/named/$hname2.fwd.tmp2
cp -p /var/named/$hname2.fwd.tmp2 /var/named/$hname2.fwd
rm -f /var/named/$hname2.fwd.tmp*
sed -i 11's/@/'$hname'./' /var/named/$hname2.fwd
sed -i 's/IN A/'$hname1' &/'  /var/named/$hname2.fwd
sed -i 's/127.0.0.1/'$IP1'.'$IP2'.'$IP3'.'$IP4'/'  /var/named/$hname2.fwd
sed -i '/IN AAAA/d'  /var/named/$hname2.fwd
sed -i '13d' /var/named/$hname2.fwd
grep $IP1 /var/named/$hname2.fwd | sed -e 's/^[ \t]*//' >> /var/named/$hname2.fwd
sed -i '12d' /var/named/$hname2.fwd
sed -i '3d' /var/named/$hname2.fwd
sed -i '3d' /var/named/$hname2.fwd

echo -e -n "\t\t\t\t Reboot or logoff the machine to apply the changes\n and run bind-chroot-admin -d; bind-chroot-admin -e; service named restart"


dils 03-27-2009 01:00 PM

Quote:

Originally Posted by oldtincup (Post 3488755)
I don't know how much help I'll be. I have only setup a DNS server in SuSE, and that was years ago.

I am not sure why you want a DNS server. Usually when you connect to your ISP it should setup resolv.conf with the ISP's DNS info.

Although, maybe you want to setup a caching DNS server? This would speed up name resolution for frequently visited sites.

Or do you have a home network that you want to resolve names for and just pass the rest to your ISP?

@
well for my project, i need to provide internet for a private network. hence i did nat. but my clients are not getting an internet connection as i do not have a DNS server. If i am pinging an external IP address, am receiving data, meaning NAT configuration is good...

@vikas
well will try that and let u know if it worked. thx a lot for ur help

oldtincup 03-30-2009 08:27 AM

Quote:

Originally Posted by dils (Post 3489821)
@
well for my project, i need to provide internet for a private network. hence i did nat. but my clients are not getting an internet connection as i do not have a DNS server. If i am pinging an external IP address, am receiving data, meaning NAT configuration is good...

In that case you don't need a DNS server. You just need to point your clients to your ISP's DNS server. Since you already have a DHCP server setup the easiest way to do that would be to add a line like this to your dhcpd.conf file:

Code:

option domain-name-servers      ISP's Primary DNS Address, Secondary DNS Address;

malekmustaq 03-30-2009 09:23 AM

dils:

There is an easily configurable dns/router daemon freely available in linux. Check if you have it already in your system:

/usr/doc/dnsmasq-2.46/setup.html

try to find out if dnsmasq can meet your need.

goodluck

hope this helps.

dils 03-31-2009 11:54 AM

Quote:

Originally Posted by malekmustaq (Post 3492551)
dils:

There is an easily configurable dns/router daemon freely available in linux. Check if you have it already in your system:

/usr/doc/dnsmasq-2.46/setup.html

try to find out if dnsmasq can meet your need.

goodluck

hope this helps.

@vikas
the code u gave me did not work... anywayz thxxx for ur help. i appreciate it...
@oldtincup
tried that out... the starting of my dhcp service failed... :(
@malekmustaq
is it a seperate package to be installed or it comes with the DNS bind package??

vikas027 03-31-2009 12:13 PM

Quote:

Originally Posted by dils (Post 3493879)
@vikas
the code u gave me did not work... anywayz thxxx for ur help. i appreciate it...

What problems are you facing while running the script. It runs on RHEL 5, RHEL 4. I have tested it many times.

Do you have yum configured ?? my script needs yum to be installed.

dils 04-01-2009 11:09 AM

well thnk i got the problem... was just that yum was not configured on my machine :S
thxx everyone who replied to the thread


All times are GMT -5. The time now is 10:01 PM.