Configuring Centos from scratch
This article describes the basic steps to set up a just-installed Centos Linux. As my focus is on software development and I am not constantly practicing server configuration, these steps are my reference where I can return to when I eventually forget it.
If your network was not configured on the installation, you’ll need to do it manually. You can configure it as DHCP or fixed IP. In both cases, you’ll have to change the files in
To test if your network is working (with the cable connected),
ping a well-known DNS server. Make sure that your network policy allows that.
This IP should be unreachable.
Go to the directory and list the files
cd /etc/sysconfig/network-scripts ls
You will find there a file called
ifcfg-eno1 that you have to edit. If you are using a virtual machine, this name can change. In my case it was
ifcfg-enp0s3. Edit this file with
To configure it to use DHCP, make sure the line BOOTPROTO is set to DHCP. Also, change ONBOOT to yes.
Here is my configuration:
service network restart to make the change take effect.
Now try pinging again.
The result should be something like this:
PING 18.104.22.168 (22.214.171.124): 56 data bytes 64 bytes from 126.96.36.199: icmp_seq=0 ttl=58 time=6.708 ms 64 bytes from 188.8.131.52: icmp_seq=1 ttl=58 time=6.901 ms 64 bytes from 184.108.40.206: icmp_seq=2 ttl=58 time=5.387 ms
^+C to stop pinging.
Similarly, you have to edit the same file for the DHCP configuration. But now you’ll set BOOTPROTO to static and that line will become
Also add the keys IPADDR, NETMASK and GATEWAY and the respective desired IP address, the network mask, and the gateway IP address. Make sure your IP will not conflict with the DHCP range, that in my network is reserved for the values between .2 and .200
The values that I used were:
IPADDR=192.168.1.201 NETMASK=255.255.255.0 GATEWAY=192.168.1.1
Additionally, you have to define the DNS server, since in a static configuration you have to define it.
The keys are DNS1 and DNS2 if a secondary DNS is needed. I used the google DNS servers and the values are:
Use the same procedure to restart the network and test the reachability as on the DNS example.
To see the current configuration, type
ip address or
ip a as a shortened form.
By default, the hostname is
localhost.localdomain after installation. You can change it to whatever makes sense for you. I’ll change it to ship1.
And it is located in the file
I have also to add the line
127.0.0.1 ship1 to the hosts file. To edit this file, type
This change requires a reboot. To reboot the system in the command line, type
shutdown -r now