1. Edit the NIC file
vi /etc/sysconfig/network-scripts/ifcfg-eth0 # eth0 for network card number
To set the IPV4 information for the NIC Eth0, it is important to note that the ipaddr set up needs to be in the same network segment as the other machines in the LAN. The following settings are required:
device=Eth0bootprot=staticipaddr=192.168. 1.27 GATEWAY=192.168. 1.1 NETMASK=255.255. 255.0 onboot=yes
Example description of NIC file contents:
Device=eth0//indicate the device nameBootprot=static//Startup Type Dhcp|staticbroadcast=192.168.1.203 //Broadcast AddressHwaddr=xx: .: 5b:fe:df:7c//Hardware MAC AddressIpaddr=192.168.0.2 //IP Addressnetmask=255.255.255.0 //Subnet Masknetwork=192.168.0.0 //Network Addressgateway=192.168.0.1 //Gateway addressOnboot=yes//whether to launch the appType=ethernet//Network Type
2. Restart the network card
Service Network restart
When you restart the network card, the shell may have information about reconfiguring the IP that appears in the shell.
3. Test whether the configuration is successful by pinging the IP of other hosts in the LAN
Ping 192.168. 1.10
Note: If you are configuring in VirtualBox, you need to change the connection mode in the Network tab to bridging.
CentOS Set Static IP