1. Type in the terminal
vi /etc/sysconfig/network-scripts/ifcfg-eth0
The static ip template is as follows:
DEVICE="eth0" #NIC name BOOTPROTO="static" #Static IP (required) HWADDR="00:0C:29:B5:65:CA" #Network card mac address IPV6INIT="yes" NM_CONTROLLED="yes" ONBOOT="yes" #Automatically start at boot (required) TYPE="Ethernet" #Network type UUID="e7b6ffae-6614-4ad3-bc96-ba4d18a6559f" IPADDR="192.168.238.133" #IP address (required) NETMASK="255.255.255.0" #Subnet mask (required) GATEWAY="192.168.238.1" #Gateway (required) DNS1=xxxx #Domain name server address (depending on the situation)
There are required fields on it, they must be filled in, and the others can be left as default.
Restart network services. service network restart or /etc/init.d/network restart
Remark:
BOOTPROTO properties have types
- BOOTPROTO=static static IP
- BOOTPROTO=dhcp dynamic IP
- BOOTPROTO=none None (do not specify)
2. Dynamic IP configuration
The dynamic IP configuration template is as follows:
DEVICE="eth0" BOOTPROTO="dhcp" HWADDR="00:0C:29:C1:5A:74" ONBOOT="yes" TYPE="Ethernet" UUID="3c9a9469-ff5f-4d7d-96b4-bc8e48d4cb96"
Run the command: dhclient eth1
Obtain dynamic IP address automatically