Saturday, December 23, 2017

Networking Bonding in RHEL/CentOS 7: Combining multiple NICs into one

Networking Bonding in RHEL/CentOS 7: Combining multiple NICs into one

When hosting a successful & busy websites or operating a critical server, high availability & redundancy are major factors to consider. To achieve high availability & redundancy, backup of the server & server clusters are prepared. One other thing that is used for HA/redundancy is Network Bonding.

Network Bonding refers to combining of more than one NIC into a single NIC for the purpose of HA/redundancy or load balancing. When network bonding is achieved and one of the NICs fail, the load will be transferred to next NIC in the bonding or we can even also configure it for load balancing.
In this tutorial, we are going to create network bonding for two interfaces on RHEL/CentOS 7 servers.

Installation

To create a network bond between NICs, we will require bonding module. To load the bonding module into the system, run
$ modprobe bonding
Once the module has been loaded, we will create a file for bonding interface ‘ifcfg-bind0’ in ‘/etc/sysconfig/network-scripts’ directory.

Configuring Bond interface

Goto ‘/etc/sysconfig/network-scripts’ & create bond file with following content,
$ cd /etc/sysconfig/network-scripts
$ vi ifcfg-bond0
DEVICE=bond0
TYPE=Bond
NAME=bond0
BONDING_MASTER=yes
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.0.100
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
BONDING_OPTS=”mode=5 miimon=100″
Here, mode=5 means network bond will provide fault tolerance & load balancing as well. Details of all available modes for network bonding are mentioned below,
mode=0 (Balance Round Robin)— round-robin mode for fault tolerance and load balancing.
mode=1 (Active backup)— Sets active-backup mode for fault tolerance.
mode=2 (Balance XOR)— Sets an XOR (exclusive-or) mode for fault tolerance and load balancing.
mode=3 (Broadcast)— Sets a broadcast mode for fault tolerance. All transmissions are sent on all slave interfaces.
mode=4 (802.3ad)— Sets an IEEE 802.3ad dynamic link aggregation mode. Creates aggregation groups that share the same speed & duplex settings.
mode=5 (Balance TLB)— Sets a Transmit Load Balancing (TLB) mode for fault tolerance & load balancing.
mode=6 (Balance ALB)— Sets an Active Load Balancing (ALB) mode for fault tolerance & load balancing.
Next step is to configure network interfaces i.e. ifcfg-en0s3 &en0s5 , for the bonding.

Configuring network interfaces

Make changes to the both interfaces file & add parameters “MASTER” & “SLAVE” to it, so that it looks like,
TYPE=Ethernet
BOOTPROTO=none
DEVICE=enp0s3
ONBOOT=yes
HWADDR=”23:03:56:bh:56:9g”
MASTER=bond0
SLAVE=yes
Save both files & restart the networking services on the system,
$ systemctl restart network
We can now run ‘ifconfig’ command to verify our newly created bonding interface or we can also check the bonding by running the following,
$ cat /proc/net/bonding/bond0
This will provide complete information about bonding interface.

Testing fault tolerance

To test if the network bonding is working or not, bring one of the network interfaces down. To do so, run
$ ifdown en0s3
& verify by making a http or ssh request to the server via the bonding interface IP address, network should be working just fine. Further we can also check which interface is working & which is down by running the above command i.e
$ cat /proc/net/bonding/bond0

This concludes our tutorial on network bonding. 

Wednesday, December 13, 2017

Router/Proxy/Gateway: Turning a CentOS/RHEL 6 or 7 machine into a router

Turning a CentOS/RHEL 6 or 7 machine into a Router


In this tutorial we are going to learn to convert RHEL/CentOS 6 & 7 machines into a router by using NATting. Router as we know is layer 3 networking device that is used to connect 2 or more networks i.e. either connecting LAN to WAN or LAN to LAN etc. Router devices are quite expensive & especially for small organizations, that might be a reason for concern. So rather than using a dedicated Hardware, we can use any Linux machine & convert it into a router.
We will be discussing process for both RHEL/CentOS 6 & 7. But before we do that, let’s discuss the things we will be needing for our setup.

Prerequisite

1- A machine with either RHEL/CentOS 6 or 7 installed
2- Two NICs to assign local IP address & WAN IP address respectively
We must assign IP address to both network interface cards, one IP should be for local area network (information regarding it will be provided by our Network administrator) & other IP should be to access internet, information for WAN IP will be provided by ISP. For example
Ifcfg-en0s3 192.168.1.1                (LAN IP address)
Ifcfg-en0s5 10.1.1.1                        (WAN IP address)
Note– Change the interface name according to Linux distro being used.
Now that we have what we need, we will move onto the setup

Step 1 Enabling IP forwarding

Firstly we will enable IP forwarding on the machine. Process of doing same is same in both RHEL/CentOS 6 & 7. To enable IP forwarding, run
$ sysctl -w net.ipv4.ip_forward=1
But this will not persist on system reboot. To make it survive a system reboot, open
$ vi /etc/sysctl.conf
& enter the following to the file,
net.ipv4.ip_forward = 1
Save file & exit. IP forwarding has now been enabled on the system.

Step 2 Configuring IPtables/Firewalld rules

Next we need to start services of IPtables/firewalld on our systems to configure the NATting rule,
$ systemctl start firewalld              (For Centos/RHEL 7)
$ service iptables start                     (For Centos/RHEL 6)
Next step is to configure the NATting rule on the firewall. Run the following command,
CentOS/RHEL 6
$ iptables -t nat -A POSTROUTING -o XXXX -j MASQUERADE
$ service iptables restart 

CentOS/RHEL 7
$ firewall-cmd –permanent –direct –passthrough ipv4 -t nat -I POSTROUTING -o XXXX -j MASQUERADE -s 192.168.1.0/24
$ systemctl restart firewalld
Here, XXXX is the name of the network interface with the WAN IP address. This completes configuration of Linux machine as router, next we will test our router after configuring a client machine.

Step 3 Configuring the client machine

To test the router, we need to assign the internal (LAN) IP address as gateway on our client machine, its 192.168.1.1 in our case. So whether using a Windows machine or linux machine as client, make sure that we have 192.168.1.1 as our gateway. Once that’s done, open terminal/CMD run a ping test against a website to make sure that internet is accessible on client machine,
$ ping google.com
We can also check by browsing websites via our web browser.

Saturday, December 9, 2017

Offline Package : Camicri Cube – Installing Packages On Offline Ubuntu Systems

Camicri Cube – Installing Packages On Offline Ubuntu Systems

As far as I tested, it was one of the easiest way for installing packages on offline Ubuntu systems. However, there is a limitation in that method. You can only download and install the software for the same Ubuntu version. In other words, If you download a package in Ubuntu 14.04, and try to install it on Ubuntu 16.04 LTS, It will not work. So, the online and offline should be the same version and architecture. Also, that method is meant for the systems that have slow Internet connection. Your offline system still need Internet connection to install Synaptic package manager if it not installed already. So that is not a viable solution to install packages on an offline system. Don’t be disappointed! There is an another way to install packages in an offline Ubuntu system. Meet Camicri Cube, a portable package manager to download applications on any internet connected computers (Ubuntu Linux or Windows), and install them back on your offline computer. Sounds great? Yes!

What exactly will Camicri Cube do?

Camicri Cube is a package manager similar to Synaptic or Ubuntu software center, but it is portable one. With Camicri Cube, we can download all packages along with required dependencies from any Internet connected systems and copy those downloaded packages in an external or USB hard drive, and install them back in an non-internet connected system. No installation required! All files in a single directory, so you can transfer them via an USB drive to any systems and install the packages with few mouse clicks. Camicri Cube is completely free, open source server-side application built in combination of Vala and Vue.
In this tutorial, I will explain how to install Camicri Cube and how to install packages in an offline Ubuntu system using it.

Camicri Cube – Installing Packages On Offline Ubuntu Systems

Requirements

You need two systems. One system must be connected to Internet to download the packages. The another system can be either completely offline or slow internet speed system.
For the purpose this guide, I will be using the following systems.
  • Online (Internet connected) system running with Ubuntu 14.04 LTS desktop.
  • Offline system running with Ubuntu 16.04 LTS desktop.
  • An External or USB drive with sufficient space.
This method consists of four steps. In first step, we download and copy Camicri Cube application to a external/usb drive from an Online system. In step two, we are going to download the package and repository lists (Note – package and repository lists, not actual packages) using Camicri Cube application in offline system and save them in external/usb drive. In step three, we download the packages and save them in external/drive from the online system. In forth and final step, we are going to install the downloaded packages in the offline system. Clear? Good! Let us get started.

1. Steps to do in Online system (14.04 LTS desktop)

From the online system (Ubuntu 14.04 LTS in our case), get the latest Camicri cube portable application from any one of the the below links.
Once downloaded, go to the location where you have downloaded the zip archive file and extract it. All contents of the zip file will extracted to a folder named “cube”.
Go to the cube folder. You will see the following inside this folder.
  1. cube-system – where Cube’s system files are stored.
  2. projects – where your project files will be stored.
  3. cube – Cube’s application executable.
Copy entire “cube” folder in your external/usb drive and go to your offline system.

2. Steps to do in offline system (16.04 LTS desktop)

Plug in the external/usb drive and copy cube folder to any location of your choice. Go to the cube folder and double click the cube executable file to launch it.

If it doesn’t start, do the following. Open Terminal and switch to the cube folder.
cd cube
Make the cube application file as executable:
chmod +x cube
Then, launch it using command:
./cube --terminal
Cube application will be started in your default web browser.
Now we need to create a new project file. The project file will contain your offline Linux computer’s repository list and installed packages. This data will be used by Cube in determining packages compatible in your system to be downloaded and installed. All Projects created in cube will be saved in cube/projects directory.
Enter a name for your new project and click Create. If you have created only one project, it will be automatically selected in the Projects drop-down box, so just click Open to load your project. If you have more than projects, you will have to choose one from the drop down list.

Cube will read your Ubuntu system’s repositories to check for all available, installed and needs to be updated packages. Once done, you will see the cube’s main interface.

Since it is offline system, we can’t download or install anything at this moment. So exit Camicri cube application.
To do so, click on the cube icon on the top left and click Quit.

Plug in your external/usb drive. On the project’s folder cube/projects, copy the newly created project folder and transfer it to your removable device.

If both systems are accessible via LAN, you can transfer the files via SSH or any file transfer medium/application.
Now go back to the online system.

3. Steps to do in Online system (14.04 LTS desktop)

Transfer the newly created project (i.e ostechnix) inside cube/projects folder from your removable device.
Then, navigate to cube folder and launch cube application.
Now, you will see the project is listed there. Just click Open to load the project.

Download Repositories
First, we need to download the repositories (In this case, we are downloading Ubuntu 16.04 system’s repositories, not Ubuntu 14.04 system).
To do so, go to Cube -> Repository -> Download Repositories to download new repositories.

Now Cube will start to download the repositories.

Once the download completed, you will be prompted to update the repositories in your original (i.e offline) system. We will do this later when we go back to our offline system. Click Close to close this dialog box.

Downloading packages
Before downloading new or any specific packages, we must update the existing packages.
To do so, click on the Asterisk button on the left and choose Upgradable.

You will now see the list of packages that needs to be updated.

Then, click on Cube -> Download -> Mark All Updates for Download to mark all packages that needs to be updated.

Now you will gre color check mark on every packages that needs to be updated.

To unmark all selected packages, click Cube -> Download -> Unmark All for Download.
Now, we have marked the packages for download. You can click on the check mark to unmark a package if you don’t want to download it.
After you marked all updates, click on Cube -> Download -> Download All Marked Packages to start downloading.

You will see package selection summary. Click Continue to start downloading the packages that needs to be updated. It will take a while depending upon the Internet speed and number of available updates.
Now, We have downloaded all available updates. It is time to download the new packages. If you don’t want to download, just close the Cube application, copy the project’s folder in your removable device and go to step 4. Just in case you want to install a new package on your offline system, read on.
Search individual packages to install
We can search for packages in two ways, either from the search box on the top or from the list of categories provided on the left pane.
To search for a package, just enter its name in the search box. You can either use the full or only the part of the name to search for a specific package. I am going to search for gimp box, so I typed gimp in the search box.
Click the Download button. You will see a brief description of the selected application. Click Download again to start downloading.

To mark multiple packages, hover the mouse over the Download button and click on the green color tick mark.

Then, click on Cube -> Download -> Download All Marked Packages to start downloading.

Similarly, you can select and download as many as applications you want. Once you have downloaded all packages, copy the project’s folder (ostechnix in our case) in your removable device and go back to your offline system. If the project’s folder is too big, compress and transfer it to your removable devices.

4. Steps to do in offline system (16.04 LTS desktop)

On cube/projects folder, delete the old project and replace it with the new project. Then launch cube application.
Remember we have downloaded new repositories? We need to update them now. To do so, Click Cube -> System -> Update Computer’s Repositories.

Now, it is time to install the downloaded updates and new packages.
Install updates
To do so, click Cube -> Install -> Mark All Downloaded for Installation. And then click Cube -> Install -> Install All Marked Packages to install them.

You will now see the list of packages to be installed. Click Continue.

You will be asked to enter your sudo password. The packages are being installed now.

Once installation completed, Cube application will automatically close.
Let us see if the newly downloaded package (gimp) is installed or not.

See? Gimp is installed!
Clean Project
Once you have installed all packages, delete the project to free up some space for future projects. To do so, click Cube -> Project -> Clean Project.

Conclusion

Camicri Cube is not just to install packages on non-internet connected systems but also to reduce bandwidth in greater number. If you have to install same packages in large number of computers, this application might be a great choice. Download the applications, keep them safely in an external drive and install them whenever required in the offline Ubuntu systems. You don’t have repeatedly download the same packages over and over. You can create different project to install different kind of packages.

Resources:

Offline Package : How To Install Software Offline In Ubuntu 16.04

How To Install Software Offline In Ubuntu 16.04

Today, we will be discussing an interesting and useful topic. We are going to install softwares offline in Ubuntu systems.  Excited? It’s fairly simple and easy. What we are going to do now is download a software along with all its dependencies from any Internet-enabled system, and copy the downloaded files and install them in the offline Ubuntu systems.this method is much easier than all other methods. All we need is just a Synaptic package manager. For those who don’t know, Synaptic package manager is the graphical front-end for APT package manager. Using Synaptic we can easily install, update, and remove packages in DEB based systems.

Why?

So, why do we need to do this? To save Internet bandwidth, of course! Let us say we have 100+ Ubuntu systems, and we need to install MySQL server in all those systems. We all know this will consume lot of Internet bandwidth. So, why don’t we just download a software with all required dependencies in only one system, and copy and install them in the rest of the systems? It doesn’t matter whether the other systems have Internet connection or not. Sounds, logical? Indeed. This method will save you a lot of bandwidth, so that we can use it for other purposes.
You might have some questions.

I have downloaded the softwares for Ubuntu 14.04 version, and I want to install them in Ubuntu 16.04. Is it possible?

No, you can’t! You can only download and install the softwares for the same Ubuntu version. For example, If you download MySQL packages of Ubuntu 14.04, and try to install it on Ubuntu 16.04 LTS, It will not work.

My system doesn’t have Internet, and Synaptic manager. Can I still install softwares using this method?

No! This method is intended to save the Bandwidth. Your system must have Synaptic installed. Otherwise this method won’t help. Or else, you can download the .deb file, and try to install it. But sometimes, .deb file will also require dependencies. In such cases, there is no way to install any softwares offline. The Internet connection is mandatory.

Install Softwares Offline In Ubuntu

I tested this on Ubuntu 16.04 LTS desktop. However, It should work all DEB based systems as long as they have Synaptic package manager installed. As you all know, we can install Synaptic, using the following command:
sudo apt-get install synaptic
For the purpose of this tutorial, I will be using two Ubuntu desktops.
  1. Lubuntu 14.04 LTS desktop (Internet enabled)
  2. Ubuntu 16.04 LTS (Synaptic package manager installed, and don’t have Internet)
For the sake of simplicity, let us call the Lubuntu (Internet-enabled) system as online system, and Ubuntu 16.04 LTS  desktop as offline system.

Steps to do in offline system

First go to the Offline system, and open Synaptic package manager. Search for the packages you want to install. For example, let us install MySQL server. Enter mysql in the search box. You will see the list of suggestions. Choose MySQL server package from the list, and select Mark for installation.
Once you selected the mysql server, the synaptic package manager will automatically select the additional required dependencies. Click Mark.
As you see in the above screenshot, Synaptic has automatically selected the required dependencies for the mysql server.
Next, go to File -> Generate package download script from the Synaptic package manager. Save this script on any folder of your choice with extension .sh. Please note that you must save this file with .sh extension.
For example, I saved this file (Ex. mysql.sh) in a folder called mysql_install.
This script contains the download URLs of all softwares that you marked for installation.
Now, copy this entire folder to a USB drive or any other medium, and go to the online (Internet enabled) system.

Steps to do in online system

Cd to the mysql_install folder, and make the script as executable:
cd mysql_install
sudo chmod +x  mysql.sh
Finally, run the script using command:
./mysql.sh
The above command will download mysql server with all dependencies, and save them inside mysql_install folder.
Once you downloaded all softwares, copy this entire folder to the USB drive or any other medium of your choice. Also, keep this folder safe if you want to install MySQL server on multiple systems.

Go back to Offline system

Again, go back to the offline (Ubuntu 16.04 LTS) system, and open Synaptic manager.
Go to File -> Add download packages.
Select the location of the folder that contains the downloaded files, and click Open.
That’s it. Synaptic will ask you to install the downloaded packages. Click Apply to install them.
The softwares will start to install in offline.
Similarly, you can install any software on your offline Ubuntu desktop.
Also, you can copy the downloaded files, and paste them in /var/cache/apt/archives/ folder. Then search package that you want to install from Synaptic and install it.
Don’t forget to keep the downloaded files in a safe location to use them later in any other offline systems.

Friday, December 1, 2017

How to use FIND command to locate anything in Linux

How to use FIND command to locate anything in Linux

Hello Linux-fanatics in this post we will discuss find command. It is very useful utility which we can be use to easily locate files & directories with a number of search criteria to refine your search. Its usually installed by default on most of the Linux distributions.

Basic syntax for using find command is :-
find  location comparison-criteria  search-term

1- Finding files or directories

$ find /etc -type f
So, this command will find all the files in /etc folder. We can also use -type d to produce list of all the directories on /etc on screen.

2- finding files/directories with size

$ find /etc -type f -size 1M
find command
will show all the files in /etc folder with size of 1 Megabytes.

3- finding files based on name

$ find /testing -iname “*.txt”
find command
command will show all the files in /testing folder with extension .txt & will also ignore if the results are case sensitive I.e. it will show results with test1.txt or test2.TXT.
Also, if we want to find files with exact match that we can use -name instead of -iname.

4- Invertive search

$ find /testing -not -name “*.txt”
find command
above command will list all the files & directories that does not have extension “.txt” at the end.

5- Combining search criteria

$ find /testing -name ‘test*’ ! -name ‘*.txt’
find command
Above example shows combining of two search criteria i.e.it will find all the file with name test at the start in /testing folder which does not have extension .php.
“!” here is equivalent of AND operator.
Also, we can combine two search criteria & produce result when any of the two search criteria are satisfied.
$ find /testing -name ‘test*’ -o -name ‘*.txt’
find command
Here “-o” is equivalent to OR operator.

6- Search based on file permissions

$ find /testing -type f -perm 0644
find command
Also, we can find files or directories based on permissions given to them. Above command shows us just that. It will show all the files in /testing folder with permission of 0644.
$ find /testing -type f -perm /u=r
Result for the above command will show all files for user with read permissions.

7- Finding files with user & group ownership

$ find / -user dan
find command
it will find all the files that are created by user dan. Similarly we can also search for files or folders that are owned by a group by replacing -user with with -group.

8- Finding files based on their modification, access & change time

$ find / -mtime 10
It will find all the files that were modified in last 10 days. Replace mtime with -atime to find all the files that were accessed in last 10 days..
$ find / -cmin -60 will find all the files that were changed in last 60 minutes.
$ find / -mmin -60 will find all the files modified in last 60 minutes.
$ find / -amin -60 will find all the files accessed in last 60 minutes.

9- Listing all the found files

$ find . -exec ls -ld {} \;
find command
Will show all the files & will show them as would be shown by ls command.

10- Finding & deleting the found files

$ find /testing -type f -name *.txt -size -1M -exec rm -f {} \;
This command will find all the files with .txt as extension with size less than 1 Megabyte & will execute rm/delete command on found files.