Three methods for configuring IP addresses in CentOS 6.5

Source: Internet
Author: User

Three methods for configuring IP addresses in CentOS 6.5

Experimental software environment: Virtual Machine VMware Workstation10.0, CentOS 6.5 32-bit client Windows 7

1. automatically obtain the IP address
The virtual machine uses the bridge mode, which is equivalent to connecting to the network of the physical machine. The physical machine network has a DHCP server automatically assigned an IP address.
# Dhclient command for Automatically Obtaining IP addresses
# Nic information, IP address, and MAC address in the ifconfig Query System
 
After the IP address is assigned, ping the IP address on the physical machine to check whether the ping is successful.
 
2. manually set IP addresses
If the virtual machine cannot automatically obtain the IP address, you can only manually configure it as follows:
Enter the command
# Vi/etc/sysconfig/network-scripts/ifcfg-eth0

Edit the NIC configuration file

Enter the preceding command and press enter to open the configuration file. Use the arrow key to move the cursor to the last line. Press "O" to enter the editing mode. Enter the following content:
IPADDR = 192.168.4.10
NETMASK = 255.255.255.0
GATEWAY = 192.168.4.1
In addition, move the cursor to the line "ONBOOT = no" and change it to ONBOOT = yes.
"BOOTPROTO = dhcp", changed to BOOTPROTO = none
After that, press the ESC key in the upper left corner of the keyboard. Enter wq in the lower left corner of the screen and press enter to save the configuration file.

Restart the network service. The command is
# Service network restart

After the network is restarted, the ip address of eth0 takes effect. Run the command # ifconfigeth0 to view
Next, check whether the configured IP address can be pinged. On the physical machine, use the shortcut key WINDOWS + R to open the run box, enter the command cmd, and enter ping 192.168.4.10. ping indicates that the IP address is correctly configured.
 
Note: The network segment of my physical machine is 192.168.4.0. During the experiment, you can set up your own environment to keep the virtual machine and the physical machine in the same network segment.

3. Use NAT Mode
The Virtual Machine network connection uses the NAT mode, and the physical machine network connection uses vmnet8.

In virtual machine settings-network adapter, select NAT mode for network connection.
Choose VM menu bar-edit-Virtual Network editor and select Vmnet8 NAT mode,

1. Set the ip address to 192.168.20.0 subnet mask 255.255.255.0 in the bottom subnet.
2. In the NAT settings, the gateway IP address is 192.168.20.2.
3. Using the local DHCP service to allocate IP addresses to virtual machines is not checked

After the settings are complete, click the application to exit.


 
Physical Machine network connection VMNet8 manual setting IP address 192.168.20.1 subnet mask 255.255.255.0
The gateway and DNS address are 192.168.20.2 (that is, the gateway address of the Virtual Machine NAT)
 
Edit the configuration file of the linux Nic eth0
# Vi/etc/sysconfig/network-scripts/ifcfg-eth0

Enter the preceding command and press enter to open the configuration file. Use the arrow key to move the cursor to the last line. Press "O" to enter the editing mode. Enter the following content:
IPADDR = 192.168.20.3
NETMASK = 255.255.255.0
GATEWAY = 192.168.20.2
In addition, move the cursor to the line "ONBOOT = no" and change it to ONBOOT = yes.
"BOOTPROTO = dhcp", changed to BOOTPROTO = none
After that, press the ESC key in the upper left corner of the keyboard. Enter wq in the lower left corner of the screen and press enter to save the configuration file.
 
Set the DNS address and run the command
# Vi/etc/resolv. conf

Move the cursor to the blank line, press "O", enter nameserver 192.168.20.2, and Press ESC, and enter: wq press enter to save the configuration file.
Restart NETWORK SERVICE
# Service network restart

After restart
# Ifconfig

Check the configured IP address. ping the address on the physical machine to test whether the IP address can be accessed.

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.