Raspberry Pi ddns

Featured

A couple of weeks back, I found my lost Raspberry Pi 1, and I wanted to put it into good use.


Since I built my lab, I had a Virtual Machine running Dynamic DNS service from noIP to “link” my PublicIP with a DNS name to be able connect to my jump-server from the internet (outside of my local LAN). This is necessary because your PublicIP is not static (unless you paid for one) and it changes from time to time, and let’s be frank, it’s easier to remeber a name than an IP 😉


This was all fun and games except when something would go wrong on my ESXi hosts, and VM would reboot, or when your better half asks you to power off the server cuz it was making too much noise 😀 (I bet you all went through this).

The plan is simple, use RPi (Raspberry Pi) to host the DDNS service as well as a Wireguard VPN Server. For now, we will focus only on the DDNS service.

What will you need to perform this:

  • Raspberry Pi # (does not matter the version)
  • SD or microSD card depending on the Raspberry Pi version you have
  • SD/microSD card reader
  • Power supply for your RPi
  • Network cabel (CAT 6 in my case) or you can use the builtin Wifi that you RPi might have
  • noIP account with a host already created

Steps involved

  • Install any Raspberry OS flavour on your RPi
  • Install and configure the noIP

How to install and OS into your Raspberry Pi

For this tutorial I will use the RPi Imager that you can download from the official Raspberry Pi webside

Once you have it installed just run it and follow the wizzard

First let us select the Operating System. In my case I will install Ubuntu Server 20.10 as I don’t need GUI for this project. Because they don’t offer Ubuntu Server for RPi 1 I opted for the 32bit (RPi 2/3/4/400)

Then Select your storage device (pay close attention you are selecting the correct one)

Press Write and Yes to continue and in a couple of minutes your RPi will be installed and ready to rock, well, almost….

After the OS is installed I had to enable SSH as I won’t have access to a monitor close to the RPi.

How to enable SSH on a fresh RPi installation

After the installation is completed you should have a new drive (SD/microSD card) connected to your computer. In my case it’s the letter I: The letter might be different in your case but the drive name will always be boot

Navigate to the root folder of boot drive and create a file called ssh with no extension and leave it empty

And that is it, SSH is enable on your RPi

Connecting to your RPi and installing the noIP service

First step is to connect your RPi to the network using the network cable, plug the power supply and let it boot up. Wait for one minute, connect to your Router administrator page and search for the connected device called RASPBERRYPI and copy the IP address.

You can use PuTTY to establish a connection to the RPi

Default credentials are:
user: pi
password: raspberry

After you login the next step is to update and upgrade your RPi installation. For that type the following commands:

$sudo apt-get update
$sudo apt-get upgrade
press ENTER to continue

Create a folder on your home directory called noip and wget the installation files for noip software inside with the commands:

$ mkdir noip
$ cd noip
$ wget https://www.noip.com/client/linux/noip-duc-linux.tar.gz

After the download is completed, unpack the file, go into noip-2.1.9-1 folder and follow the commands

$ tar vzxf noip-duc-linux.tar.gz
$ cd noip-2.1.9-1
$ sudo make
$ sudo make install

Now it’s time to follow the instructions.

In this case select 0 as the RPi is connected using a network cable.

Next you will be asked for your no-ip.com account and password
And if you want to update all your hosts. I selected no but ended up choosing all as I have 2 right now.
Select the interval update I left it as default.

After this point noIP service is configured on your environment.

To run the service and check the status run the following commands

$ sudo /usr/local/bin/noip2
$ sudo noip2 -S

Now that the service is runnig fine the next thing you’ll wanna do is to start the service once your RPi starts.

Adding noip2 service to autostart

To perform this task we will use the systemd feature from Ubuntu.

Create a file on /etc/systemd/system/noip2.service using the folowing command:

$ sudo touch /etc/systemd/system/noip2.service

After the file is created edit it and copy the following content inside:

$ sudo vi /etc/systemd/system/noip2.service

Once vi is open just press “i” once so you can insert text and paste the below lines inside

[Unit]
Description=noip2 service

[Service]
Type=forking
ExecStart=/usr/local/bin/noip2
Restart=always

[Install]
WantedBy=default.target

Once you’re finishe type “:wq” this will save your file and close it.

After run the folowing command:

$ sudo systemctl daemon-reload

This will reload your systemd so it’s aware of the new unit you have just created.

Now you can get status, start and stop your sevice using the folowing commands:

$ sudo systemctl status noip2
$ sudo systemctl start  noip2
$ sudo systemctl status noip2
$ sudo systemctl stop   noip2
$ sudo systemctl status noip2

To enable the autostart issue this command

$ sudo systemctl enable noip2

And that makes it for today.

You have just installed noIP in your RPi and set it to autostart on every boot.

KISS 😉

References:

https://ubuntu.forumming.com/question/7826/can-39-t-get-service-noip2-to-start-on-boot

https://www.noip.com/support/knowledgebase/install-ip-duc-onto-raspberry-pi/

Get VM name with specific MAC Address

-Recently I got a request to get a virtual machine (vm) name using only the network interface MAC Address.

After search for some scripts I could not find one that really worked for me so I put my brain to work and this is what I came up:

get-vm | get-networkadapter | Where-Object { $_.macaddress -eq "00:50:56:XX:XX:XX"} | select parent, macaddress

A brief description on how it’s working

get-vm -> gets all VMs on the vSphere server.

get-netwrokadapter -> gets the nertwork adapter properties as name, type, macaddress…

$_.macaddress -eq -> for each networkadapter it is going to compare the MACs and if they are equal it is going to be printed out

The output should be something like this:

55a15d7e5c007131

Add host to Icinga2

icinga_logo

Adding a Windows 2008 Server to Icinga2 master Server using Icinga2 agent

Setup the Icinga2 master for node clients and make shure the answer to the first question is n (no).

# icinga2 node wizard

Dowload  the agent from Icinga2 website and run it.

After the installation the setup wizzard will pop up.

icinga1

Remember the Instance Name as you will need it to generate the Setup Ticket in the Icinga2 server.

Add the Icinga2 master

Click the Add button and fill in the box

icinga2

Run this command in Icinga2 server to generate the Setup Ticket

# icinga2 pki ticket -cn infra-veeam.domain.local

Now copy the ticket and past it to the box

icinga3

Firewall

Before you click next check if the port 5665 is open in the Windows server and add a rule in Icinga2 server to permit connections

Check your active zones

# firewall-cmd --get-active-zones

I just had one “public” zone

At this point i added the rule to the firewall by running the command

# firewall-cmd --zone=public --add-port=5665/tcp --permanent

Continue the installation and finish it.

Open a command prompt and type in the command:

command

If all goes well you should get this output

command1

Now update the configured hosts by running and restart icinga2

# icinga2 node update-config
# systemctl reload icinga2

And that’s it! If you have Icinga Web 2 the host should pop up.
This post was based on the Documentation shared by the Icinga project

 

Icinga2 on CentOS7

icinga_logo

A Software to monitor the health of an infrastructure is a vital component to a good system administrator.

After looking arround for open source software i decided to give Icinga2 a try.

Icinga2 is a fork of Nagios (it’s a good start) and looks much cooler 🙂 (IMO The cool factor is very important)

CentOS7 was the choice for the Operating System.

After reading the documentation in Icinga website and having some trouble i decided to add some crucial steps that i had to take to perform a successful installation.

All the steps described are performed as root user

First thing firts, after CentOS installation update your system:

# yum update

Now add the Icinga repository to your package management configuration

# rpm --import http://packages.icinga.org/icinga.key
# curl -o /etc/yum.repos.d/ICINGA-release.repo http://packages.icinga.org/epel/ICINGA-release.repo
# yum makecache

Install Icinga2

# yum install icinga2
# systemctl enable icinga2
# systemctl start icinga2

Congratulations Icinga2 is installed.

CheckPlugins

It’s time to install the checkplugins.

As Icinga2 is a Nagios fork we are going ot install the same plugins for it to work properly by installing the Monitoring Plugins.

# wget https://www.monitoring-plugins.org/download/monitoring-plugins-2.1.2.tar.gz
# yum install gcc
# gzip -dc monitoring-plugins-2.x.tar.gz | tar -xf -
# cd monitoring-plugins-2.x
# ./configure
# make
# make install

Vim editor

Icinga2 comes with some color schemes for vim that you can install by

# PREFIX=~/.vim
# mkdir -p $PREFIX/{syntax,ftdetect}
# cd /usr/share/doc/icinga2-common-2.4.1/syntax/
# cp vim/syntax/icinga2.vim $PREFIX/syntax/
# cp vim/ftdetect/icinga2.vim $PREFIX/ftdetect/

Lets change the installation directory of the plugins from /urs/lib64/* to /urs/local/libexec in the constants.conf file of icinga2. The file is in /etc/icinga2

# cd /etc/icinga2
# vim constants.conf

Creating a systemctl for Icinga2

# systemctl enable icinga2
# systemctl start icinga2

Icinga Web 2 interface

At this point Icinga2 is istalled and configured.
Icinga 2 can be used with Icinga Web 2 and a number of other web interfaces.
For now i am going to install Icinga Web 2.
Firts we are going to install MySQL

# yum install mariadb-server mariadb
# systemctl enable mariadb
# systemctl start mariadb
# mysql_secure_installation

Now install install the icinga2-ido-mysql package

# yum install icinga2-ido-mysql

MySQL setup and configuration

# mysql -u root -p
mysql>  CREATE DATABASE icinga;
        GRANT SELECT, INSERT, UPDATE, DELETE, DROP, CREATE VIEW, INDEX, EXECUTE ON icinga.* TO 'icinga'@'localhost' IDENTIFIED BY 'icinga';
# mysql -u root -p icinga < /usr/share/icinga2-ido-mysql/schema/mysql.sql

Enable the IDO MySQL module

# icinga2 feature enable ido-mysql
# systemctl restart icinga2

WebServer install

If you did not install the CenOS web server you need to install httpd

# yum install httpd
# systemctl enable httpd
# systemctl start httpd

Firewall

Add some rules to permit access to the web server

# firewall-cmd --add-service=http
# firewall-cmd --permanent --add-service=http

Command Pipe

For the Icinga2 to receive commands from the Icinga Web 2 you need to enable the command pipe

# icinga2 feature enable command
# systemctl restart icinga2

Icinga Web 2 interface installation

Setting up package repository

# rpm --import http://packages.icinga.org/icinga.key
# curl -o /etc/yum.repos.d/ICINGA-release.repo http://packages.icinga.org/epel/ICINGA-release.repo
# yum makecache

EPEL install

# yum install epel-release

PHP install

# yum install php php-mysql

Don’t forget to change the date.timezone in /etc/php.ini

Let’s install the web interface

# yum install icingaweb2 icingacli

And now lets prepare for the web setup

# icingacli setup token create

Run this command to mitigate an error at the web setup

chcon -R -t httpd_sys_rw_content_t /etc/icingaweb2/

Copy the token and access the site:
http://<server-ip>/icingaweb2/setup
past the token and continue the setup
If the website does not open restart the httpd by running:

# systemctl restart http

For the web interface to work (send commands to your icinga server) you need to disable SELinx in your system.
To do that just edit the file /etc/selinux/confing and change the enforcing to disabled.

VMware ESXi server hardware

I have a VMware infrastructure in my company and it’s time to make a hardware upgrade.

All my server are up and running and i can’t shut them down, how can i check how many slots of physical memory RAM are free? It’s as simple as running on the ESXi Shell the command:

smbiosDump

This command will list all the hardware on the server and all you need to find is the
Memory Device section an in Size you’ll see the size of the memory that is installed or it says Size: no memory installed all you have to do is count the ones that says that.