Configuration of static Ip under centOS7.

Configuration of NAT static network card under centOS7

Recently, large data was built under cenOS7 and the need for centOS7 to configure static IPS was found.This post is about how to configure centOS7's static ip in a VM virtual machine.If there are any deficiencies, we also hope that like-minded people can correct and communicate, and make progress together.

1. Why configure a static ip address in centOS?

This is because the IP address in centOS in the vm changes without restarting. When the virtual machine's IP lease expires, the IP will be reassigned, causing the IP address to change itself.In order to apply convenience and fix the IP address, you need to set the centOS static ip, which is also the solid IP address.

Second, configure static ip in centOS in NAT mode

1. Set the network configuration of the vm virtual machine and set the network card to NAT mode
  • Set the network card type of the virtual machine to NAT mode

  • View virtual network card information in NAT mode.

    Subnet ip:192.168.192.0, or centOS, can be set between 192.168.192.0 and 192.168.192.255.
    Subnet mask: 255.255.255.0
    Gateway: 192.168.192.2      

These three are useful when configuring.In particular, the gateway must remember.

2. Set centOS's network adapter to NAT

After CentOS is installed, you can also view the type of network adapter by setting it up.Typically, they are specified at installation time.

3. Modify the configuration file

  • ifconfig view network card information:

  • View default network card information.

General network card information is in the ifcfg-ens33 file under the directory of / etc/sysconfig/network-scripts/
Use the command vi/etc/sysconfig/network-scripts/ifcfg-ens33
View the default network card information as follows:

 TYPE="Ethernet"   # Network Card Type: This defaults to Ethernet
 PROXY_METHOD="none"  # Agent mode
 BROWSER_ONLY="no"    
 BOOTPROTO="no"   # static ip
 DEFROUTE="yes"       # Default Route
 IPV4_FAILURE_FATAL="no"   # Turn on IPV4 fatal error detection: No
 IPV6INIT="yes"        # Is ipv6 initialized: Yes
 IPV6_AUTOCONF="yes" 
 IPV6_DEFROUTE="yes"
 IPV6_FAILURE_FATAL="no"
 IPV6_ADDR_GEN_MODE="stable-privacy"
 NAME="ens33"   #Network Card Physical Device Name
 UUID="b4af2f5f-f889-40d6-9058-2eff9f29539b"  # Universal Unique Identification Code for Network Card Information
 DEVICE="ens33"   # Network Card Device Name, Must Ha`NAME`Same
 ONBOOT=no      # Start or not, default:no

The default network card has so much information, in fact, we only need to configure the following information, other use the default.

Set Network Card Boot Protocol to Static

 BOOTPROTO=static

Set up the network card to start by starting up, and configure ip, subnet mask, gateway, domain name information as follows:

 ONBOOT="yes"       # Set to Start Up
 IPADDR=192.168.192.131  # ip address, must be on the same network segment as the host
 NETMASK=255.255.255.0   # Subnet Mask
 GATEWAY=192.168.192.2   # Gateway, where the gateway is the gateway to the virtual machine network card you set up in the first step
 DNS1=119.29.29.29       # Server address for domain name resolution, use ipconfig/all on windows to view the address of the local DNS server

Use ipconfig/all under window to view the address of the local DNS server:

The last configured network card information is as follows:

  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="b4af2f5f-f889-40d6-9058-2eff9f29539b"
  DEVICE="ens33"
  ONBOOT="yes"
  IPADDR=192.168.192.131
  NETMASK=255.255.255.0
  GATEWAY=192.168.192.2
  DNS1=119.29.29.29

4. Restart the network and verify that the static ip settings are successful.

  • Use the command systemctl restart network to restart the network, Ping other hosts within the network.My Ping is my host.

    [root@localhost /]# ping 10.4.60.28
    

  • Other hosts on ping extranet

    [root@localhost /]# ping baidu.com
    

The centOS static ip configuration is now complete.##

Tags: network CentOS DNS Windows

Posted on Sat, 27 Jun 2020 19:53:04 -0400 by mikeduke