Centos7/Ubuntu1604 network static configuration IP address process

Network configuration process (static configuration of IP address + realization of Internet access)

Experimental interpretation

  • Since it is necessary to realize that the virtual machine can access the Internet in a new virtual local area network, that is, not only the network segment where the virtual machine is located, when the virtual machine selects the network working mode, the bridged mode and the host-only mode cannot be selected. -Only) , we select the network address translation mode (NAT), by selecting this mode, the virtual machine automatically applies for a new network segment for the VMware platform;
  • When the virtual machine software platform chooses the NAT network working mode, we must choose the VMnet8 virtual switch on the virtual machine (working at the link layer and dividing the conflict domain), so the VMnet8 virtual switch is connected to multiple virtual machines on the one hand, and the other On the one hand, it connects the virtual NAT device and the virtual DHCP server; at the same time, this virtual switch is connected to the virtual network card VMnet8 on the local host. We can call the virtual network card VMnet8 to divide the broadcast domain;
  • The network segment where the virtual machine is located and the network segment where the local host is located are not in the same network segment in my selected NAT network mode
  • Since this experiment is to implement static configuration of the IP address, we must manually modify the network card configuration files under different virtual operating systems

Modify the virtual network editor

  1. Click "Virtual Machine -> Edit -> Virtual Network Editor -> Check whether the NAT mode is successfully connected. If there is no NAT mode, you need to manually add the VMnet8 network -> set the parameters under the "NAT Settings" information box (first enter the administrator authority Mode can be modified)
  2. Record the subnet IP as: 192.168.6.0, the subnet mask as 255.255.255.0, and the gateway IP address as 192.168.6.2. These parameters will be used later

Insert picture description here

Centos7 network configuration

  1. Modify the network mode under the virtual machine

Insert picture description here

  1. After configuring the network mode, start the system and execute the following commands

    a. Modify the network card configuration file

[root@ ~ 08:26:43]#vi /etc/sysconfig/network-scripts/ifcfg-ens33
    TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static" //修改这里
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no" 
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="d1545fa1-f413-44f6-8efa-f8f2390b9e20"
DEVICE="ens33"
IPADDR="192.168.6.128"  //添加IP地址
NETMASK="255.255.255.0" //添加子网掩码
GATEWAY="192.168.6.2"   //添加默认网关
DNS1="114.114.114.114"  //添加DNS
DNS2="233.5.5.5"
ONBOOT="yes"
//最后保存退出

b. Experimental results: restart the virtual machine network card -> view network card information -> ping external network ip -> success

[root@ ~ 08:32:59]#systemctl restart network
[root@ ~ 08:34:28]#ip ad sh
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:52:a9:d1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.128/24 brd 192.168.6.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::aa12:45ba:339d:3f87/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
[root@ ~ 08:34:43]#ping www.baidu.com
PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data.
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=128 time=9.63 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=128 time=10.7 ms
64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=3 ttl=128 time=10.3 ms
^Z
[3]+  Stopped                 ping www.baidu.com
[root@ ~ 08:34:51]#

Ubuntu 1604 network configuration

  1. Modify the network mode under the virtual machine, the steps are the same as above
    Insert picture description here

  2. After configuring the network mode, start the system and execute the following commands

    a. First open the terminal, enter the command to enter the file to start our configuration (after the configuration, remember to return to the vim extended mode "Esc" to save the modification record ":x!"/":wq!")

sudo vim /etc/network/interfaces
 # This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

   source /etc/network/interfaces.d/*

# The loopback network interface

   auto lo
   iface lo inet loopback

# The primary network interface

   auto ens33
   iface ens33 inet static
   address 192.168.6.143
   netmask 255.255.255.0
   gateway 192.168.6.2
   dns-nameserver 114.114.114.114                                                                           
   "/etc/network/interfaces" 16L, 403C  

c. Use the command to restart the network, and the configuration is successful after success. At this time, you can enter the command ping www.baidu.com to verify

   root@lin:/# sudo /etc/init.d/networking restart
   [ ok ] Restarting networking (via systemctl): networking.service.
   root@lin:/# ping www.baidu.com
   PING www.a.shifen.com (14.215.177.38) 56(84) bytes of data.
   64 bytes from 14.215.177.38: icmp_seq=1 ttl=128 time=10.6 ms
   64 bytes from 14.215.177.38: icmp_seq=2 ttl=128 time=9.45 ms
   64 bytes from 14.215.177.38: icmp_seq=3 ttl=128 time=9.11 ms
   64 bytes from 14.215.177.38: icmp_seq=4 ttl=128 time=8.86 ms
   ^C
   --- www.a.shifen.com ping statistics ---
   4 packets transmitted, 4 received, 0% packet loss, time 3006ms
   rtt min/avg/max/mdev = 8.866/9.526/10.670/0.695 ms
   root@lin:/# 

Problems encountered during operation

Restart the network card servie network restart error

  1. First, check whether the virtual machine network card is plugged into the host network card interface, and whether the network card logo in the lower right corner of the vmware virtual machine appears as green;
  2. If the green color is normal, that is, the network card access is correct, then you have to see if the network-manager service is running. This is another way to configure the network service. It is suitable for the graphical interface system. We use the command to close this The service can then reload the network card:
systemctl stop NetworkManager //暂时关闭
systemctl disable NetworkManager //永久关闭

The local LAN is pinged, but the external ping is different

  1. Check whether the ADDRESS/NETMASK/GATEWAY/DNS1 of the configuration file is written correctly, including whether the letters are spelled correctly; if the letters are written incorrectly, the relevant parameters will fail to read from the network card, then the network service cannot be used normally; because ADDRESS is written as other The IP address of the network segment cannot be communicated. The router has a routing table of its own, and will throw IP packets that are not in this network segment to a default gateway interface or an interface that is not in the network segment; whether it is written by the GATEWAY gateway Correct? ; Subnet mask?

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/107463137