How to set static IP in centos: First use the vi editor and press the insert key to insert; then enter the editing mode, move the cursor to the IPADDR setting part, and change it to the IP address that needs to be set; finally set it After that, just restart the network service.
How to set a static IP in centos:
1. Temporarily set the IP address
1. Take this machine as an example. The IP query above is 1.117. Enter ifconfig eth0 (the default is the first network card) followed by the IP address, network mask and gateway. If not set, use the default mask. Code
2. Check the IP again and it will become a new IP address
Note that this modification is only a temporary modification and will be restored after restarting the network card or server
2. Set [\] to modify the IP address
1. If you want the IP address to be permanent, you need to edit the network card configuration file
Use VI Editor
Settings, such as
vi /etc/sysconfig/network-scripts/ifcfg-eth0
Describe this file;
DEVICE=eth0 The device alias corresponding to the network card, such as ifcfg-eth0 The first network card BOOTPROTO=static network card How to obtain the ip address,
Static (static ip address)
dhcp (obtain ip through dhcp protocol)
bootip The ip address obtained through the bootp protocol BROADCAST=192.168.0.255 Subnet broadcast address HWADDR=00:50:56:8E:47:EE Network card physical address IPADDR=12.168.1.117
IPV6INIT=no Whether to enable IPV6IPV6_AUTOCONF=no NETMASK=255.255.255.0 The network mask corresponding to the network card NETWORK=192.168.1.0 The network address corresponding to the network card ONBOOT=yes Whether to set this network interface when the system starts, when set to yes , activate this device when the system starts. The default setting is yes
As for the following TYPE and UUID, you don’t need to worry about it. The class of this network card is
2. Use the vi editor and press the insert key to insert. Enter the editing mode
3. Move the cursor to the IPADDR setting part and change it to the IP address that needs to be set,
For example, change it to 1.118 in this example. Press the esc key.
Enter colon:wq
Save and exit
will prompt
"/etc/sysconfig/network-scripts/ifcfg-eth0" 14L, 302C written
4. After setting up, restart the network service, service network restart
Recommended related tutorials: centos tutorial
The above is the detailed content of How to set static IP in centos?. For more information, please follow other related articles on the PHP Chinese website!