Linux-centos the network configuration in the VM

Source: Internet
Author: User
Tags get ip

1. Get IP address automatically

Virtual machines use bridging mode, which is equivalent to a network connected to a physical machine, and the physical machine network has a DHCP server that automatically assigns IP addresses.

#dhclient Auto Get IP address command

#ifconfig Query System network card information, IP address, MAC address

After assigning to an IP address, ping the IP address with the physical machine and detect if it is ping.

2. Set IP manually Address

If the virtual machine does not acquire IP automatically, it can only be configured manually, as follows:

Input command

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

Edit the configuration file for the NIC

Enter the above command after entering, open the configuration file, use the arrow keys to move the cursor to the last line, press the letter key "O", enter the edit mode, input the following content:

ipaddr=192.168.4.10

netmask=255.255.255.0

gateway=192.168.4.1 dns1=202.102.154.3

In addition, the cursor moves to the line "Onboot=no" and changes to Onboot=yes

"Bootproto=dhcp", change to Bootproto=none

When you're done, press the ESC key in the upper-left corner of the keyboard, enter: Wq in the lower left of the screen, enter to save the configuration file.

The network service needs to be restarted after the command is

#service network restart

After the network restarts, the IP of eth0 is in effect, use the command #ifconfigeth0 to view

Next detects whether the configured IP can ping, in the physical machine using the shortcut key Windows+r Open the Run box, enter command cmd, enter ping 192.168.4.10 for detection, ping to explain the IP configuration is correct.

Note : My physical network segment is a 192.168.4.0 network segment. When you do the experiment according to your own environment to set, keep the virtual machine and physical machine in the same network segment can be.

3. using NAT Mode

The virtual Machine network connection uses NAT mode, and the physical Machine network connection uses VMNET8.

Virtual machine settings inside--Network adapter, network connection Select NAT mode.

Virtual Machine Menu Bar-edit-Virtual network editor, select Vmnet8 Nat mode,

1. On the bottom subnet, set the IP to 192.168.20.0 subnet mask 255.255.255.0

2. NAT setting inside Gateway IP is 192.168.20.2

3. Assigning IP addresses to virtual machines using the local DHCP service does not tick

Click Apply to exit when the settings are complete.

Physical machine network connection VMNET8 manually set the IP address 192.168.20.1 subnet mask 255.255.255.0

Gateway and DNS address 192.168.20.2(that is, gateway address for Virtual machine NAT)

Edit the configuration file for the Linux NIC Eth0

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

Enter the above command after entering, open the configuration file, use the arrow keys to move the cursor to the last line, press the letter key "O", enter the edit mode, input the following content:

ipaddr=192.168.20.3

netmask=255.255.255.0

gateway=192.168.20.2

In addition, the cursor moves to the line "Onboot=no" and changes to Onboot=yes

"Bootproto=dhcp", change to Bootproto=none

When you're done, press the ESC key in the upper-left corner of the keyboard, enter: Wq in the lower left of the screen, enter to save the configuration file.

Set DNS address, Run command

#vi /etc/resolv.conf

Move cursor to blank line, press "O" key, enter nameserver 192.168.20.2 Exit Press ESC, enter: WQ carriage return to save profile.

Restart Network Service

 #service network restart

After reboot

#ifconfig
Check the IP address of the configuration, the physical machine ping this address to test whether it can pass. my address office and home:Device=eth0hwaddr=00:0c:29:22:4f:91type=ethernetuuid=ee91f0cf-4ea5-4044-88d3-dac4f414aaf6onboot=yesnm_ Controlled=yesbootproto=none ipaddr=10.1.5.44netmask=255.0.0.0gateway=10.1.5.1dns1=202.102.154.3 IPADDR= 192.168.1.111netmask=255.255.255.0gateway=192.168.1.100dns1= 219.146.0.130

Linux-centos the network configuration in the VM

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.