Linux system configuration DNS server

  1. configure ip address

Use the vi command to edit the network card configuration file eth0 to modify the ip address:

The #vi command is an editing tool that comes with linux, similar to Notepad on windows. vi has three modes, which are command mode, input mode and bottom line command mode. When opening a file with vi, it is in the command mode. In the command mode, the keystrokes are regarded as commands by the vi editor. You can use i, o, aSwitch to the input mode, press the esc key in the input mode to switch to the command mode, enter the English colon ":" in the command mode to enter the bottom line command mode, you can use ":q" to exit the editor, ":w" to save, "wq" saves and exits the editor, "!" means mandatory execution (all command characters are English characters). 

After opening the ifcfg-eth0 network card configuration file with the vi command, it enters the command mode of the vi editor

Press a on the keyboard to enter the edit mode of vi

The meaning of the network card configuration file:

DEVICE=eth0 #Network card device name can be used ifconfig

BOOTPROTO= none       #Network configuration parameters, parameters can be none, static, dhcp (none and static are static ip, dhcp is dynamic ip)

ONBOOT= yes            # Whether to activate the network card

USERCTL=no #Whether non-root users are allowed to control the device

PEERDNS=no #Whether to allow the DNS obtained by DHCP to override the local DNS

TYPE=Ethernet #Network type, the default is Ethernet

IPADDR= 192.168.47.131              #ip address, modify the place where the ip address needs to be modified                   

NETMASK= 255.255.255.0                      #subnet mask

GATEWAY = 192.168.47.254                     #Gateway

NETWORK= 192.168.47.0                      #Network address, obtained by AND operation of ip address and subnet mask

BROADCAST= 192.168.47.255                #Host number is all 1 for broadcast address

To modify the ip, you only need to modify the parameters marked in yellow.

For example, configure the network card ip as 192.168.57.100, subnet mask: 255.255.255.0 (also can be said as a 24-bit subnet mask), gateway: 192.168.57.1

IPADDR= 192.168.57.100                   # When the subnet mask is 255.255.255.0, 192.168.57 is the network address, and 100 is the host number

If the subnet mask is 255.255.0.0, that is, 192.168 is the network address, 57.100 is the host number, network address + host number = ip address, generally the same network address can communicate

NETMASK= 255.255.255.0                       #The subnet mask is used to distinguish whether the ip address is the same network

GATEWAY= 192.168.57.1                     ​​#The gateway is the IP address leading to other networks

NETWORK= 192.168.57.0                        #The ip of the same network address can communicate, and the IP address is converted into binary and the subnet mask is obtained by AND operation.

                                                                 For example: 192.168.57.100 and 255.255.255.0

                                  1100 0000.1010 1000.0011 1001.0110 0100  and 1111 1111.1111 1111.1111 1111.0000 0000 get

                                 1100 0000.1010 1000.0011 1001.0000 0000  converted to decimal is 192.168.57.0

                                 (Tips: If the subnet mask is 24 bits, just change the last bit of the ip address to 0 for the network address, and change the last 2 bits to 0 for 16 bits)

BROADCAST=192.168.57.255

 After the modification, press the esc key to enter the command mode, and then press: wq to save and exit

After configuring the network card file, restart the network card to make the configuration take effect. First use ifdown eth0 to turn off the network card, then use ifup eth0 to start the network card (service network restart is also a command to restart the network card), and finally use ifconfig to check whether the ip address is configured successfully.

2. Configure DNS server

The DNS resolution function is completed by the bind program. The name of the bind program on Linux is named. The management configuration file of bind (that is, the dns service) is /etc/named.conf.

This configuration file mainly defines the file location where the domain name and IP address resolution rules are saved and the service type.

Requirement: Configure 192.168.57.100 as the DNS server, and add the following domain names:

dns.test.org    192.168.57.100

aaa.test.org    192.168.57.110

Modify the management configuration file /etc/named.conf of the dns service

Enter vi /etc/named.conf

The #vi command is an editing tool that comes with linux, similar to Notepad on windows. vi has three modes, which are command mode, input mode and bottom line command mode. When opening a file with vi, it is in the command mode. In the command mode, the keystrokes are regarded as commands by the vi editor. You can use i, o, aSwitch to the input mode, press the esc key in the input mode to switch to the command mode, enter the English colon ":" in the command mode to enter the bottom line command mode, you can use ":q" to exit the editor, ":w" to save, "wq" saves and exits the editor, "!" means mandatory execution (all command characters are English characters).

After opening the ifcfg-eth0 network card configuration file with the vi command, it enters the command mode of the vi editor

Press a on the keyboard to enter the edit mode of vi

The meaning of the network card configuration file:

DEVICE=eth0 #Network card device name can be used ifconfig

BOOTPROTO= none       #Network configuration parameters, parameters can be none, static, dhcp (none and static are static ip, dhcp is dynamic ip)

ONBOOT= yes            # Whether to activate the network card

USERCTL=no #Whether non-root users are allowed to control the device

PEERDNS=no #Whether to allow the DNS obtained by DHCP to override the local DNS

TYPE=Ethernet #Network type, the default is Ethernet

IPADDR= 192.168.47.131              #ip address, modify the place where the ip address needs to be modified                   

NETMASK= 255.255.255.0                      #subnet mask

GATEWAY = 192.168.47.254                     #Gateway

NETWORK= 192.168.47.0                      #Network address, obtained by AND operation of ip address and subnet mask

BROADCAST= 192.168.47.255                #Host number is all 1 for broadcast address

To modify the ip, you only need to modify the parameters marked in yellow.

For example, configure the network card ip as 192.168.57.100, subnet mask: 255.255.255.0 (also can be said as a 24-bit subnet mask), gateway: 192.168.57.1

IPADDR= 192.168.57.100                   # When the subnet mask is 255.255.255.0, 192.168.57 is the network address, and 100 is the host number

If the subnet mask is 255.255.0.0, that is, 192.168 is the network address, 57.100 is the host number, network address + host number = ip address, generally the same network address can communicate

NETMASK= 255.255.255.0                       #The subnet mask is used to distinguish whether the ip address is the same network

GATEWAY= 192.168.57.1                     ​​#The gateway is the IP address leading to other networks

NETWORK= 192.168.57.0                        #The ip of the same network address can communicate, and the IP address is converted into binary and the subnet mask is obtained by AND operation.

                                                                 For example: 192.168.57.100 and 255.255.255.0

                                  1100 0000.1010 1000.0011 1001.0110 0100  and 1111 1111.1111 1111.1111 1111.0000 0000 get

                                 1100 0000.1010 1000.0011 1001.0000 0000  converted to decimal is 192.168.57.0

                                 (Tips: If the subnet mask is 24 bits, just change the last bit of the ip address to 0 for the network address, and change the last 2 bits to 0 for 16 bits)

BROADCAST=192.168.57.255

After the modification, press the esc key to enter the command mode, and then press: wq to save and exit

After configuring the network card file, restart the network card to make the configuration take effect. First use ifdown eth0 to turn off the network card, then use ifup eth0 to start the network card (service network restart is also a command to restart the network card), and finally use ifconfig to check whether the ip address is configured successfully.

3. Configure DNS server

The DNS resolution function is completed by the bind program. The name of the bind program on Linux is named. The management configuration file of bind (that is, the dns service) is /etc/named.conf.

This configuration file mainly defines the file location where the domain name and IP address resolution rules are saved and the service type.

Requirement: Configure 192.168.57.100 as the DNS server, and add the following domain names:

dns.test.org    192.168.57.100

aaa.test.org    192.168.57.110

Modify the management configuration file /etc/named.conf of the dns service

Enter vi /etc/named.conf

The Named.conf file already has basic configuration parameters for reference. If there is no special requirement, it does not need to be modified. You only need to add the required forward proxy parameters and reverse proxy parameters later.

After the configuration is complete, press the esc key to enter the command mode and then press: wq to save and exit. In this way, the rules for domain name and ip address resolution are successfully configured. You can use the named-checkconf /etc/named.conf command to check the   configuration file 

If no result is returned, the configuration is correct

The next step is to configure the data configuration file. This parsing file is used to resolve the domain name into ip. The file name should be the same as the file field in the zone area in the above configuration file, and the default path is the directory field in the option.

Configure forward parsing:

Create test.org data files under /var/named/

First use cd to enter the /var/named path and use ls to view the files in this directory

The named.local file is a reverse-parsed data configuration file, which can be copied as a template and then modified.

cp -a The file to be copied, the file name after copying (-a is to give the source file permission and user group to the copied file)

After copying, use vi to edit the test.org file, and modify the file to the following form

vi test.org

it was like this

modified to the following form

After the modification is successful, save and exit, and use the named-checkzone command to test whether the configuration is successful.

Note: After modifying the configuration file, the named service must be restarted for the configuration to take effect

Next configure reverse parsing:

Copy named.local in the same way, and then modify it

Save and exit after the modification is complete, and use the named-checkzone command to test whether the configuration is successful

In this way, forward analysis and reverse analysis can be completed

Note: After modifying the configuration file, the named service must be restarted for the configuration to take effect

Start the dns service, use service named start to start the dns service (service named restart is to restart, stop is to close)

Note: After modifying the configuration file, the named service must be restarted for the configuration to take effect

test:

on linux:

Modify the dns configuration file /etc/resolv.conf

Delete all the content in the /etc/resolv.conf file (press dd twice in the vi command mode to delete a whole line), then enter the following content and save and exit

After the configuration is complete, use the host test

If you can get the normal domain name and ip address, you will be successful! 

Guess you like

Origin blog.csdn.net/weixin_46568591/article/details/125491862