69.Linux: Network configuration

table of Contents

1. The principle of NAT network configuration

2. Basic instructions for network configuration

(1) View the virtual network editor and modify the IP address

(2) View network IP and gateway

*1) View VMnet8 network configuration in windows environment

*2) View the network configuration in the linux environment

(3) Test network connectivity between hosts

Three, linux network environment configuration

Method 1: Obtain automatically

Method 2: Specify IP (recommended by programmers)

Four, network configuration commonly used instructions

(1) Set the host name

(2) Hosts mapping

*1) Set the mapping in windows

*2) Set up the mapping in linux

(3) Analysis of the host name resolution process

*1)Hosts

*2)DNS

*3) Analysis process


1. The principle of NAT network configuration

First of all, we must make it clear that there are the following things in our windows: linux virtual machine, vmnet8, wireless network card . They represent different ips.

Among them, the linux virtual machine and vmnet8 can communicate with each other (the firewall needs to be turned off), and vmnet8 can communicate with the wireless network card. The wireless network card will be connected to the outside network through the gateway.

 

Turn off the firewall method:

 

First look at our own linux virtual machine IP:

 

2. Basic instructions for network configuration

(1) View the virtual network editor and modify the IP address

Select "Virtual Network Editor" and click to change settings:

Select VMnet8, we can see that the subnet IP is 244, which is why our virtual machine IP is 192.168.244, followed by 130. Because he is from 128-254

3

 

(2) View network IP and gateway

*1) View VMnet8 network configuration in windows environment

ipconfig

win+r, then enter cmd, there will be a pop-up window, enter ipconfig

*2) View the network configuration in the linux environment

ifconfig

 

(3) Test network connectivity between hosts

ping 主机ip

 

Three, linux network environment configuration

Method 1: Obtain automatically

After logging in, the ip is automatically obtained through the interface settings.

Features: IP may be different each time, this is not recommended in work.

Method 2: Specify IP (recommended by programmers)

#编辑对应文件
vim /etc/sysconfig/network-scripts/ifcfg-ens33


#修改一些参数
BOOTPROTO=static


#在文件最后添加如下
#IP地址
IPADDR=192.168.200.130
#网关
GATEWAY=192.168.200.2
#域名解析器
DNS1=192.168.200.2

 

After we enter the above command, it will display as follows:

Then we click Settings, open the virtual network editor, and click Change Settings:

We choose WMnet8 and modify the subnet IP as follows. Click NAT settings again to change the gateway:

There are two ways to restart to make it take effect:

#方法一
reboot

#方法二
service network restart

After restarting, let's take a look at the ip, which is indeed what we set before:

 

Four, network configuration commonly used instructions

(1) Set the host name

#查看主机名
hostname

#修改文件再/etc/hostname指定

(2) Hosts mapping

For example, the ip of our linux virtual machine is 192.168.200.130, but it is too troublesome to remember the ip each time, we need to give him a name.

*1) Set the mapping in windows

Modify the C:\Windows\System32\drivers\etc\hosts file

Ping the virtual machine in windows:

*2) Set up the mapping in linux

Just modify the /etc/hosts file.

(3) Analysis of the host name resolution process

*1)Hosts

Hosts is a text file used to record the mapping between IP and HostName (host name)

*2)DNS

DNS: Domain Name System. It is a distributed database on the Internet as a mapping between domain names and IP addresses

*3) Analysis process

The browser first checks whether the domain name resolves the IP address in the browser cache , and if not, it checks the operating system DNS resolver cache .

If neither cache is found, check the hosts file in the system .

If none of the above, go to the domain name service DNS to resolve the domain name

#cmd中DNS域名解析缓存
ipconfig /displaydns

#手动清理dns缓存
ipconfig /flushdns

 

Guess you like

Origin blog.csdn.net/qq_40594696/article/details/114005637