openvpn

OpenVPN is a robust and highly flexible tunneling application that uses all of the encryption, authentication, and certification features of the OpenSSL library to securely tunnel IP networks over a single TCP/UDP port. OpenVPN is developed by James Yonan of OpenVPN Technologies.
In this brief guide, let us setup OpenVPN server on CentOS 6.5, and connect from a remote client. For the purpose of this tutorial, I use two systems running with CentOS 6.5, one acts as VPN server and other one acts as VPN client.

Part One – VPN Server Side Configuration

Here, I use CentOS 6.5 as VPN server, and it’s actual IP address is 192.168.1.2/24.

Prerequisites

OpenVPN and it’s dependencies are not available in the CentOS default repositories. So, we should install the “EPEL” repository in order to install OpenVPN and its dependencies.
To enable EPEL repository On CentOS, refer the following link.
Also, update the system using the following command:
yum update

Install OpenVPN Software

Install the OpenVPN software using the following command:
yum install openvpn easy-rsa
The easy-rsa scripts are located by default in the /usr/share/easy-rsa/ directory. Make a directory /easy-rsa/keys inside the/etc/openvpn directory and copy the scripts to that directory as shown below:
mkdir -p /etc/openvpn/easy-rsa/keys
cp -rf /usr/share/easy-rsa/2.0/* /etc/openvpn/easy-rsa/

Generate CA Certificate and CA key

Edit file /etc/openvpn/easy-rsa/2.0/vars,
vi /etc/openvpn/easy-rsa/vars
And, change the values that matches with your country, state, city, mail id etc.
[...]
# Don't leave any of these fields blank.
export KEY_COUNTRY="IN"
export KEY_PROVINCE="TN"
export KEY_CITY="Erode"
export KEY_ORG="Unixmen"
export KEY_EMAIL="sk@unixmen.com"
export KEY_OU="server"
[...]
Go to the openvpn/easy-rsa directory:
cd /etc/openvpn/easy-rsa/
Enter the following commands one by one to initialize the certificate authority:
cp openssl-1.0.0.cnf openssl.cnf
source ./vars
./clean-all
Then, run the following command to generate CA certificate and CA key:
./build-ca
Sample output:
Generating a 2048 bit RSA private key
......................................................+++
............................................................+++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [IN]: ----> Press Enter
State or Province Name (full name) [TN]: ----> Press Enter
Locality Name (eg, city) [Erode]: ----> Press Enter
Organization Name (eg, company) [Unixmen]: ----> Press Enter
Organizational Unit Name (eg, section) [server]: ----> Press Enter
Common Name (eg, your name or your server's hostname) [Unixmen CA]: ----> Press Enter
Name [EasyRSA]: ----> Press Enter
Email Address [sk@unixmen.com]: ----> Press Enter
We have now generated the CA certificate and CA key. Then create certificate and key for server using the following command:
./build-key-server server
Sample output:
Generating a 2048 bit RSA private key
....................+++
.............+++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [IN]: ----> Press Enter
State or Province Name (full name) [TN]: ----> Press Enter
Locality Name (eg, city) [Erode]: ----> Press Enter
Organization Name (eg, company) [Unixmen]: ----> Press Enter
Organizational Unit Name (eg, section) [server]: ----> Press Enter
Common Name (eg, your name or your server's hostname) [server]: ----> Press Enter
Name [EasyRSA]: ----> Press Enter
Email Address [sk@unixmen.com]: ----> Press Enter

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ----> Press Enter      
An optional company name []: ----> Press Enter
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'IN'
stateOrProvinceName   :PRINTABLE:'TN'
localityName          :PRINTABLE:'Erode'
organizationName      :PRINTABLE:'Unixmen'
organizationalUnitName:PRINTABLE:'server'
commonName            :PRINTABLE:'server'
name                  :PRINTABLE:'EasyRSA'
emailAddress          :IA5STRING:'sk@unixmen.com'
Certificate is to be certified until Mar 23 12:21:34 2024 GMT (3650 days)
Sign the certificate? [y/n]:y ----> Type Y and Press Enter

1 out of 1 certificate requests certified, commit? [y/n]y ----> Type Y and Press Enter
Write out database with 1 new entries
Data Base Updated
Create certificate and key for VPN clients using the following command:
./build-key client
If you want to create certificate and key files for each client, you should replace the client parameter with an unique identifier.
Sample output:
Generating a 2048 bit RSA private key
.......+++
..................................................................................................+++
writing new private key to 'client.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [IN]: ----> Press Enter
State or Province Name (full name) [TN]: ----> Press Enter
Locality Name (eg, city) [Erode]: ----> Press Enter
Organization Name (eg, company) [Unixmen]: ----> Press Enter
Organizational Unit Name (eg, section) [server]: ----> Press Enter
Common Name (eg, your name or your server's hostname) [client]: ----> Press Enter
Name [EasyRSA]: ----> Press Enter
Email Address [sk@unixmen.com]: ----> Press Enter

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ----> Press Enter
An optional company name []: ----> Press Enter
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'IN'
stateOrProvinceName   :PRINTABLE:'TN'
localityName          :PRINTABLE:'Erode'
organizationName      :PRINTABLE:'Unixmen'
organizationalUnitName:PRINTABLE:'server'
commonName            :PRINTABLE:'client'
name                  :PRINTABLE:'EasyRSA'
emailAddress          :IA5STRING:'sk@unixmen.com'
Certificate is to be certified until Mar 23 12:23:44 2024 GMT (3650 days)
Sign the certificate? [y/n]:y ----> Type Y and Press Enter

1 out of 1 certificate requests certified, commit? [y/n]y ----> Type Y and Press Enter
Write out database with 1 new entries
Data Base Updated

Generate Diffie Hellman Parameter

Enter the following command to generate DH parameter.
./build-dh
Sample output:
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
The necessary keys and certificates will be generated in the /etc/openvpn/easy-rsa/keys/ directory. Copy the following certificate and key files to the /etc/openvpn/ directory.
  • ca.crt
  • dh2048.pem
  • server.crt
  • server.key
Go to the directory /etc/openvpn/easy-rsa/keys/ and enter the following command to transfer the above files to /etc/openvpn/directory.
cd /etc/openvpn/easy-rsa/keys/
cp dh2048.pem ca.crt server.crt server.key /etc/openvpn/
And then, you must copy all client certificates and keys to the remote VPN clients in order to authenticate to the VPN server. In our case, we have generated certificates and keys to only one client, so we have to copy the following files to the VPN client.
  • ca.crt
  • client.crt
  • client.key
As I mentioned before, I have another system running with CentOS 6.5 that acts as my VPN client. Make sure you have installed openvpn package on your client systems. Then, copy the above files to your VPN client system, using the following command:
scp ca.crt client.crt client.key root@192.168.1.101:/etc/openvpn
Copy the keys with caution. If anyone have chances to get the keys, they can easily intrude and get full access to your virtual private network.

Remove Client access to VPN server

If you want to remove a user’s access to the VPN server, enter the following command:
. /etc/openvpn/easy-rsa/2.0/vars
. /etc/openvpn/easy-rsa/2.0/revoke-full client
The above commands remove the user who have the certificate to access the VPN server.

Configuring VPN Server

Now, we have to configure our VPN server. Copy the file server.conf file to /etc/openvpn/ directory.
cp /usr/share/doc/openvpn-2.3.2/sample/sample-config-files/server.conf /etc/openvpn/
Edit file server.conf,
vi /etc/openvpn/server.conf
Find and uncomment the following lines to route client systems traffic through OpenVPN server.
[...]

# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh dh2048.pem

[...]

push "redirect-gateway def1 bypass-dhcp"

[...]
Also, Uncomment and change the DNS servers to reflect your own DNS values. Here I am using Google public DNS servers.
[...]

push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

[...]
Uncomment the following lines:
[...]

user nobody
group nobody

[...]
Save and close the file.
Then we need to copy and edit the client.conf file. We need this file to be transferred to the VPN clients. First copy the file to any location (ex. /home directory).
cp /usr/share/doc/openvpn-2.3.2/sample/sample-config-files/client.conf /home/
Edit file client.conf,
vi /home/client.conf
Set the VPN server host name/IP address:
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote 192.168.1.2 1194
Here 192.168.1.2 is my VPN server IP address.
Next, Copy the client.conf file to your client system.
scp /home/client.conf root@192.168.1.101:/etc/openvpn

IP forwarding and routing Configuration

Edit sysctl.conf file,
vi /etc/sysctl.conf
Find the following line and set value “1” to enable IP forwarding.
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
Run the following command to apply the sysctl changes.
sysctl -p
Adjust iptables to forward traffic through VPN properly.
Enter the following commands one by one:
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
Save the iptables changes using command:
service iptables save
service iptables restart
Finally, start openvpn service and make it to start automatically on every reboot using the following commands:
service openvpn start
chkconfig openvpn on
At this time, you should have a working OpenVPN server. Next, let us move to client side configuration.
Verify if VPN interface(tun0) is created using ifconfig command:
ifconfig
Sample output:
eth0      Link encap:Ethernet  HWaddr 08:00:27:46:36:62  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe46:3662/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:604 errors:0 dropped:0 overruns:0 frame:0
          TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:44166 (43.1 KiB)  TX bytes:14434 (14.0 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

Part Two – VPN Client side configuration

Here, I use CentOS 6.5 as my VPN client system. And, it’s actual IP address is 192.168.1.101/24.

Install OpenVPN

Enter the following command from the Terminal to install openvpn package.
yum install openvpn
After installing openvpn, start the service and make it to run automatically on every reboot.
service openvpn start
chkconfig openvpn on
Now, check if tun0(VPN interface) is created.
ifconfig
Sample output:
eth0      Link encap:Ethernet  HWaddr 08:00:27:BE:25:49  
          inet addr:192.168.1.101  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:febe:2549/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:537 errors:0 dropped:0 overruns:0 frame:0
          TX packets:387 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:52177 (50.9 KiB)  TX bytes:50170 (48.9 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.6  P-t-P:10.8.0.5  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
As you see in the above output, the VPN server has automatically assigned IP address 10.8.0.6 to my VPN client.
Check if you can ping your VPN server from client system.
ping 10.8.0.1
10.8.0.1 is my VPN server tun0 address.
Sample output:
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.
64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=9.61 ms
64 bytes from 10.8.0.1: icmp_seq=2 ttl=64 time=7.17 ms
64 bytes from 10.8.0.1: icmp_seq=3 ttl=64 time=4.87 ms
That’s it. Now the VPN server and client are ready. Connect to your VPN server securely.

chattr & lsattr immutable undeleteable

  • a – append only: Writing to a file will only allow the file to be opened in append mode for writing. That is you cannot redirect output to overwrite the file, only append to it. Most normal file edit operations, like opening the file with a text editor, will most likely fail as the program will attempt to overwrite the file with the changes and “permission denied” will be displayed. This attribute can only be set by an account with superuser privileges.
  • A – Do not update Atime – access time. When the file is accessed do not update the access time (atime) attribute. This attribute can be a little tricky because if you want to see it in action you need to be aware of a few things. The behavior of atime is determine by how the file system is mounted. With noatime set the access time of the file is not updated when the file is accessed. With atime set use the kernel defaults for how atime is set. Now it could be set in strict mode where atime is always updated when the file is accesses or with relatime which only update the access time should it be older than the modification time when the file is accessed. So if you are monitoring the atime with stat on a file and you are accessing the file and not seeing this time stamp change, chances are the file system you are on is mounted with noatime or relatime set. You would actually have to modify the file and then access it (e.g; cat the file) before the atime would change.
  • c – compressed attribute: Compress sets the file to be compressed when written to on the disk. Data written to the file is compressed by the kernel before the file is written and when read, the file is uncompressed by the kernel for the read. Note that setting this attribute can incur overhead as the file will need to be compressed and uncompressed when written to or accessed. Note that this attribute is not honored by ext2 and ext3 file systems.
  • C – no copy-on-write: The standard behavior on most Linux file systems is that when a file is opened by multiple tasks at one time, instead of creating multiple copies of the information for each task, a pointer to the shared resource is used. Should a task write to the file, then a private copy is broken off for that task instead of manipulating the shared resource. This behavior can be turned off by setting the C attribute so that a separate, private copy is never created.
  • d -no dump: This marks the file as not being a candidate for backups when the dump command is used.
  • D – Sychronous Directory Updates: When a change is made to the file changes are written synchronously to the disk. What this means is that any changes to a file are immediately written to disk and available. This is particularly useful in a networked situation where multiple systems may be accessing a share. When a file is created in that share the directory is immediately updated so that it is visible to all systems accessing the share.
  • e – extents: This attribute indicates that the file is using extents for mapping the blocks on disk. Extents replaced traditional block mapping schemes (found in ext2 and ext3) and define a contiguous range of physical blocks for storage of the data. This attribute is set by the file system and cannot be altered by chattr.
  • E – This is an experimental attribute that may be set by compression programs to indicate that a compressed file has a compression error. This attribute cannot be set or changed with chattr.
  • h – This is not an attribute you can set. Its presence indicates that the file is storing its blocks in units of the file system block size as opposed to the units of sectors. This is shown when a file is, or was at one time, larger than 2TB.
  • i – Immutable: This renders the file impervious to change. The file cannot be written to, appended to, or deleted. It cannot be renamed and it cannot have a link created to it. This attribute can only be set by a superuser account.
  • I - Directory is being indexed: This attribute is not something you can set with chattr. What this indicates is that the directory is being indexed using hashed trees.
  • j – Data journaling: If the file system is mounted with the data=ordered or data=writeback options enabled then this attribute will force the data to be written to the ext3 journal before being written to the file. If the share is mounted with data=journal, than this attribute has no effect as that is the way data=journal behaves.
  • s – Secure deletion: When the file is deleted the blocks the file used are zeroed out. This attribute is not honored by ext2 and ext3 file systems.
  • S – Sychronous Updates: With synchronous update attribute set any changes to the file are immediately written to the disk. Otherwise, changes to the file are cached and then updated at a later time.
  • t- no tail merging: Tail merging, or block sub-allocation  is when a single block is used to hold the tail end of a files data. File systems are formatted into blocks for storage. The default in most Linux systems if 4KB blocks. Most files do not evenly divide into the block values resulting in the last, or tail, block of the file containing empty space. Block sub-allocation is a behavior of some file systems to aggregate the tails of multiple blocks into a single block thus freeing up the blocks those file ends would have consumed. This no tail merging attribute turns this feature off on the file.
  • T – Top of directory hierarchy: This attribute works with Orlov’s block allocator algorithm. The idea is that storing files in related directories closer together will result in faster disk access. An apt example is home directories. By grouping files with their home directories on a disk theoretically most access should be sped up. Otherwise, if directories and unrelated files are grouped together then disk access to related files will take longer. This flag will attempt to force sub-directories to be unrelated and should be spread apart.
  • u – Undeletable: This attribute sets the file to be recoverable should it be deleted, the contents of the file are actually saved. This option is not available to ext2 and ext3 file systems. This is a hold over from extfs.
A file or directories attributes can be viewed with the lsattr command. This command by itself acts like a directory listing showing all the files in the current working directory and their attributes. Specifying a single file will show only the attributes of that file. The output will look something like this:
lsattr test.txt
Produces:
————-e– test.txt
To fill in the dashes, should these values be set:
suS-iadAcj-t-e– test.txt
The lsattr command has a few flags you can pass:
  • -R – recursively list attributes of directories and their contents
  • -a – list all files in the directory including hidden files
  • -d – suppress listing contents of directories and just list directories like other files
  • -V – display version of lsattr
  • -v – display the file’s version/generation number
The version generation number is typically handled by the file system. This number is handy in networked file systems like NFS where the version number can be checked to see if a file has been changed or deleted by another user in situations where multiple users are accessing the file.
File system attributes can be manipulated by the chattr command. The command works similarly to chmod in that it requires that the change in attributes and a file or list of files be passed to it. Changing attributes can be done with:
  • + – set attribute
  • - – remove attribute
  • = – force these attributes
Thus to add the append attribute to test.txt:
chattr +a test.txt
Remember, this attribute can only be added by a superuser account like root.
To remove the append attribute:
chattr -a test.txt
Using the = to set attributes will force only those attributes to be applied. If there are already attributes that are applied to the file those will be removed if not specified by in the chattr command. The caveat here is that only those attributes that can be set with the chattr will be altered. Trying to set or remove the h attribute will fail as this can only be set by the file system not with chattr.
There are a few flags that chattr accepts. The -R flag recursively sets the attributes for all files and sub-directories below the specified or current directory.
The -V flag tells chattr to be verbose on what it is doing and will also print the program version.
The -f switch will suppress error message.
The -v switch will allow you to set the version number of a file. It requires the version number to be passed. Unless you know what you are doing, do not use this flag.

Find ports used by program

You are sometimes trying to install or configure a program and bind it to a port and it throws an error. That means some other program is using that particular port. Let’s see how you can check what program is using your system’s ports.
First if you know the number of the port you are interested in you can:
For example let’s check port number 631:
$ sudo lsof –i:631 –n –P
That should give you something like that:
COMMAND   PID USER   FD   TYPE  DEVICE  SIZE/OFF  NODE NAME
cupsd         776 root   10u  IPv6   9353       0t0  TCP [::1]:631 (LISTEN)
cupsd         776 root   11u  IPv4   9354       0t0  TCP 127.0.0.1:631 (LISTEN)
cups-brow      953 root    8u  IPv4   9930      0t0  UDP *:631
In the above, the “-n” parameter prevents automatic conversion of host IP address to host name, and “-P” parameter prohibits conversion of port number to port name. In our example, cupsd and cups-brow processes are using TCP and UDP port number 631, respectively.
If you want a list of all open TCP ports and the programs/processes associated you can type:
$ sudo lsof -i -n -P | grep TCP
On the table resulting from it, on the left column it has the processes and on the right the ports.
- See more at: http://www.unixmen.com/check-program-using-port-via-terminal/#sthash.RJSMJDQE.dpuf

Chef



Chef server part 1
===================
Enviroments
===============
think of it as development enviroment..development,test,staging,production
etc
model lif stages
may include url,location of your package repository,version of chef configuration

ROLES
=======
-->represents the type of servers in your infrastructure
like load balancer,app server ,monitoring server, DB server,DB cache server etc.

--allows you to define policy,may include list of chef config files (also called run list) to be applied.
--may include data attributes necessary for configuring your infrastructure, eg port that app server listens on,list of app to be deployed

Nodes
=============
nodes represents physical/virtual server in your infrastructure(may be in a public or pvt cloud).
each node will --belong to one organization,one enviroment,
have zero or more role.

Resources
===========
represents piece of system and its desired state eg. a package that should be installed,service to run,
file to be configured, cron job to run,a user which should be managed etc.
~ are fundamental building blocks of chef configuration.
~  are gathered into recipes...recipes ensure system is in desired state.

Recipe
========
collection of resources..help define the policy that should be  applied to node or in any component of  infrastructure,,it is configuration files that describe resources and its desired state
--it can install and configure s/w components.
--~ can manage files,deploy apps,execute other recipes


Cookbooks
==================
multiple recipes are taken and packaged into Cookbook.
recipes are stored in cookbooks.
contains recipes,templates,files,custom.
it makes use of code reuse and modularity.

Runlist
=======
runlist is the thing that is applied to the node.
it is marrying of policy and the node.
run list is composed of recipes and roles(application server role,database server role etc).

Search feature
=================
application server nodes can ask Chef server to search for other available servers with Roles,topology data
can use ip address,hostnames,FQDNs

NIC Bonding

eth2==
          ||||==> bond0---->>[]
eth3==


----------------------------------------------------------------------------------------------------
 [root@server2 network-scripts]#cat  ifcfg-eth2   
DEVICE=eth2
HWADDR=00:0c:29:5b:39:1d
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
IPV6INIT=no
USERCTL=no
##########################################
MASTER=bond0
SLAVE=yes

##########################################
#IPADDR=192.168.213.112
#NETMASK=255.255.255.0
#GATEWAY=192.168.213.2
#DNS1=8.8.8.8
[root@server2 network-scripts]#
[root@server2 network-scripts]# cat  ifcfg-eth3   
DEVICE=eth3
HWADDR=00:0c:29:5b:39:27
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes

[root@server2 network-scripts]#
[root@server2 network-scripts]# cat ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPV6INIT=no
USERCTL=no
IPADDR=192.168.213.112
NETMASK=255.255.255.0
GATEWAY=192.168.213.2
DNS1=8.8.8.8

###below are setting for mode0 (mode zero)#####
#mode=0  for round robin and mode=1 for active backup
# miimon = n milliseconds  to check if any eth is down

BONDING_OPTS="mode=0  miimon=100"


 [root@server2 network-scripts]# watch -n .1 cat /proc/net/bonding/bond0

Changing passwords from scripts (docker file)

You can run the passwd command and send it piped input. So, do something like:
echo thePassword | passwd theUsername --stdin
 
You could also use chpasswd:
echo username:new_password | chpasswd   
echo username:newpassword   | chpasswd
so, you change password for user username to new_password.

Docker container commands

check docker version
------------------------
docker version    

Search for image


docker search urgensherpa/lamp6
redhat@test:~/ssh_image$ docker search urgensherpa
NAME                        DESCRIPTION   STARS     OFFICIAL   TRUSTED
urgensherpa/lamp6                                        0                   

Pulling image
you@tutorial:~$ docker pull learn/tutorial
Pulling repository learn/tutorial from https://index.docker.io/v1
Pulling image 8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c (precise) from ubuntu
Pulling image b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc (12.10) from ubuntu
Pulling image 27cf784147099545 () from tutorial
you@tutorial:~$

Run commands in container   
docker run learn/tutorial echo "hello world"

installing things in the container

docker run learn/tutorial apt-get install -y ping  

docker ps -l
docker ps
=== ========== ========= =        ====================
docker commit 698989sdafd learn/ping  
====meaning==
698989sd...= container id
learn/ping = learn -username and ping - image
-----------------------------------------------------------
docker run learn/ping ping google.com      
Find info about docker container
--------------------------------
docker inspect efesdlfk     

docker images   = This will show you which images are currently on your host

docker push learn/ping   

fail2ban on Ubuntu 12.04 LTS

Simple fail2ban config
- - - - -- - - - - -  - --  - -
#sudo apt-get install fail2ban

Now to fine tune default configs

#cd /etc/fail2ban

#sudo vim jail.conf
#it also help protect ssh ftp apache asterisk ...
.
.
bantime  = 989898     ##in seconds
maxretry = 3     ##place your threshold value

#search for jails
#JAILS

[ssh]
enabled=true
port =ssh
filter = sshd
logpath = var/log/auth.log
maxretry = 3

save/exit
................................
#service fail2ban restart

Change language setting os = ubuntu 13.04

# vim /etc/default/locale

 //change to below param's if its like eg. LANG="np_NP"                                    
LANG="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
.
..
...

# sudo locale-gen

logout and login again

Autostart script at runtime /etc/rc.local


The /etc/rc.local file is common to major Linux distributions.
This file contains BASH commands which will be run after run-level specific commands whenever the system is booted.
In a VPS environment, /etc/rc.local is commonly used to store the hostname <SERVER_HOSTNAME>command (where <SERVER_HOSTNAME> is the intended hostname for the VPS) to ensure that the VPS hostname is not reset when the VPS is rebooted.
                                                                         Method 1                                     
redhat@cloud01:/etc/init.d$ nano rc.local 


  GNU nano 2.2.6                                      File: rc.local                                                                                    


        if [ -x /etc/rc.local ]; then

                [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
                /etc/rc.local
                ES=$?
                [ "$VERBOSE" != no ] && log_end_msg $ES
                return $ES
        fi
}

case "$1" in

    start)
        do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac
###########################at the end of file >>>>

/root/script/mystartupscript1.sh

/root/script/mystartupscript2.sh  &    #mystartupscript2  & ==the & sends the script to background 
chown wso2:docker /var/run/docker.sock
modprobe aufs
sudo killall dnsmasq


##$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

                                                        Method 2  #vim   /root/scripts/mystartupscript1.sh
boot=$(date)
echo "the system boot at $boot " >> /var/log/custombootlog.log

#chmod u+x mystartupscript1.sh

#vim /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#put your script/command here

chown wso2:docker /var/run/docker.sock
modprobe aufs
sudo killall dnsmasq
/root/script/mystartupscript1.sh
/root/script/mystartupscript2.sh &

exit 0