Solve several methods for setting IP addresses in centos and Related Problems

Source: Internet
Author: User

Solve several methods for setting IP addresses in centos and Related Problems
Set a temporary IP Address

Ifconfig eth0 192.168.159.100 netmask 255.255.255.0
If the virtual machine is configured with a nat address, the corresponding Nic is vmnet8. Enter a command on the local machine to view the IP address of the VMnet8 Nic. In nat mode, your local computer is equivalent to a gateway. In the local machine, you can use cmd to view the VMnet8 IP address, which is actually equivalent to the gateway address of the virtual machine.

In the newly installed virtual machine, the system does not allocate the corresponding IP address. In this case, you need to manually assign an IP address. ifconfig eth0 192.168.159.100 netmask 255.255.255.0 temporary IP address, the IP address must be in the same LAN as the VMnet8 address.

However, ifconfig only sets a temporary ip address. When the system restarts, the ip address is invalid. In this case, another ip Address Setting method is required.

Modify the configuration file to set the IP address
Vi/etc/sysconfig/network-scripts/ifcfg-eth0 BOOTPROTO = "static" # dhcp changed to static ONBOOT = "yes" # enable the configuration of IPADDR = 192.168.159.100 # static ip gateway = 192.168.159.1 # default gateway NETMASK = 255.255.255.0 # subnet mask DNS1 = 192.168.159.1 # DNS configuration is not required
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

During static configuration, domain name resolution is sometimes not allowed. Even if you still cannot set the dns configuration parameters, You need to modify another configuration file,/etc/resolv. conf. Add the corresponding DNS server address after the file. The command is as follows:

Echo "nameserver 8.8.8.8">/etc/resolv. confvi/etc/sysconfig/network # to access this file, add the default GATEWAY = 192.168.159.1 # local GATEWAY address
  • 1
  • 2
  • 3
  • 4

After the above settings, you still cannot ping the Internet. At this time, you also need to modify the network adaptation and change it to the bridging mode (bridging: The Virtual Machine and the host are in the same network, equivalent to the equivalent, however, you can only have a maximum of 245 hosts in this lan. If you cannot add the bridging mode to the VM> edit, it may be because the Device install Service is not enabled. Go to the local machine and enable this Service. In the VM> Edit> VPC Editor, click Restore default settings to find the required bridging Nic. After the configuration is complete, ping the command on the local machine or virtual machine for testing. If it still fails, you need to disable the firewall settings. (The Bridge also needs to modify the Netework adaper mode, not automatic)

The above section describes how to change the connection mode to the Bridge Mode if you need to access the Internet when setting it as a static IP address. However, the limitations of the bridge mode can be imagined, it is not suitable for a large number of hosts. In this case, you still need to use the nat mode. Use dhcp to dynamically set IP addresses.

Set the static IP address to dynamic. Then modify the centos settings and change it to the nat mode.

When it is set to NAT, it usually does not fail. If it cannot be pinged, check the problem step by step.

1. Check the IP address of VMnet8 on the local machine. It is equivalent to the gateway of the virtual machine. If the virtual machine cannot ping the gateway, choose Virtual Machine> Edit> Virtual Network editor> NAT mode> Find the NAT settings to see if the gateway is wrong. Generally, when the gateway cannot be pinged, the gateway is faulty. 2. Firewall should be disabled due to firewall issues.

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.