Teach you the network configuration of Linux

Table of contents

network connection test

Test whether the Linux virtual machine is connected to the host

Test whether the host is connected to the virtual machine

network connection mode

bridge mode

NAT mode

host only mode

Modify static IP

Problems that may be encountered after changing the IP address

configure hostname


network connection test

Test whether the Linux virtual machine is connected to the host

First, you can open the command line by pressing the windows + R key to output cmd on the windows interface, and enter ipconfig 

You can query things related to network configuration

 copy this address

Then the virtual machine interface

1. Enter ping www.baidu.com

2. After a while, press ctrl + c to stop

3. Enter ping , and then enter the host IP just pasted (press ctrl + shift + c to copy in the virtual machine, and ctrl + shift + v to paste)

Test whether the host is connected to the virtual machine

Open the settings in the virtual machine, find the network, and click the small gear under the limited

 Then copy the IPv4 address

Enter ping + "the IP address you just copied" in the windows command line

 Success means there is no problem with the configuration


network connection mode

bridge mode

The mode in which the virtual machine is directly connected to the external physical network, and the host acts as a bridge. In this mode, the virtual machine can directly access the external network and is visible to the external network

In essence, the virtual machine here and the current PC are directly connected to the router, and everyone in the LAN can access the virtual machine built by themselves, and the built virtual machine will also occupy the same level of address IP as the PC side.

NAT mode

The virtual machine and the host build a private network and translate IP through the virtual machine network address translation (NAT) device. The virtual machine can access the external network through the shared host IP, but the external network cannot access the virtual machine.

The PC side accesses the virtual machine part through the network card

host only mode

The virtual machine only shares a private network with the host and cannot communicate with external networks

NAT mode is often used


Modify static IP

Open the virtual machine and find the editor above, click on the virtual network editor

 Then open the administrator settings, click on change settings

 Generally, the host remotely controls the virtual machines, and the IP addresses of all virtual machines should be set to static.

First open the terminal, enter vim /etc/sysconfig/net in the terminal and press the tab key

Find network-scripts , just enter it, and press the tab key

In this directory, see ifcfg-ens33 , enter, press Enter

 Enter normal mode after pressing Enter

Press 4 + shift + g   to adjust the cursor to the fourth line

Keep pressing the w key to adjust the cursor to the word dhcp

Press d+w to delete the word dhcp

Then press lowercase i to enter insert mode 

 In edit mode, add the following fields

 Pay attention to the content of this field, what the gateway is must be viewed through the NAT settings in the virtual network editor, and it needs to be consistent

Use the command mode to press   : wq to save and exit (if there is an exception, add a ! after q, and then press Enter)

Execute the restart service command  service network restart, press Enter to execute (if confirmed, it will succeed)

Then enter ifconfig and press Enter to find the IP of ens33 (as shown below)

 Copy this IP, and then enter ping "Copied IP" at the command line of windows

Problems that may be encountered after changing the IP address

(1) The physical machine can ping the virtual machine, but the virtual machine cannot ping the physical machine, usually because of the physical machine
Firewall problem, turn off the firewall on the line
(2) The virtual machine can ping the physical machine, but the virtual machine cannot ping the external network, usually because the DNS settings are incorrect.
question
(3) The virtual machine Ping www.baidu.com displays information such as unknown domain name, generally check the GATEWAY and DNS settings
Is the setting correct?
(4) If all the above settings are still not working, you need to close the NetworkManager service
systemctl stop NetworkManager shutdown
systemctl disable NetworkManager disable
(5) If there is a problem with systemctl status network, you need to check ifcfg-ens33


configure hostname

Enter hostname directly in the terminal to view the current hostname

The first modification method , if you want to modify, enter vim /etc/hostname    (note that there is a space between vim and etc)

After editing in the vim editor, remember: wq to save and exit (you need to restart the server to display after modification)

The second modification method is to enter hostnamectl set-hostname spark10  in the terminal , so that the input hostname can be directly displayed

Add host and mapping relationship (address book)

Terminal input vim /etc/hosts

Enter the desired mapping relationship (ie as follows)

 Copy these mapping relationships, save and exit

Go to the windows interface, open My Computer, go to C:\Windows\System32\drivers\etc, go to this directory, find the host file, open it with Notepad, paste the copied relationship (as shown below), because it cannot be directly modified below because windows10 and above , save as to the desktop, modify the suffix, delete the suffix txt, copy this file, then click to open the directory again, paste and select to replace this file

 Complete the above operations, check it, open the windows command, enter ping hadoop100, you can connect

Guess you like

Origin blog.csdn.net/qq_64691289/article/details/127316744