L04-Linux CentOS7 network configuration (can be connected to the Internet), l04-linuxcentos7
Although the system demonstrated here is CentOS7, it is also applicable in RHEL6.5, RHEL7, and CentOS6.5.
1.Tool: virtualbox, virtual machine: CentOS7
2. VirtualBoxNetwork configuration in the tool
(1)VirtualBox settings: Manage --> global settings --> network --> only host (host-only)
Note:Because I want to build the network environment of OpenStack in this configuration, I have created another Nic Virtualbox Host-Only Ethernet Adapter.#2As the management network of openstack for communication and management among various services in openstack. If you only want to configure one Nic, you can directly use the original Host-Only network VirtualBox Host-Only Ethernet Adapter in Virtualbox.
The first ENI is set as follows:
The second ENI is set as follows:
The DHCP server option for both NICS is disabled.
(2) to connect to the Internet, share the local wireless Network to VirtualBox Host-Only Network (the first Network card)
(3) configure the NIC for the VM in VirtualBox:
Nic 1:
Nic 2:
Note that the MAC addresses of the two NICs are different. Remember them to help determine which Nic corresponds to which configuration file in the Next Step (ether in ifconfig command is followed by the MAC address ).
3.Network Configuration in Virtual Machine
(1) configuration of ifcfg-xxx File
Because the virtual machine is assigned two NICs in virtualbox, you can see two network configuration files ifcfg-xxx in the virtual machine.
The configuration of the two files is as follows:
Ifcfg-enp0s3(The MAC address indicates that it corresponds to the VirtualBox Host-Only Ethernet Adapter in Virtualbox):
Note: BOOTPROTO can also be set to static, so that the configured IP address is static.
Ifcfg-enp0s8:
(2) configure the/etc/resolv. conf file
Modify DNS and add a Domain Name Server to the/etc/resolv. conf file so that the virtual machine can connect to the Internet.
Nameserver 192.168.137.1
(3) restart the network: service network restart, and then use the ifconfig command to view
Note:Sometimes, even if the ifcfg-xxx file is configured correctly and the network is restarted using the service network restart command, the ifconfig command shows that the IP address is still not configured as desired, in this case, you can use the ifdown command (for example, ifdown enp0s3) to disable the NIC and enable it with the ifup command. If not, you need to go back and check whether the file is correctly configured.
4.Network test:
(1) ping yourself
Ping-c 4 10.0.0.11
Ping-c 4 192.168.137.110
Ping-c 4 controller(In the/etc/hosts file, you need to add the ip address to the host name ing)
(2) ping the Internet
(3) ping-c 4 8.8.8.8