Linux create intelligent DNS

Depending on the client source IP address, DNS resolution service provides different addresses

1, the installation dns service, modify the global configuration file /etc/named.conf

# yum -y install bind

# vim /etc/named.conf

acl beijingnet {                              simulate Beijing network segment
     192.168 . 1.0 / 24 ; 
}; 
ACL shanghainet {                              simulated network segment Shanghai
     10.10 . 10.0 / 24 ; 
}; 

Options { 
//       the listen-ON {Port 53 is 127.0.0.1;};    Zhushidiao this configuration: the IP address allows all machines can monitor port UDP53   //       the listen-ON-V6 {port 53 is ::. 1;};
 //       the allow-Query {localhost;};         Comment out this configuration, allows all ip to query dns
 @ omitted other .... 
}; 

// Zone {the IN "."                                Commented configured here, the move to /etc/named.rfc1912.zones.bj
 //       of the type hint;
 //       File "named.ca";
 // }; 

// the include "/etc/named.rfc1912.zones "; 

View view_beijing {                             enable Beijing network segment, matched to the file /etc/named.rfc1912.zones.bj 
    match - Clients {beijingnet;}; 
    the include " /etc/named.rfc1912.zones.bj " ; 
}; 
View view_shanghai {                            make Shanghai network segment, matched to the file /etc/named.rfc1912.zones.sh 
    match - Clients {shanghainet;}; 
    the include " /etc/named.rfc1912.zones.sh " ; 
};

 

2, Beijing and Shanghai to create regional profiles

Create a zone file in Beijing

# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.bj

# chown :named /etc/named.rfc1912.zones.bj

# vim /etc/named.rfc1912.zones.bj

//新增如下代码
zone "." IN {
        type hint;
        file "named.ca";
};
zone "ysu.com" {
    type master;
    file "ysu.com.zone.bj";
};

Create a profile Shanghai area

# cp /etc/named.rfc1912.zones /etc/named.rfc1912.zones.sh

# chown :named /etc/named.rfc1912.zones.sh

# vim /etc/named.rfc1912.zones.sh

//新增如下代码
zone "." IN {
        type hint;
        file "named.ca";
};
zone "ysu.com" {
    type master;
    file "ysu.com.zone.sh";
};

 

3, modify the zone database file

Create a regional database of Beijing

# touch /var/named/ysu.com.zone.bj

# chown :named /var/named/ysu.com.zone.bj

# chmod 640 /var/named/ysu.com.zone.bj

# vim /var/named/ysu.com.zone.bj

$TTL 86400
@       IN      SOA     ns1.ysu.com. admin.ysu.com. (
                        2018060601
                        1H
                        5M
                        7D
                        1D )
        IN      NS      ns1.ysu.com.
ns1.ysu.com.    IN      A       192.168.1.1
www.ysu.com.    IN      A       192.168.1.250

 

Create a regional database of Shanghai

# touch /var/named/ysu.com.zone.sh

# chown :named /var/named/ysu.com.zone.sh

# chmod 640 /var/named/ysu.com.zone.sh

# vim /var/named/ysu.com.zone.sh

$TTL 86400
@       IN      SOA     ns1.ysu.com. admin.ysu.com. (
                        2018060601
                        1H
                        5M
                        7D
                        1D )
        IN      NS      ns1.ysu.com.
ns1.ysu.com.    IN      A       10.10.10.1
www.ysu.com.    IN      A       10.10.10.250

 

4, start the DNS service

# systemctl start named

 

5, intelligent DNS test results

The two segments can be tested by a testing machine dig command

如: # you www.ysu.com @ 192.168.1.1

# You www.ysu.com @ 10.10.10.1

 

Guess you like

Origin www.cnblogs.com/ysuwangqiang/p/11749661.html