Wednesday, April 15, 2020

How to fill memory on Linux

The easy way to fill memory is to  fill /dev/shm via dd command

1) Fill shm with random data
while true ; do dd if=/dev/zero of=/dev/shm/fill bs=1k count=4024k; sleep 2; done
2) Monitor memory usig free command and you should see memory usage under "used" and "free" changing
while true ; do free -m ;  sleep 2;done
# free -m
              total        used        free      shared  buff/cache   available
Mem:           7822        1937         164        3920        5720        1650
Swap:          3583           0        3583

Monday, March 30, 2020

Grant command changed in MySQL 8

The below command no longer working in MySQL 8.x

msql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "password";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY "password"' at line 1

It seems that MySQL no longer support the one liner version of grant command, it's now requires to create user first and the grant the privileges


mySQL> CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'word123';
Query OK, 0 rows affected (0.01 sec)


mysql> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost";

Wednesday, March 25, 2020

Duck DNS free dynamic DNS for your hosts

A few days back I was searching for free DNS server to use for my dynamic IP host

Found DuckDNS from its web it says ...
"Duck DNS is a free service which will point a DNS (sub domains of duckdns.org) to an IP of your choice"

Below are the steps to configure and use DuckDNS service

1) First create a log in the duckdns, by choosing sign in with Google , twitter etc
2) Once logged in take note of the "Token" which will be on the first page
3) Create a subdomain by typing the name in the sub domain box and click "add domain" button.  This would be your DNS hostname in the form of yourdomain.duckdns.org
4) Follow the instructions under the "install" tab to configure duckdns on your dynamic IP host, below is the steps for Linux host with cron installed already

- mkdir duckdns
- cd duckdns
- Now copy this text and put it into the script
vi duck.sh
echo url="https://www.duckdns.org/update?domains=exampledomain&token=a7c4d0ad-114e-40ef-ba1d-d217904a50f2&ip=" | curl -k -o /root/duckdns/duck.log -K -

Replace
exampledomain: with your subdomain name created on duckdns site
a7c4d0ad-114e-40ef-ba1d-d217904a50f2&ip= : with your token from the duckdns site

- Make the script executable
chmod 700 duck.sh
- Next, create a crontab entry for the script to run every 5 minutes
*/5 * * * * /root/duckdns/duck.sh >/dev/null 2>&1

- Test the script
./duck.sh

This should simply return to a prompt, we can also see if the last attempt was successful (OK or bad KO)
cat duck.log

5) Now try ssh into your Linux host using the domain name created
ssh youdomain.duckdns.org

6) Reboot the host or change the IP of the host and then wait 5 minutes, you should be able to ssh using the DNS domain name

Monday, March 16, 2020

Duck DNS

Now it's easy to remember my internet-facing hosts with dynamic IP using DuckDNS

Monday, January 14, 2019

How to boot into Rescue Mode or Emergency Mode CentOS / RHEL / Ubuntu

This article explain Rescue Mode and Emergency and also explain how to boot Ubuntu into these modes.

This Article explain how to boot CentOS/ RHEL 7 into rescue or emergency mode

I found it very useful hence sharing here

Sunday, January 13, 2019

Play with Docker

The Play with Docker classroom  is a nice tool for newbies to learn containers/Docker. Give it a try 

Sunday, May 1, 2016

Rotating traffic captures using tcpdump

To avoid creating large traffic captures using tcpdump, there are couple of interesting switches in tcpdump command which enable one to create rotating traffic captures, compress it on the fly etc.

ni :specifies the network interface on which to capture traffic
-s :; indicates a capture of the full size of the packet
-vvv : verbose
-w  :  indicates the file name and location in which the capture will be saved
-C  :  indicates the size of each file, after reaching this size file will be rotated
-W  :  indicates the number of files that will be stored
-z  :  to compress the file


For example,

tcpdump -ni eth1 -C 20 -z gzip -w /tmp/trace.pcap

This would create a file named trace.pcap...trace.pcapX. After 20MB of data, (-C 20) tcpdump would create a file named trace.pcapX and so on. and compress the capture files after tcpdump finished writing to them.

tcpdump -pni eth0 -s0 -C 100 -W 10 -w /tmp/capture

In this example, tcpdump starts capturing into capture1 until it reaches capture10. When it filled up capture10 with 100MB of data, it starts again, overwriting capture1. This way, your captures
will never use more then 1000MB of disk space.