After CentOS 7 is installed, use a static IP address to configure the network
Use a static IP address to configure the network
The first thing you need to do is configure static IP addresses, routes, and DNS for your CentOS server. We will use the ip command instead of the ifconfig command. Of course, the ifconfig command is still available for most Linux distributions and can be installed from the default library.
# Yum install net-tools [It provides ifconfig tool. If you are not familiar with ip commands, you can also use it]
For how to use the ip command, see: http://www.linux.cn/article-3631-1.html)
But as I said before, we will use ip commands to configure static IP addresses. Therefore, check the current IP address first.
# Ip addr show
Now open and edit the file/etc/sysconfig/network-scripts/ifcfg-enp0s3 in your editor (LCTT Note: Your Nic name may be different if you want to change to an older NIC name, refer: http://www.linux.cn/article-4045-1.html ). Here, I use the vi editor, and make sure that you are the root user to save the changes.
# Vi/etc/sysconfig/network-scripts/ifcfg-enp0s3
We will edit four parts in the file. Pay attention to the following four places and never touch anything else. Double quotation marks are also retained to input your data among them.
IPADDR = "[enter your static IP address here]"
GATEWAY = "[enter your default GATEWAY]"
DNS1 = "[your DNS 1]"
DNS2 = "[your DNS 2]"
After 'ifcfg-enp0s3' is changed, it looks like the image below. Note that your IP address, gateway, and DNS may change. Please confirm with your ISP (Internet Service Provider, that is, the telecom or IDC that provides you with the Access Service. Save and exit.
Network details
Restart the network service and check whether the IP address is the same as that allocated. If everything goes smoothly, use Ping to view the network status.
# Service network restart
Restart NETWORK SERVICE
After the network is restarted, check the IP address and network status.
# Ip addr show
# Ping-c4 google.com
Verify IP Address
Check Network Status
For more information about setting static IP addresses, see: http://www.linux.cn/article-3977-1.html)
3. Set the Host Name of the server
The next step is to change the Host Name of the CentOS server. View the name of the currently allocated host.
# Echo $ HOSTNAME
View system Host Name
To set a new host name, we need to edit the '/etc/hostsname' file and replace the old host name with the desired name.
# Vi/etc/hostname
Set host name in CentOS
After the host name is set, log out and log on again to confirm the host name. Check the new host name after logging on.
$ Echo $ HOSTNAME
Confirm Host Name
You can also run the 'hostname' command to view your current host name.
$ Hostname