Network configuration after installing centOS on VM

1. Environment

 

Host: winXP SP2, home broadband, LAN connected to router , ip address is 192.168.1.101.

 

 

 

Virtual machine: centOS (open source free version of redhat linux), plain text mode.

 

 

 

After installing CentOS on the VM, it is found that there are two more network connections on the host: VMNet1 and VMNet8. Each network connection has an IP address and subnet mask.

 

VMNet1 is: 192.168.229.1/255.255.255.0

 

VMNet8 is: 192.168.30.1/255.255.255.0

 

 

 

2. Next, let centOS access the Internet.

 

To start, set the network connection in the VM to bridged. After starting centOS, execute the ifconfig command to find that the ip address of eth0 is set to the ip address of the same network segment as the host: 192.168.1.102. At the same time, I can connect to centOS using ssh, but I cannot ping the host on centOS, nor can I ping www.baidu.com. Looking at the configuration file, it is found that the router on centOS is the router of the host, and the dns is also the dns of the host.

 

 

 

In order to use the bridged method to surf the Internet, Baidu has collected a lot of information and tried to do it, but it is useless.

 

 

 

I had no choice but to change it to NAT. After restarting, I found that I could access the Internet. At the same time, I noticed that using ssh to connect to centOS seems to be faster.

 

 

 

After changing to NAT, run the ifconfig command to find that the ip address of centOS is the ip address 192.168.30.128 in the host VMnet8. And DNS has also become 192.168.30.2 under VMnet8.

 

 

 

According to the information on the Internet, the bridged way to access the Internet is directly connected to the physical network card of the machine. At this time, the centOS virtual machine is equivalent to a machine on the same local area network as the host. While using NAT to access the Internet, centOS and the host are in a client/server relationship. The host provides VMnet8 to centOS. For centOS, VMnet8 is equivalent to a gateway or router, and centOS is equivalent to a machine in the local area network that VMnet8 is responsible for.

 

 

 

Nat online process is as follows

 

 

 

1. The VMware network connection is selected in the NAT mode.

 

2. Check VMnet8 in the NAT item in VMware network settings, and the NAT gateway is set to 192.168.X.2.

 

3. In Windows , check all network connections, you should find that in addition to the original network card, there are more Vmnet1 and Vmnet8. vmnet1 is the hostonly interface, and Vmnet8 is the network interface of the NAT we want to apply.

 

4. Use ipconfig to view the IP address of VMnet8 on the Windows host, usually 192.168.X.1. At this time, the setting of VMnet8 should be AUTO to obtain IP, and now it is changed to static IP, and this IP is directly filled in VMnet8 without gateway.

 

 

 

5. Under linux, set the IP of the network card to the IP of the same network segment as VMnet8 (192.168.XY/255.255.255.0)

 

 

 

6. Set the hostname (open the /etc/sysconfig/network file with the vi editor)

 

 

 

set /etc/sysconfig/network

 

# vi /etc/sysconfig/network

 

NETWORKING=yes <==Whether to start the network, of course it is!

 

HOSTNAME=localhost <== hostname, be sure! You can modify it anytime!

 

GATEWAY=192.168.X.2

 

 

 

7. Set the network card parameters (open the /etc/sysconfig/network-scripts/ifcfg-eth0 file through the vi editor)

 

 

 

Set network card parameters /etc/sysconfig/network-scripts/ifcfg-eth0

 

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

 

DEVICE=eth0 <== Set the name of the device, this should correspond to the file name!

 

ONBOOT=yes <==Whether to start the network card at boot time

 

BOOTPROTO=dhcp <== The agreement obtained by IP at startup, static is fixed, if it is Cable, it needs to be changed to dhcp.

 

 

 

8. Set DNS (open /etc/resolv.conf file through vi editor)

 

 

 

[root@hostname root]# vi /etc/resolv.conf

 

 

 

vi /etc/resolv.conf

 

nameserver 192.168.X.2

 

 

 

9. Restart the network configuration  

 

 

 

[root@hostname root]# reboot //reboot

 

 

 

  [root@hostname root]# ifconfig //You can see that centos has been automatically assigned an ip of 192.168.XZ

 

 

 

service network restart //gateway restart    

 

 

 

10. Ping 192.168.x.1 under linux, and ping 192.168.xz under windows. After successful, it is confirmed that the host and the virtual machine can access each other. At this moment, the virtual machine can also share the host ip to access the Internet.
 
Execute service network restart and device eth0 does not seem to be present, delaying initialization solution
1、
vi  /etc/sysconfig/network-scripts/ ifcfg-eth0
The previous MAC address is saved in the configuration file of ifcfg-eth0, so delete this line before restarting the network card.

2、
Restart the machine after deleting /etc/udev/rules.d/70-persistent-net.rules
Because this file is bound to the network card and mac address, the MAC address has changed after changing the network card, so it cannot be started normally. You can also directly edit this configuration file to modify and multiply the network card and mac address correspondingly, but it is so troublesome. Directly delete and restart, it will automatically generate one.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326777226&siteId=291194637