Software configuration: vmware, openeuler 21.03 (other linux systems)
1. Bridging mode
This is equivalent to creating a separate host in a LAN. It can access all hosts in the LAN, but it needs to manually configure the IP address and subnet mask, and it is in the same network segment as the real host (nat is two network segments). In this mode, the virtual machine and the host can ping each other.
During specific configuration, set the ip address of linux to the same network segment and different ip host number as the local machine, and configure other subnet masks, gateways and DNS to be the same as the host.
The root account must be used during network configuration, otherwise it cannot be changed. So I log in directly with my root account.
- Virtual machine network adapter settings: select bridge mode
2. Local machine IP address viewing (two methods)
- Enter the windows operation command port, enter cmd to pop up the control terminal, and enter ipconfig. My computer is connected to wifi, so the address here is the IP address of wifi.
2. Open the network and inter options, change the adapter options, select WLAN, right-click to view the status, and click Details.
3. Network profile settings
1) Enter the network profile directory. The files in this directory are network configuration files
cd /etc/sysconfig/network-scripts
2) Edit network profile
vi ifcfg-ens33
The contents in the following box are the same as the local machine except that the IP address and host number are different from the local machine.
3) Save and modify the network configuration file and restart the network card service. root privileges are required
systemctl restart NetworkManager
4) ifconfig: check whether the IP address of the virtual machine is modified. (if you find that the data from ifconfig has not been changed, but the network configuration file has been changed, you can restart the system and try ifconfig again.)
changai001@ubuntu:~$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0c:29:6a:7d:8f inet addr:192.168.0.117 Bcast:192.168.1.255 Mask:255.255.254.0 inet6 addr: fe80::20c:29ff:fe6a:7d8f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:332550 errors:1 dropped:27 overruns:0 frame:0 TX packets:3937 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:22376612 (22.3 MB) TX bytes:676681 (676.6 KB) Interrupt:19 Base address:0x2000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:2190 errors:0 dropped:0 overruns:0 frame:0 TX packets:2190 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:157443 (157.4 KB) TX bytes:157443 (157.4 KB)
Confirm that it has been modified, ping Baidu Com to see if there is data return. If there is data return, it indicates that the network configuration is successful, and ctrc+c exits ping
5) if ping the domain name: Name or service not known
[root@localhost desktop]# ping baidu.com ping: baidu.com: Unknown name or service
Modify DNS service configuration
[root@localhost desktop]# vi /etc/resolv.conf
Change the DNS address in the figure below to the DNS server address of the local machine
After modification, there is no need to restart anything. do it again.
2.NAT mode
Using NAT mode is to let the virtual system access the public network through the network where the host computer is located with the help of NAT function. In this mode, the host becomes a dual network card host and participates in the existing host LAN and the new virtual LAN at the same time. However, due to the addition of a virtual NAT server, the virtual machines in the virtual LAN use the IP address of the host when accessing the outside. In this way, from the external network, you can only see the host, You can't see the new virtual LAN at all. (the DNS access domain name of the local machine is used externally, so you don't need to set the DNS address of the virtual machine)
1. Switch the network adapter to Nat mode first
2. Open the virtual network editor for the virtual machine in edit
Select VMnet8 - > Click NAT settings} and record the IP address, subnet mask and gateway set by Nat
3. Network profile settings
1) Enter the network profile directory. The files in this directory are network configuration files
cd /etc/sysconfig/network-scripts
2) Edit network profile
vi ifcfg-ens33
The IP address is set to the same network segment and different IP host number of the IP address of the virtual machine recorded at the beginning. Other subnet masks, gateways and DNS are configured to be the same as that recorded at the beginning. (DNS may not be set or managed)
3) Save and modify the network configuration file and restart the network card service. root permission is required (I checked this instruction online and found it useless)
systemctl restart NetworkManager
4) ifconfig: check whether the IP address of the virtual machine is modified. (if you find that the data from ifconfig has not been changed, but the network configuration file has been changed, you can reboot # restart the system and try ifconfig again.)
Finally, like the bridge mode above, ping the domain name to see if it can succeed.