99. Config files
99.1. Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.define :precise1 do |t|
t.vm.box = "hashicorp/precise64"
t.vm.provider "virtualbox" do |prov|
prov.customize ["modifyvm", :id, "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet0" ]
end
t.vm.provision "shell", path: "./setup.precise1.sh"
end
config.vm.define :precise2 do |t|
t.vm.box = "hashicorp/precise64"
t.vm.provider "virtualbox" do |prov|
prov.customize ["modifyvm", :id, "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet2" ]
end
t.vm.provision "shell", path: "./setup.precise2.sh"
end
config.vm.define :precise3 do |t|
t.vm.box = "hashicorp/precise64"
t.vm.provider "virtualbox" do |prov|
prov.customize ["modifyvm", :id, "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet3" ]
end
t.vm.provision "shell", path: "./setup.precise3.sh"
end
config.vm.define :precise4 do |t|
t.vm.box = "hashicorp/precise64"
t.vm.provider "virtualbox" do |prov|
prov.customize ["modifyvm", :id, "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet4" ]
end
t.vm.provision "shell", path: "./setup.precise4.sh"
end
end
99.2. make_config.perl
#!/usr/bin/perl
$i_am=`hostname`; chomp $i_am;
$i_am_long=`hostname -f`;chomp $i_am_long;
$i_am_domain=`hostname -d`;chomp $i_am_domain;
$i_am_ip=`hostname -i`;chomp $i_am_ip;
($a,$b,$c,$d)=split('\.',$i_am_ip);
$subnet=sprintf("%03d.%03d.%03d",$a,$b,$c);
# Read the hosts-file for this named
$infile=@ARGV[0];
if ($i_am_domain eq ''){
$i_am_domain=$infile;
}
open (INFILE,"<$infile") || die "cannot open $infile ; did you supply a source file as argument? ";
@hosts=
close INFILE;
$qty=0;
$zns=0;
for (@hosts){
s/\#.*//;s/[ ]*$//;
if (/^$/){
print ' ';
}
else {
($h,$ip,$dhcp)=split;
print "\n$h,$ip =";
($a,$b,$c,$d)=split('\.',$ip);
@ip1[$qty]=$ip;
$zn=sprintf("%03d%03d%03d",$a,$b,$c);
print "$zn -";
$fl=0;
for ($i=0;$i<$zns;$i++){ if (@zones[$i] eq $zn) {$fl=1;}}
if ($fl==0){
@zones[$zns]=$zn;
@nw[$zns]="$c.$b.$a";
print "@nw[$zns]";
$zns++;
}
$h=~s/\..*//;
@hst[$qty]=$h;
@hw[$qty]=$dhcp;
$qty++;
}
}
open (NDCONF, ">named.conf.local") || die "cannot write named.conf.local";
print NDCONF "zone \"$i_am_domain.\" in { type master ; file \"/etc/bind/db.$i_am_domain\"; };\n";
for($i=0;$i<$zns;$i++){
print NDCONF "zone \"@nw[$i].in-addr.arpa\" in { type master; file \"/etc/bind/db.@zones[$i]\"; };\n";
}
close NDCONF;
open (DB,">db.$i_am_domain")|| die "cannot open db.$i_am_domain";
print DB "@ IN SOA $i_am_long. $i_am_long. (\n";
print DB " 1 ; serial\n";
print DB " 360000 ; refresh\n";
print DB " 3600 ; retry\n";
print DB " 960000 ; expire\n";
print DB " 36000 ; ttl\n";
print DB " )\n";
print DB " IN NS $i_am_long.\n";
for($i=0;$i<$qty;$i++){
print DB "@hst[$i] IN A @ip1[$i]\n";
}
close DB;
for ($i=0;$i<$zns;$i++){
open (DB,">db.@zones[$i]")|| die "cannot open db.@zones[$i]";
print DB '$TTL 604800';
print DB "\n@ IN SOA $i_am_ip $i_am_long. (\n";
print DB " 2 ; serial\n";
print DB " 360000 ; refresh\n";
print DB " 3600 ; retry\n";
print DB " 960000 ; expire\n";
print DB " 36000 ; ttl\n";
print DB " )\n";
print DB " IN NS $i_am_long.\n";
for($j=0;$j<$qty;$j++){
($a,$b,$c,$d)=split('\.',@ip1[$j]);
$zn=sprintf("%03d%03d%03d",$a,$b,$c);
if (@zones[$i] eq $zn) {
printf DB ("%-4d IN PTR @hst[$j].$i_am_domain.\n",$d);;
}
}
close DB;
}
print "\n";
system "pkill -HUP named";
99.3. R1
ip cef
!
interface Ethernet0/0
ip address 10.128.1.1 255.255.255.0
!
interface Ethernet0/1
ip address 10.128.2.1 255.255.255.0
!
interface Ethernet0/3
ip address 10.128.3.2 255.255.255.0
!
router rip
network 10.0.0.0
!
99.4. R2
ip cef
interface Ethernet0/0
ip address 10.128.5.1 255.255.255.0
interface Ethernet0/1
ip address 10.128.4.1 255.255.255.0
interface Ethernet0/2
ip address 10.128.6.1 255.255.255.0
interface Ethernet0/3
ip address 10.128.3.1 255.255.255.0
router rip
network 10.0.0.0
99.5. setup.precise1.sh
echo '*********************************************************'
echo '*********************************************************'
echo '*********************************************************'
echo '* Setup precise1 start *'
echo '*********************************************************'
echo '**************PROXY**************************************'
echo '*********************************************************'
# SHELL
function aptget {
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
$@
}
aptget -y update
aptget -y upgrade
ifconfig eth1 10.128.4.100 netmask 255.255.255.0 up
route add -net 10.128.0.0 netmask 255.255.0.0 gw 10.128.4.1
ifconfig
netstat -rn
aptget install -y squid
aptget install -y squid-deb-proxy
aptget install -y language-pack-en
cp /vagrant/squid.conf /etc/squid3/squid.conf
service squid3 restart
cat > /etc/resolv.conf <
search server
nameserver 10.128.6.100
EOF
99.6. setup.precise2.sh
echo '*********************************************************'
echo '*********************************************************'
echo '*********************************************************'
echo '* Setup precise2 start *'
echo '*********************************************************'
echo '***************DNS CLIENT********************************'
echo '*********************************************************'
# SHELL
function aptget {
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
$@
}
aptget -y update
aptget -y upgrade
ifconfig eth1 10.128.2.100 netmask 255.255.255.0 up
route add -net 10.128.0.0 netmask 255.255.0.0 gw 10.128.2.1
ifconfig
netstat -rn
echo '*********************************************************'
echo '* precise2: install bind *'
echo '*********************************************************'
aptget install bind9
aptget install dnsutils
cd /etc/bind
cp /vagrant/client /vagrant/make_config.perl .
perl make_config.perl client
/etc/init.d/bind9 restart
99.7. setup.precise3.sh
echo '*********************************************************'
echo '*********************************************************'
echo '*********************************************************'
echo '* Setup precise3 start *'
echo '*********************************************************'
echo '*************WEB SERVER**********************************'
echo '*********************************************************'
# SHELL
function aptget {
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
$@
}
aptget -y update
aptget -y upgrade
ifconfig eth1 10.128.5.100 netmask 255.255.255.0 up
route add -net 10.128.0.0 netmask 255.255.0.0 gw 10.128.5.1
ifconfig
netstat -rn
aptget install lighttpd
cat > /etc/resolv.conf <
search server
nameserver 10.128.6.100
EOF
99.8. setup.precise4.sh
echo '*********************************************************'
echo '*********************************************************'
echo '*********************************************************'
echo '* Setup precise4 start *'
echo '*********************************************************'
echo '**************DNS SERVER*********************************'
echo '*********************************************************'
# SHELL
function aptget {
DEBIAN_FRONTEND=noninteractive apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
$@
}
aptget -y update
aptget -y upgrade
ifconfig eth1 10.128.6.100 netmask 255.255.255.0 up
route add -net 10.128.0.0 netmask 255.255.0.0 gw 10.128.6.1
ifconfig
netstat -rn
echo '*********************************************************'
echo '* precise4: install bind *'
echo '*********************************************************'
aptget install bind9
aptget install dnsutils
cd /etc/bind
cp /vagrant/server /vagrant/make_config.perl .
perl make_config.perl server
/etc/init.d/bind9 restart
cat > /etc/resolv.conf <
search server
nameserver 10.128.6.100
EOF
99.9. client
gateway 10.128.1.1 win10 10.128.1.100 dnsgw 10.128.2.1 dns 10.128.2.100 proxy 10.128.4.100