Configure static IP addresses in Linux and set DNS and host names

Source: Internet
Author: User
Tags domain name server nameserver nslookup nslookup command

 

 

The configuration file is located:
/Etc/sysconfig/network-ScriptS/ifcfg-eth0
Device = eth0
Onboot = Yes
Bootproto = static
Ipaddr = 192.168.0.3
Netmask = 255.255.255.0
Gateway = 192.168.0.1

Make the IP address take effect:
/Sbin/ifdown eth0
/Sbin/IFUP eth0

Configure DNS resolution
Echo "nameserver 211.98.1.28">/etc/resolv. conf

Notify gateway to update information:
/Etc/init. d/network restart

① Introduction

DNS is the domain name system, which can convert a domain name such as www.21php.com to an IP address such as 211.152.50.35. If there is no DNS, When you browse the website 21php.com, you must use numbers that are so hard to remember as 211.152.50.35. The DNS server provides the DNS service. There are three types of DNS servers: cache-only server, primary name server, and second name server ).

The detailed principles, workflows, terms, and concepts of DNS are limited by space. Can read special articles such as DNS-HOWTO to learn.

② Configure the primary DNS Server

First, let's make the following assumptions: server a is the primary Domain Name Server of 21php.com, its IP address is 11.0.0.1, server B is the secondary Domain Name Server of 21php.com, and its IP address is 11.0.0.2;

Next we configure the primary DNS server 11.0.0.1 as 21php. com.

The DNS function in Linux is implemented through the BIND software. After the BIND software is installed, several inherent files are generated, which can be divided into two categories: configuration files under the/etc directory and DNS record files under the/var/named directory. Add other related files to set up the DNS server. The following is a list and description of all files related to DNS settings.

Hosts, host. conf, resolv. conf, named. boot, and named. conf are located in the/etc directory.

1. In the "hosts" file, the host name and IP address are defined, and the IP address and Host Name of the computer that will run DNS are also defined. Content:

127.0.0.1 localhost. localdomain localhost

2. "host. CONF file [Boban Note: originally written as hosts. conf], "Order hosts bind" Statement, specifying the resolution order for the host name is first found in hosts, and then found in the DNS server record. "Multi on" allows a host name to correspond to multiple IP addresses. Content:

Order hosts, bind

Multi on

Nospoof on

3. In the "resolv. conf" file, "nameserver 10.0.0.211" specifies the address of the DNS server. Note: This file is essential for computers that do not use DNS servers (non-Windows systems; Windows systems set this file in "Network Properties. If you have not set the local machine as a DNS server, you must specify the address of a DNS server to resolve the domain name. You can write up to three addresses as the candidate DNS server for the previous failure. "Domain zrs.com" specifies the default domain. File Content:

Domain 21php.com

Nameserver 11.0.0.1

4. The "named. Boot" file is the configuration file used by the BIND software of earlier versions. Now the new version has already been stored in "named. conf ". Named. conf is the core file of DNS server configuration. The following is a piece of explanation.

# Named. conf-configuration for bind

#

# Generated automatically by bindconf, alchemist et al.

Controls {

Inet 127.0.0.1 allow {localhost;} Keys {rndckey ;};

};

Include "/etc/rndc. Key"; Options {

Directory "/var/named /";

};

Zone "."{

Type hint;

File "named. ca ";

};

Zone "0.0.127.in-ADDR. Arpa "{

Type master;

File "0.0.127.in-ADDR. ARPA. Zone ";

};

Zone "localhost "{

Type master;

File "localhost. Zone ";

};

Zone "21php.com "{

Type master;

Optional Y yes;

File "21php.com ";

};

In the above Article, # Is the annotation symbol. The meanings of other lines are as follows:

Diretables/var/named

Specify that named reads DNS data files from the/var/named directory. You can specify and create this directory. All DNS data files are stored in this directory;

Zone "."{

Type hint;

File "named. ca ";

};

Specify named to obtain the top-level "root" server address of the Internet from the named. Ca file.

Zone "0.0.127.in-ADDR. Arpa "{

Type master;

File "0.0.127.in-ADDR. ARPA. Zone ";

};

Specify the named as the IP address range of 127.0.0 to the master server, named. the local file contains 127.0.0. * form of address-to-Domain Name conversion data (127.0.0 segment address is the internal loopback address of the LAN interface );

Zone "localhost "{

Type master;

File "localhost. Zone ";

};

The DNS file data containing localhost is stored in/var/named/localhost. Zone;

Zone "21php.com "{

Type master;

Optional Y yes;

File "21php.com. Zone ";

};

The preceding statement indicates that DNS data in the domain 21php.com is stored in 21php.com. Zone in the/var/named/directory;

You can use the text editor to open/var/named/21php.com. Zone. The content is as follows:

$ TTL 86400 @ in SOA @ root. localhost (

2; Serial

28800; refresh

7200; retry

604800; expire

86400; TTL

)

@ In NS localhost

WWW in a 11.0.0.233

Www2 in a 11.0.0.23

Forum in a 11.0.0.10

@ In MX 5 mail.21php.com.

The first part of the file is the corresponding parameter settings, this part does not need to be modified, and the subsequent part is the specific DNS data;

For example:

WWW in a 11.0.0.233

Resolve www.21php.com to 11.0.0.233;

Www2 in a 11.0.0.23

Resolve www2.21php.com to 11.0.0.23;

Club in a 11.0.0.10

Resolve club.21php.com to 11.0.0.10;

③ Configure the secondary DNS Server

Configure the server 11.0.0.2 as the 21php.com secondary DNS Server

The secondary DNS Server transfers a complete set of domain information from the primary server. Zone files are transferred from the master server and stored as local disk files on the secondary server. The secondary server has a complete copy of the domain information, so you can also query the domain. The configuration content of this part is as follows:

Zone "21php.com" in {

Type slave;

File "21php.com. Zone ";

Masters {11.0.0.1 ;};

};

As you can see, unlike the primary DNS server, "type" is changed to "slave", and then the address "Masters {11.0.0.1 ;};" of the primary DNS server is specified ;};". When the DNS service is started, it automatically connects 11.0.0.1, reads information about the 21php.com domain, and saves it to the 21php.com. Zone file on the local machine.

④ Test the DNS server

After modifying the corresponding DNS file, run the "NDC restart" command to restart the service. In Redhat 7.1 or a later version, run the following command:

/Etc/rc. d/init. d/named restart

Or

/Etc/rc. d/init. d/named reload

Make the change take effect.

To test DNS, you can find a client and set its DNS address to a new DNS server address. Then, try surfing the Internet, receiving emails, downloading emails, and so on. You can also run the NSLookup command: Run NSlookup, enter the host name to be queried, and check whether the correct IP address is returned. We recommend that you use the dig command in RedHat 7.1 or later versions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.