How do you set a static IP address in CentOS?
Setting a static IP address on CentOS can be done by following these steps:
- Open the network configuration file.
- Type “sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0” in the terminal.
- Set BOOTPROTO to “static” to indicate the use of a static IP address.
- BOOTPROTO is set to static.
- Configure the IP address, subnet mask, gateway, and DNS server address.
- The IP address is 192.168.1.100, with a netmask of 255.255.255.0, gateway of 192.168.1.1, and DNS servers at 8.8.8.8 and 8.8.4.4.
- Save the file and then exit.
- Restart network services.
- Restart the network service with administrative privileges.
- Check if the IP address has been changed:
- Display the IP address of eth0.
Note: The “eth0” in the above steps is the network card name, which may vary depending on the actual situation. You can run the ifconfig command to view the correct network card name and replace it with “eth0” in step 2 and step 6.