(CentOS7)IP address configuration and host name and hosts mapping

1, Linux IP address configuration

Acquisition method - automatically acquire and specify IP

  • The first method: automatic acquisition

    • Note: after logging in, set the automatic acquisition of ip through system settings
    • Features: Linux will automatically obtain ip after startup. The disadvantage is that the ip address obtained automatically each time may be different
  • The second method: specify the ip address

    • Description: directly modify the configuration file to specify the IP and connect to the external network.
    • Set by editing the VI / etc / sysconfig / network scripts / ifcfg-ens33 file.
    • After editing, use service network restart or reboot to make the editing effective
    [root@CentOS ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
    TYPE="Ethernet"			# Network card type (usually Ethernet)
    PROXY_METHOD="none"		 # Agent mode: off
    BROWSER_ONLY="no"		# Browser only: no
    BOOTPROTO="static"	#Boot protocol of network card (static: static IP dhcp: dynamic IP none: not specified)
    DEFROUTE="yes"			#Default route
    IPV4_FAILURE_FATAL="no"		#Whether to enable IPV4 fatal error detection
    IPV6INIT="yes"		  #Whether IPV6 is automatically initialized: Yes
    IPV6_AUTOCONF="yes"    #Whether IPV6 is automatically configured: Yes
    IPV6_DEFROUTE="yes"    #Whether IPV6 can be the default route: Yes
    IPV6_FAILURE_FATAL="no"   #Whether to enable IPV6 fatal error detection
    IPV6_ADDR_GEN_MODE="stable-privacy"  #IPV6 address generation model
    NAME="ens33"			#Network card physical device name
    UUID="208cc1c8-bfdd-48f8-9567-9d50d12a8320" #Universal unique identification code. Each network card will have it and cannot be repeated. Otherwise, only one of the two linux machines can access the Internet
    DEVICE="ens33"  #The network card device NAME must be the same as the 'NAME' value
    ONBOOT="yes"	#Whether to start the network card. If you want to start the network card or control the network card through 'systemctl restart network', you must set it to 'yes'`
    IPADDR="192.168.5.130"	# Native IP
    GATEWAY="192.168.5.2" # gateway
    BROADCAST="192.168.0.255" # Subnet mask
    # DNS
    DNS1=114.114.114.114
    DNS2=8.8.8.8
    
    

2, Host name and hosts mapping

2.1 setting host name

(1) In order to facilitate memory, you can set the host name for the linux system or modify the host name as needed

(2) View hostname Directive: hostname

(3) Modify the file specified in / etc/hostname

(4) After modification, restart takes effect.

Modify host name:

[root@wlw102 ~]# hostname
wlw102
[root@wlw102 ~]# vim /etc/hostname
wlw102
~
~
"/etc/hostname" 1L, 7C       		  1,1    		    whole
[root@xiaoshun ~]# reboot
[root@CentOS ~]# hostname
wlw102

2.2 setting hosts mapping

Question: how can I find (for example, ping) a Linux system through the host name?

2.2.1,Windows :

Specify it in the C:\Windows\System32\drivers\etc\hosts file

192.168.5.129  wlw102
192.168.5.130  wlw103
192.168.5.131  wlw104

2.2.2,Linux :

Specify in the / etc/hosts file

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.5.129 wlw102
192.168.5.130 wlw103
192.168.5.131 wlw104
~                          

2.3 host name resolution process analysis (hosts, DNS)

What is hosts: a text file used to record the mapping relationship between IP and hostname

DNS :

  • DNS is the abbreviation of Domain Name System, which translates into Domain Name System.

  • It is a distributed database that maps domain names and IP addresses on the Internet.

Application example: the user enters www.baidu.com in the browser com

1. The browser first checks whether the domain name resolves the IP address in the browser cache. If so, call the IP first to complete the resolution; If not, check the DNS resolver cache. If yes, directly return to the IP address to complete the resolution. These two caches can be understood as local parser caches

2. Generally speaking, when a computer successfully accesses a website for the first time, the browser or operating system will cache its IP address (DNS resolution record) for a certain period of time. For example:

Enter in cmd window

ipconfig /displaydns // DNS domain name resolution cache

ipconfig /flushdns / / manually clean dns cache

3. If the local parser cache does not find the corresponding mapping, check whether the corresponding domain name IP mapping is configured in the hosts file in the system. If so, complete the parsing and return.

4. If the corresponding IP is not found in the local DNS resolver cache and the hosts file, go to the Domain Name Service DNS for resolution

Tags: Linux

Posted by Chezshire on Sun, 22 May 2022 05:09:10 +0300