Monday, October 12, 2015

How to change network interface name from Enp0s3 to Eth0 on CentOS 7

 CentOS 7 Change Network Interface Name From Enp0s3 To Eth0

CentOS 7 Change Network Interface Name

Step1
# issue the ifconfig command to check the current network interface information, type:
# yum install net-tools









[root@localhost Desktop]$sudo ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 192.168.42.129  netmask 255.255.255.0  broadcast 192.168.42.255
inet6 fe80::20c:29ff:fec7:25ae  prefixlen 64  scopeid 0x20<link>
ether 00:0c:29:c7:25:ae  txqueuelen 1000  (Ethernet)
RX packets 200948  bytes 253071365 (241.3 MiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 56043  bytes 3420351 (3.2 MiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


Step2
# edit “/etc/sysconfig/grub” configuration file using “vim” command:
before:






[root@localhost Desktop]$sudo vim /etc/sysconfig/grub
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto  vconsole.keymap=us rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

then searching for “GRUB_CMDLINE_LINUX” line  and appending the following content “net.ifnames=0 biosdevname=0“, just like the below:


GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/swap vconsole.font=latarcyrheb-sun16 rd.lvm.lv=centos/root crashkernel=auto  vconsole.keymap=us rhgb quiet net.ifnames=0 biosdevname=0"

Step3
# Using “grub2-mkconfig” command to re-generate a new grub configuration file, type:
>








[root@localhost Desktop]$sudo grub2-mkconfig  -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
Warning: Please don't use old title `CentOS Linux, with Linux 3.10.0-123.el7.x86_64' for GRUB_DEFAULT, use `Advanced options for CentOS Linux CentOS Linux, with Linux 3.10.0-123.el7.x86_64' (for versions before 2.00) or `gnulinux-advanced-dbedd8fa-5d86-4ea0-8551-8444a48cd44f nulinux-3.10.0-123.el7.x86_64-advanced-dbedd8fa-5d86-4ea0-8551-8444a48cd44f' (for 2.00 or later)
Found linux image: /boot/vmlinuz-0-rescue-3303e35a730a41e3b4e99b544acea205
Found initrd image: /boot/initramfs-0-rescue-3303e35a730a41e3b4e99b544acea205.img
done

Step4
#   Rename “Enp” network file using”mv”command, type:

$sudo mv /etc/sysconfig/network-scripts/ifcfg-enp0s3  /etc/sysconfig/network-scripts/ifcfg-eth0

Step5
# Edit “/etc/sysconfig/network-scripts/ifcfg-eth0 ” configuration file and set the value of “Name” field to “eth0″.


















# vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
<strong>NAME=eth0</strong>
UUID=5ae10208-855b-41af-99e7-0673d3792d15
ONBOOT=yes
HWADDR=00:0C:29:C7:25:AE
PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
Step6
# reboot system, after rebooting system, using “ifconfig” command check network interface information again.









[root@localhost Desktop]# ifconfig
eth0: flags=4163 UP,BROADCAST,RUNNING,MULTICAST  mtu 1500
inet 192.168.42.129  netmask 255.255.255.0  broadcast 192.168.42.255
inet6 fe80::20c:29ff:fec7:25ae  prefixlen 64  scopeid 0x20
ether 00:0c:29:c7:25:ae  txqueuelen 1000  (Ethernet)
RX packets 49  bytes 5285 (5.1 KiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 76  bytes 8540 (8.3 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
done….

Tuesday, October 6, 2015

Monthly Bandwidth Usage monitoring with Zabbix


Monitoring server's used bandwidth is not something that comes integrated with Zabbix by default.

First of all we deploy vnstat on target server(s).  vnstat is a simple program to monitor network traffic: 

[root@centos ~]# yum install vnstat

Then we need to initialize the vnstat database for the interface we want to monitor bandwidth on. i.e. for eth0 (change this to the interface that you want to monitor!) :

[root@centos ~]# vnstat -u -i eth0

We are done with vnstat . After a while we should be able to start retrieving stats for the given interface. i.e. to get the monthly used bandwidth (you can get daily, hourly ... check man page): 

[root@centos ~]# vnstat –m

eth0  /  monthly
       month        rx      |     tx      |    total    |   avg. rate
    ------------------------+-------------+-------------+---------------
      Nov '14    201.01 GiB |   82.29 GiB |  283.30 GiB |  916.87 kbit/s
      Dec '14    282.30 GiB |  219.39 GiB |  501.69 GiB |    1.57 Mbit/s
      Jan '15    637.36 GiB |  521.07 GiB |    1.13 TiB |    3.63 Mbit/s
      Feb '15    608.20 GiB |  608.40 GiB |    1.19 TiB |    4.22 Mbit/s
      Mar '15    559.96 GiB |  419.99 GiB |  979.95 GiB |    3.07 Mbit/s
      Apr '15    420.36 GiB |  355.42 GiB |  775.78 GiB |    2.51 Mbit/s
      May '15    155.58 GiB |  110.97 GiB |  266.55 GiB |  834.81 kbit/s
      Jun '15    184.76 GiB |  122.08 GiB |  306.84 GiB |  993.05 kbit/s
      Jul '15    288.87 GiB |  143.55 GiB |  432.42 GiB |    1.35 Mbit/s
      Aug '15    268.43 GiB |  266.29 GiB |  534.71 GiB |    1.67 Mbit/s
      Sep '15     93.30 GiB |  235.18 GiB |  328.48 GiB |    1.06 Mbit/s
      Oct '15     15.69 GiB |    6.72 GiB |   22.40 GiB |  419.62 kbit/s
    ------------------------+-------------+-------------+---------------
    estimated     93.79 GiB |   40.18 GiB |  133.97 GiB |


With vnstat in place and correctly working , we move now to creating a Zabbix UserParameter that will retrieve the total bandwidth used in a given month and send it to Zabbix via the Zabbix agent that we have installed in our server. Visit this link for more information on Zabbix UserParameters.

For this we first create a script that will get from vnstat the necessary information (so the total bandwidth used up to now in the current month): 

#!/bin/bash
# Current month total bandwidth in MB
i=$(vnstat --oneline | awk -F\; '{ print $11 }')
bandwidth_number=$(echo $i | awk '{ print $1 }')
bandwidth_unit=$(echo $i | awk '{ print $2 }')
case "$bandwidth_unit" in
KiB)    bandwidth_number_MB=$(echo "$bandwidth_number/1024" | bc)
    ;;
MiB)    bandwidth_number_MB=$bandwidth_number
    ;;
GiB)     bandwidth_number_MB=$(echo "$bandwidth_number*1024" | bc)
    ;;
TiB)    bandwidth_number_MB=$(echo "$bandwidth_number*1024*1024" | bc)
    ;;
esac
echo $bandwidth_number_MB


And now we add the aforementioned  UserParameter to the Zabbix Agent configuration file (in Debian it is located in /etc/zabbix/zabbix_agentd.conf. We add this line under the ####### USER-DEFINED MONITORED PARAMETERS ####### section:
UserParameter=system.monthlybandwidth,/home/zabbix/zabbix_total_month_bandwidth.sh

Please modify the script path and name according to your settings.  Note that the name we have used for this new UserParameter is system.monthlybandwidth . Again, you can customize this according to your needs.

We are mostly done. 

We just need now to go to Zabbix Admin and add the new parameter as an item to the desired server or template. You will want typically to deploy this new parameter to a template so it gets automatically distributed to new servers using this template







Here you can see the definition of the new item with the name of  Bandwidth Month . We have used a multiplier too to convert the final unit to GB.

So now we can check how it looks a graph for one server with this item configured:   



As expected we have a raising line each month from 0 to the total used bandwidth. We will be able to spot sudden rises in bandwidth consumption, max during the period for which we have data ... 

Monday, October 5, 2015

[Docker] x509: certificate signed by unknown authority - Docker

Issue:

# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/hello-world ... failed
Get https://index.docker.io/v1/repositories/library/hello-world/images: x509: certificate signed by unknown authority


Solution:

 # echo -n | openssl s_client -connect index.docker.io:443 -showcerts | sed -n -e '/BE-GIN\ CERTIICATE/,/END\ CERTIFICATE/ p'

depth=1 C = IN, ST = Gujarat, L = Ahmedabad, O = Cyberoam, OU = Cyberoam Certificate Authority, CN = Cyberoam SSL CA_C202314364571, emailAddress = support@cyberoam.com
verify error:num=19:self signed certificate in certificate chain
verify return:0
DONE

...and put it in
/usr/share/pki/ca-trust-source/anchors/

# cp cyberoam_ssl_ca.pem /usr/share/pki/ca-trust-source/anchors/

# update-ca-trust extract

# systemctl restart docker

# docker run hello-world