I Linux IP address configuration
Acquisition method - automatically acquire and specify IP
-
The first method: automatic acquisition
Note: after logging in, set automatic ip acquisition through system settings
Features: linux will automatically obtain ip after startup. The disadvantage is that the ip address automatically obtained 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" #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. To start the network card or control the network card through 'systemctl restart network', it must be set to 'yes'` IPADDR=192.168.200.184 # Native IP GATEWAY=192.168.200.2 #Subnet mask DNS1=192.168.200.2 #Default gateway ~ ~ "/etc/sysconfig/network-scripts/ifcfg-ens33" 18L, 376C 18,1 whole
II 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 and take effect
Modify host name:
[root@xiaoshun ~]# hostname xiaoshun [root@xiaoshun ~]# vim /etc/hostname CentOS ~ ~ "/etc/hostname" 1L, 7C 1,1 whole [root@xiaoshun ~]# reboot [root@CentOS ~]# hostname CentOS
2.2 setting hosts mapping
Question:
**How can I find it by hostname(such as ping) Some linux system?**
-
Windows :
Specify it in the C:\Windows\System32\drivers\etc\hosts file
-
Linux :
Specify in the / etc/hosts file
[root@CentOS ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.200.1 DESKTOP-BRRCQ9M ~ ~ 3,29 whole
2.3 host name resolution process analysis (hosts, DNS)
-
What are 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 entered in the browser www.baidu.com
- 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 the IP address to complete the resolution. These two caches can be understood as local parser caches
-
Generally speaking, after the computer successfully accesses a website for the first time, the browser or operating system will cache its IP address (DNS resolution record) within a certain period of time. For example:
Enter in the cmd window
ipconfig /displaydns // DNS domain name resolution cache
ipconfig /flushdns / / manually clean dns cache
-
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.
-
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
This article refers to the Linux video tutorial released by Han Shunping, the up Master of station B, in station B. thank you, Mr. Han Shunping;
This article is only for personal notes and will not involve any business activities.