We are going to learn in this tutorial how to host multiple domains on a single IP.
Bind Installation
———————-
yum install bind bind-utils bind-* caching-*
Now we are going to configure the Bind Service you can copy the files content and modify with your required settings.
# cd /var/named/chroot/etc
# vi named.conf
Named.conf Contents
options { directory "/var/named"; // the default dump-file "data/cache_dump.db"; statistics-file "data/named_stats.txt"; memstatistics-file "data/named_mem_stats.txt"; }; zone "." IN { type hint; file "named.root"; }; zone "localhost" IN { type master; file "localhost.fwd"; allow-update { none; }; }; zone "0.0.127.in-addr.arpa" IN { type master; file "localhost.rev"; allow-update { none; }; }; zone "maindomain.com" IN { type master; file "maindomain.com.fwd"; allow-update { none; }; }; zone "domain1.com" IN { type master; file "domain1.com.fwd"; allow-update { none; }; }; zone "domain2.com" IN { type master; file "domain2.com.fwd"; allow-update { none; }; }; zone "0.168.192.in-addr.arpa" IN { type master; file "maindomain.com.rev"; allow-update { none; }; };
# cd .. # cd var/named
Now create named.root file # This file is used for root dns
# vi named.root
Named.root File Contents
Linux Bind :
; root “.†zone hints file, queried of a.root-servers.net. by system-config-bind ; version of root zone: 2011061400 . 518400 IN NS b.root-servers.net. . 518400 IN NS i.root-servers.net. . 518400 IN NS l.root-servers.net. . 518400 IN NS f.root-servers.net. . 518400 IN NS d.root-servers.net. . 518400 IN NS k.root-servers.net. . 518400 IN NS h.root-servers.net. . 518400 IN NS g.root-servers.net. . 518400 IN NS a.root-servers.net. . 518400 IN NS c.root-servers.net. . 518400 IN NS m.root-servers.net. . 518400 IN NS e.root-servers.net. . 518400 IN NS j.root-servers.net. b.root-servers.net. 3600000 IN A 192.228.79.201 i.root-servers.net. 3600000 IN A 192.36.148.17 i.root-servers.net. 3600000 IN AAAA 2001:7fe::53 l.root-servers.net. 3600000 IN A 199.7.83.42 l.root-servers.net. 3600000 IN AAAA 2001:500:3::42 f.root-servers.net. 3600000 IN A 192.5.5.241 f.root-servers.net. 3600000 IN AAAA 2001:500:2f::f d.root-servers.net. 3600000 IN A 128.8.10.90 d.root-servers.net. 3600000 IN AAAA 2001:500:2d::d k.root-servers.net. 3600000 IN A 193.0.14.129 k.root-servers.net. 3600000 IN AAAA 2001:7fd::1 h.root-servers.net. 3600000 IN A 128.63.2.53 h.root-servers.net. 3600000 IN AAAA 2001:500:1::803f:235
Save & Exit
Now Create Zone Files which we mentioned in named.conf file
localhost.fwd
localhost.rev
maindomain.com.fwd
maindomain.com.rev
domain1.com.fwd
domain2.com.fwd
# vi localhost.fwd
Localhost.fwd file contents
$ORIGIN localhost. $TTL 86400 @ IN SOA ns1.maindomain.com. root.maindomain.com. ( 20110930 ; Serial number 3H ; Refresh 1 day 15M ; Retry 2 hours 1W ; Expire 41.67 days 1D ) ; Minimum TTL 2 days @ IN NS ns1.maindomain.com. localhost. IN A 127.0.0.1
Save & Exit
# vi localhost.rev
Localhost.rev file contents
$ORIGIN 0.0.127.in-addr.arpa. $TTL 86400 @ IN SOA ns1.maindomain.com. root.maindomain.com. ( 20110930 ; Serial number 3H ; Refresh 1 day 15M ; Retry 2 hours 1W ; Expire 41.67 days 1D ) ; Minimum TTL 2 days @ IN NS ns1.maindomain.com. 1.0.0.127.in-addr.arpa. IN PTR localhost.
# vi maindomain.com.fwd
Maindomain.com.fwd Contents
$ORIGIN maindomain.com. $TTL 86400 @ IN SOA ns1.maindomain.com. root.maindomain.com. ( 20110930 ; Serial number 3H ; Refresh 1 day 15M ; Retry 2 hours 1W ; Expire 41.67 days 1D ) ; Minimum TTL 2 days @ IN NS ns1.maindomain.com. @ IN MX 10 ns1.maindomain.com. ns1.maindomain.com. IN A 192.168.0.220 www IN CNAME ns1
# vi maindomain.com.rev
Maindomain.com.rev Contents
$ORIGIN 0.168.192.in-addr.arpa. $TTL 86400 @ IN SOA ns1.maindomain.com. root.maindomain.com. ( 20110930 ; Serial number 3H ; Refresh 1 day 15M ; Retry 2 hours 1W ; Expire 41.67 days 1D ) ; Minimum TTL 2 days @ IN NS ns1.maindomain.com. @ IN MX 10 ns1.maindomain.com. 220.0.168.192.in-addr.arpa. IN PTR ns1.maindomain.com.
# vi domain1.com.fwd
domain1.com.fwd Contents
$ORIGIN domain1.com. $TTL 86400 @ IN SOA ns1.maindomain.com. root.maindomain.com. ( 20110930 ; Serial number 3H ; Refresh 1 day 15M ; Retry 2 hours 1W ; Expire 41.67 days 1D ) ; Minimum TTL 2 days @ IN NS ns1.maindomain.com. @ IN MX 10 ns1.maindomain.com. www IN CNAME ns1.maindomain.com.
domain2.com.fwd Contents
$ORIGIN domain2.com. $TTL 86400 @ IN SOA ns1.maindomain.com. root.maindomain.com. ( 20110930 ; Serial number 3H ; Refresh 1 day 15M ; Retry 2 hours 1W ; Expire 41.67 days 1D ) ; Minimum TTL 2 days @ IN NS ns1.maindomain.com. @ IN MX 10 ns1.maindomain.com. www IN CNAME ns1.maindomain.com.
Start Named Service
# service named start
Start named service on boot
# chkconfig named on
Install Apache Server
=================
# yum install httpd
# vi /etc/httpd/conf/httpd.conf
You need to add These Lines at the end of httpd.conf file
———————————————————————-
NameVirtualHost 192.168.0.220:80 ServerName www.domain1.com DocumentRoot /var/www/domain1/ ServerName www.domain2.com DocumentRoot /var/www/domain2/
Create these directories which we mention above
# mkdir -p /var/www/domain1 # mkdir -p /var/www/domain2 # touch /var/www/domain1/index.html # echo "welcome to Domain 1 " >> /var/www/domain1/index.html # touch /var/www/domain2/index.html # echo "welcome to Domain 2 " >> /var/www/domain2/index.html
Now browse www.domain1.com & www.domain2.com