Initial Configuration of CentOS 6.5

Initial Configuration of CentOS 6.5

Hello! In this article, I’ll be explaining about initial configuration steps for CentOS 6.5 system. You can learn about CentOS from here. These are the tasks we need to perform after our new CentOS server is installed and before the specific applications or software are installed. Without further adieu, let’s get into the setup process.

CentOS Logo

CentOS Networking Configuration

If you’re new to CentOS, you should know that all configuration files related to network interfaces are stored inside /etc/sysconfig/network-scripts/ directory. And the interfaces are named as ethx, eg. eth0, eth1, and so on. Also the configuration file for each interface has a prefix of “ifcfg-” added to the interface name. So, when you need to configure your network manually, open up and edit the configuration file for that specific interface. For example, if you’ve got only one interface attached to your server, your interface is more likely to be named as “eth0”. Therefore, you need to open up the configuration file named “ifcfg-eth0” from /etc/sysconfig/network-scripts/ directory.

To edit this file, you can use any text editor of your choice. My favorite is “vi” editor, so I’m using it here. You can use the editor you prefer. So, my command looks something like this:

[root@centos ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

By default, it is configured to use DHCP for acquiring network information. You can set static IP details as follows:

DEVICE=eth0
HWADDR=00:0C:29:F0:46:22
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.193
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.100

Let’s understand this configuration now. The “DEVICE=eth0” specifies that this configuration file is for “eth0” interface. This is same name we see when entering the command “ifconfig” or “ip link show“. The “HWADDR=00:0C:29:F0:46:22” represents the MAC address of that interface. If you don’t know what’s your NIC’s MAC address and don’t already have in your config file, simply remove this line. The “TYPE=Ethernet” tells the system that this is an Ethernet type device. You can have other options like Bridge, OVS, and so on, based on your topology.

In order to bring this interface up and running with defined config during system startup, add the option “ONBOOT=yes”. Otherwise, you would need to manually up this interface, which isn’t an ideal choice. Now comes the part, where we should provide information according to our custom needs and environment. Since our goal here is to set static IP information, provide “BOOTPROTO=static” which will allow the system to use the IP details provided in this config file rather than using dynamic IP resolution during boot period. Then, we need to provide the IP address, subnet mask, gateway address and name servers’ addresses to this interface. For the same purpose, I’m using “IPADDR=192.168.1.193” here to set its IP address as 192.168.1.193. My network’s subnet mask is /24, so I’m entering “NETMASK=255.255.255.0”. My network’s gateway address or router’s IP address is 192.168.1.1, so I entered “GATEWAY=192.168.1.1”. Similarly, my name server is hosted on IP 192.168.1.100, so I entered “DNS1=192.168.1.100”. If you’ve got multiple name servers, you can specify them as DNS2 and DNS3 respectively. Please enter these values according to your network setup.

After you’ve customized this network config file, you can save it and exit (in vi editor, use Esc followed by :wq and Enter). Then to implement this new configuration, you can restart the network daemon itself.

[root@centos ~]# service network restart

CentOS Hostname and Hosts

Now, let’s modify the hosts file to contain names for the machines we know. Here, we specify the  IP address of the machine or system and the name we would like to assign to it. Doing this enables us to use these names instead of the difficult to remember/use IP addresses. To do this, enter following command:

[root@centos ~]# vi /etc/hosts

By default, this file will look like this:

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

This config simply assigns the hostname  “localhost” to this system. Note that 127.0.0.1 is the loopback IPv4 address and ::1 is the loopback IPv6 address of any system. The “localhost.localdomain” represents the Fully Qualified Domain Name (FQDN) of the system. Now, we need to modify this file according to our needs.

First, let’s comment (adding # before line) or remove these lines completely. Then, let’s add new hosts like this:

127.0.0.1     localhost
::1                  localhost
192.168.1.193     mycentos       mycentos.sajjan.com.np
192.168.1.100    DC1         DC1.sajjan.com.np
192.168.1.107    support   support.sajjan.com.np

Here, the first two lines are similar to what we had earlier, except that I’ve made it shorter. Then, I’ve added another three hosts including their IP address, hostname and FQDN. In this case, mycentos is this system itself and sajjan.com.np is my domain name.

Now, let’s also change the hostname of this system. To do this, either modify the /etc/hostname file (if available) or /etc/sysconfig/network file. You can also use the hostname command and provide host’s name as an argument to it. Note that using hostname command will only change the host’s name for current runtime and will revert back once the system reboots.

[root@centos ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mycentos.sajjan.com.np

Doing this will set my system’s hostname as “mycentos.sajjan.com.np”. The next time we boot our system, we should be greeted with this hostname.

Installing Vmware Tools in CentOS (VMware Only)

Most of us nowadays use virtualization for both personal and enterprise use, and VMware is the most popular virtual platform. So, I’m going to install VMware tools in my CentOS machine here to enhance its performance. First, let’s login to the vsphere client and navigate to Inventory > Hosts and Clusters. Right click on the CentOS system in which we would like to install VMware tools. Then, go to Guest and click on Install/Upgrade VMware Tools. Doing this, will mount a CD-ROM containing VMware tools into the CentOS. Now, let’s login into the CentOS machine and perform following steps:

Mount the CD-ROM to the desired partition:

[root@mycentos ~]# mount /dev/cdrom /mnt

Extract the tarball file to the /tmp directory:

[root@mycentos ~]# cd /tmp
[root@mycentos tmp]# tar -xzvf /mnt/VMwareTools-9.0.0-782409.tar.gz

Install the tools:

[root@mycentos tmp]# cd vmware-tools-distrib/
[root@mycentos vmware-tools-distrib]# ./vmware-install.pl

Since, this install file “vmware-install.pl” is a Perl script, we must have Perl installed first in our system. To install perl, simply enter this command and then enter the above command to install VMware tools.

[root@mycentos vmware-tools-distrib]# yum -y install perl
[root@mycentos vmware-tools-distrib]# ./vmware-install.pl
[root@mycentos vmware-tools-distrib]# cd ~
[root@mycentos ~]# umount /dev/cdrom
[root@mycentos ~]# rm -rf /tmp/vmware-tools-distrib
[root@mycentos ~]# reboot

This will launch an interactive installation wizard to guide us through the installation of VMware tools. You can simply choose the default values (if you don’t have different requirement) and complete the installation. We can then reboot the system to implement changes to the system.

CentOS Remote Administration

Next, we can also perform SSH into our CentOS system using SSH clients like Putty for Windows or simply from terminal or console in Linux, Unix or Macintosh. By default, SSH daemon is started during the startup of CentOS 6.5 and Iptables firewall also allows SSH’s default port 22 for remote login. We can change the port for SSH by modifying its configuration file.

[root@mycentos ~]# vi /etc/ssh/sshd_config

In the configuration file, find the line containing “# Port 22“. Un-comment this line by deleting the “#” character and then change the value of 22 to another numeric value, which is your port of choice for SSH. For example, change it to “Port 2222“. To implement this change, restart the SSH daemon.

[root@mycentos ~]# service sshd restart

Now, if we try ssh to this system from another system using the new port, we won’t be able to access it. The main reason behind this is the presence of Iptables firewall in our CentOS system, which is currently configured to allow the port 22 but not port 2222. So, let’s allow the port 2222 in our Iptables.

[root@mycentos ~]# vi /etc/sysconfig/iptables

Within this file, find the Iptables statement which is permitting the access to port 22 and then, replace that statement to permit access to port 2222. By default, this statement looks like this:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT

And we need to modify this statement to become like this to allow port 2222:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 2222 -j ACCEPT

Restart Iptables to implement the change:

[root@mycentos ~]# service iptables restart

Now, we can SSH to our CentOS system remotely on port 2222 and perform remote administration from wherever in our network.

I hope you found it informative. Please let me know in the below Comments section if you’ve any question or suggestion for me.

Comments are closed.