Initial ip network configuration process after creating a new virtual machine under Linux system (centos system and ubuntu system)

Early preparation:

  1. Install the VMware virtual machine, the version here is VMware 16.
  2. System image to be installed:
  • CentOS-7-x86_64-DVD-2207-02.iso
  • ubuntu-20.04.5-desktop-amd64.iso
  1. Environment to be installed:
  • Virtual machine 1: centos 7.5, configuration ip: 192.168.79.102
  • Virtual machine 2: ubuntu 20.04, configuration ip: 192.168.79.110

foreword

Since virtual machines are often used to build various environments, here is a brief record of the virtual machine ip network configuration process.

First, the installation of the virtual machine

There are many tutorials on the installation of virtual machines on the Internet. Here we take the installation process of the Centos 7 system virtual machine as an example to briefly summarize:

  1. Open VMware and choose to create a new virtual machine.
  2. Choose a custom (advanced) installation method.
  3. Virtual machine hardware compatibility can be selected by default.
  4. Choose to install the system later.
  5. Select linux as the client operating system, and the version corresponds to the image version you downloaded (Centos 7 64-bit).
  6. Virtual machine name and installation location customization.
  7. The processor configuration is allocated according to the needs, such as (2x1) 2 cores are enough.
  8. The memory of the virtual machine can be 2048 as needed.
  9. Network connection select "Use Network Address Translation (NAT)".
  10. Select the recommended LSI Logic for the SCSI controller.
  11. Select the recommended SCSI for the virtual disk type.
  12. Select Create New Virtual Disk.
  13. 20GB is enough for the maximum disk size.
  14. The disk file can be selected by default.
  15. Click Finish to create the virtual machine.
  16. Don't rush to "Start this virtual machine", click "Edit virtual machine settings".
  17. Click "CD/DVD (IDE)" and choose to use the ISO image file (select the downloaded iso image file).
    insert image description here
  18. Other device configurations such as "memory", "processor", and "network adapter" can be "started" after checking that there is no problem, and the virtual machine will start to install.
  19. Language selection Chinese – Simplified Chinese.
  20. There is a red exclamation mark in the installation location, double-click to enter and click Finish.
  21. User settings Here, set the root password (such as root/root), and you can not set it when creating a user.
  22. Wait for the installation to complete and restart.
    insert image description here

The installation process of the virtual machine of the ubuntu system is similar. In the fifth step, the ubuntu 64-bit version is selected, and the rest will not be repeated.

2. Virtual network editor configuration

After the installation of the virtual machine is completed, there is no rush to configure the ip. You must first understand some basic network information of the machine.

VMware has three network working modes: Bridged (bridge mode), NAT (network address translation mode), and Host-Only (host-only mode). For a detailed understanding of this content, refer to the blog: Detailed vmware virtual machine network configuration
The configuration of the virtual network editor is as follows:

  1. VMware select Edit – Virtual Network Editor.
    insert image description here
  2. There are two network cards VMnet1 and VMnet8 in the virtual network editor. In the network mode of the previous virtual machine, we chose the NAT mode, so here we only focus on the VMnet8 network card. Click Change Settings in the lower right corner.
    insert image description here
  3. Now that the virtual network is editable, select VMnet8.
    insert image description here
  4. Click to view NAT settings, do not make changes here, just press the default, pay attention to the default gateway (for example, the default gateway here is: 192.168.79.2)
    insert image description here
  5. Click to view the DHCP settings, you can change the starting IP address to start from 1 (the original is 128, you can also use the default), that is, all the virtual machines that need to be configured only need to use the NAT network mode, when setting the IP, the range of the IP Must be between 192.168.79.1~192.168.79.254.
    insert image description here
  6. After the configuration is complete, click "Apply" and then "OK" to complete the configuration. It is also possible to completely follow VMware's default without making changes. The above are just some ideas for changes.

Through the above operations, the main goal is to get some information about the virtual machine to be configured, such as virtual machine ip range, subnet mask, gateway

focus value
IP range 192.168.79.1~192.168.79.254
subnet mask 255.255.255.0
gateway 192.168.79.2

3. Centos system ip network configuration

3.1 Edit network configuration file

  1. After logging in, obtain administrator privileges and operate with root privileges.
  2. Enter the network configuration folder and view the network configuration files under the current folder:
cd /etc/sysconfig/network-scripts/
ls

insert image description here
3. The network configuration file under the Centos 7.5 system is ifcfg-ens33. Edit the file, the content includes: set as a static proxy, ip address (customized within the IP range), gateway (the gateway address in the VMnet8 network card), dns address (just set the commonly used one).

##修改
BOOTPROTO=static
ONBOOT=yes

##增加
IPADDR=192.168.79.102
NETMASK=255.255.255.0
GATEWAY=192.168.79.2
DNS1=114.114.114.114
DNS2=8.8.8.8

insert image description here

3.2 Restart the network service.

systemctl restart network

Because the firewall may affect network connectivity, turn off the firewall:

#关闭防火墙
systemctl stop firewalld
#设置禁止开机自启
systemctl disable firewalld
#查看防火墙状态
systemctl status firewalld

It is recommended to also turn off selinux, and set selinux=disabled in the /etc/selinux/config file.

3.3 Verify network connectivity.

#查看本机ip是否生效 
ip a     
#查看dns是否生效
ping www.baidu.com 

insert image description here
At this point, use the remote connection tool to directly connect to this virtual machine, and the Centos ip network configuration has been completed.

Four, Ubuntu system ip network configuration

4.1 Initial operation

  1. Su root found that administrator privileges cannot be obtained. Solution: the password must be updated before the authentication succeeds.
sudo passwd
su root

insert image description here
2. It is found that the file cannot be edited. Solution: first download the document editing tool vim, and then authorize the file to be edited.

apt -y install vim	
进入文件所在目录:chmod 777 *
或者:chmod 777 * + 文件目录位置

insert image description here

4.2 Network configuration

4.2.1 Edit network configuration file

  1. First execute the command ip a to view the network information of the virtual machine. For example, the IP must be 127.0.0.1, so you need to modify it to your own needs, and check the network card type, because the following configuration is required, and the network card here is ens33.
  2. Note: The network configuration file in ubuntu 20.04 is 01-network-manager-all.yaml
vi /etc/netplan/01-network-manager-all.yaml
  1. Edit the network configuration file, the content includes: network card (ens33), ip address (customized within the IP range), set as a static proxy, gateway address (the gateway address in the VMnet8 network card), dns address (just set the commonly used one) .
network:
    ethernets:
      ens33:
        addresses:
        - 192.168.79.110/24
        dhcp4: no
        optional: true
        gateway4: 192.168.79.2
        nameservers:
          addresses:
          - 114.114.114.114
    version: 2
    renderer: NetworkManager

insert image description here

4.2.2 Make the configuration take effect and restart the network.

#使配置生效
netplan apply 
#重启网络
service network-manager restart

insert image description here

4.2.3 Verify network connectivity.

#查看本机ip是否生效 
ip a     
#查看dns是否生效
ping www.baidu.com 

insert image description here

4.3 Remote connection

  1. Install the ssh connection tool.
apt-get -y install openssh-server
  1. After installation, the tool starts automatically, check the ssh status:
systemctl status ssh

insert image description here

If disabled, start it manually, command: /etc/init.d/ssh start

  1. Connect to this virtual machine directly with the remote connection tool, and the Ubuntu ip network configuration is complete.

If you can’t connect, allow remote connection, and make the following settings:
1. Modify the file: vi /etc/ssh/sshd_config; modify the file: PermitRootLogin yes
2. Restart ssh: service sshd restart
3. Expand: ssh service enablement and disabled.
systemctl disable --now ssh # disable service
systemctl enable --now ssh # enable service

Guess you like

Origin blog.csdn.net/qq_44214446/article/details/128285892