Skip to main content

Posts

Showing posts with the label Linux basic device utility tools

Linux quickly check MAC or IP

How to view or check MAC address or IP address in Linux VM or Server? On the the Terminal or CLI, to view MAC address: Type: ip -4 neigh show  This will show all IPV4 addresses plus the MAC address linked to the IP and will also show the status whether it's Reachable or Stale. Or just simple type: ip neigh The legacy command is: arp -an To check for IP via CLi, one way is to type: ip r It will show the IP and whether there is an assigned gateway. To view all IP addresses assigned to an interface is to type: ip addr show Checking MAC addresses is quite important especially if there's some network flapping issues, since MAC address is at Layer 2 on the OSI model, if it's not working properly then all other layers will be affected. Of course, IP is also important or else it can't connect to the network, or reach the internet That's it till next time. Keep learning. Always Pray no matter what circumstances is happening in your life, being connected to Jesus all the time...

Ansible comment all existing lines and add new lines

Backing up every configuration before any change is a good idea.  With the Git tool, every revision or change can be keep track and changes can be reversed. However, not everything is in Git. For example, in Linux configuration on /etc configuration or other important location or files is not under Git. To keep track of the changes, old school method can still be applied. Making another copy of the file, or just simply commenting every line and adding changes or new configuration after commenting the existing lines or configuration; are forms of backup. Existing configuration can still be seen, and can put back if there's a need to reverse the configuration. In an environment where there is hundred or more virtualized machines, Ansible is a way to go.  Ansible can do the task to comment all the existing lines and apply new configurations. Ansible script below, are references from multiple sources found on the web to create this Ansible script below. Here's the Ansible, save it...

How to automate Python to use Telnet to check ports

 Checking ports automatically can be stressful if there are quite a few addresses and ports to be checked. And typing manually is prone to error by mistyping the IP Address and Port. This is where automation comes into play. Prepare the IP Address and Port on  a text file, and once all is prepared. Let Python do the job or the task to Telnet and check the port whether the system can successfully connect or not. The tester just need to watch or monitor the terminal or do some other task, while waiting for the Python to do its job. Simple code below shows, how to do this task. #===================================== import sys import telnetlib def get_all_ips(filename_to_check):   with open(filename_to_check, 'r') as entries:     for ip_entries in entries:       ip_and_port=ip_entries.split(" ")                 the_ip=ip_and_port[0]       the_port_num=ip_and_port[1]       the_...

Unable to login to SSH even with a correct password

 In Linux world, SSH is a life. Especially, now with remote work, data center, servers without graphical interface. If you can't login via SSH,  even with a correct password but other user accounts is able to login. Then the person need to check with HR whether he or she is still on the payroll. :)  😄 Of course, glitch, errors and other issues will always be a part of this technology. Nothing is perfect in this world, so errors, technological issues will always be there it won't go away. So, what will will you do if you are sure that the SSH password and username is correct? Like you can login to Server 1, Server 2 but unable to login with Server 3 using the same credentials? If other users with sudo credentials are still able to login, the sudo account can be used to troubleshoot the specific SSH account that is having the issue. What would be the first thing to do? Well, joke as it seems that "restart works always" but the reality is not far from there. Restart SSH...

Basic Ansible copy file/files to remote server

Copying files to remote server is needed at times, like deploying a new certificate or just some readme notes or other files that are just necessary in order to complete a task. Working with a single server, is not an issue. However, managing or deploying a file to a multiple servers could be daunting by doing it manually from server to server. Ansible is a good tool to copy files in one go, to multiple servers. Below is a sample code that would copy a file or group of files to specified servers. This can be a run as ansible adhoc playbook on an ansible node controller. {{ item }} <-- is the place holder for all file or files to be copied with_items <-- are the variables that will be placed on {{ item }} and it will be copied to the specified destination         with_items:           - test.crt           - server.crt           - filetest.pem #==========Ansible code below ---   ...

Ping sweep with Bash script in Linux

Ping is a good tool to easily check or troubleshoot a system whether it is online or not. Provided the system or device is allowed to reply to any ICMP request. A simple Bash script below shows how to ping a Class C subnet. Replace the IP Address range below if you want to use it depending on the IP Address set on your network. It also illustrates how to make use of while loop, increment a variable counter, and use a variable to substitute as part of the whole command in Bash.  #====================== #!/bin/sh i=0 while [ $i -ne 255 ]   # initialize the counter don't exit until 255 counter is reached do         i=$(($i+1))   #increment the variable counter by adding 1 to it         echo "$i"     # just show the counter as it is incremented         ping -c2 192.168.0.$i   # ping the IP Address twice $i will be substituted with ...

Linux get IP and Gateway and DNS subnet from CLI

In windows getting gateway, IP, subnet and DNS is quite straight forward using ipconfig command via command line.  ipconfig /all or ipconfig -all will show the settings of the IP Address, DNS IP, Subnet mask and Gateway. In Linux world, well it can also be done but need to remember a few command line to get all these settings. Here's how it's done from the command line or terminal. hostname -I;netstat -rn;cat /etc/resolv.conf So, it's hostname -I <--capital letter i and netstat -rn plus the resolv.conf file where the DNS IP Address is set. The ";" semi-colon is to execute the command line one after the other. hostname -I <-- will show the IP Address netstat -rn <-- will show the gateway and the subnet mask (need to install net tools if command is not found) /etc/resolv.conf <-- where the DNS IP Address is set It's quite daunting if you're a newbee, but hey it is just a command line it doesn't bite it just shows good information to know abo...

Nano editor shortcut keys

Nano editor in Linux is quite handy when working with text files in terminal window. Here's some keystroke that is quite useful when using Nano or editing text file with Nano. Ctrl + i  is like pressing the "Tab" key Ctrl + y will   go to top of the current displayed window or the top of the current nano screen Ctrl + v will go to the end of the current displayed window or the end of the current nano screen Ctrl + m  will move current line below the current cursor position Ctrl  + d will delete empty line                or will delete tab spaces                or will delete a single character if the line has text on it Ctrl + k   will cut the current line or current line will be cut and copied to clipboard (like Ctrl + x in word document if the text is highlighted) Ctrl + u   will paste the line that was cut or whatever is on the clipboard (like Ctrl /+ v in word doc...

Compare multiple variables Conditions with if else in PowerShell

Multiple conditions to evaluate is sometimes necessary in order to decide whether the script should continue to execute a specific command or do another process. PowerShell is able to do this kind of task using if else statement. Example script below just shows 3 variables that should match and it will output "OK", the output is just a write-host command but it could be replaced with other codes. And if one of the statements does not match the "else" statement is executed. Example code: All statements or condition matches $var1 = "Online" $var2 = "Running" $var3 = "Proceed"   if (( $var1 -eq "Online" ) -and ( $var2 -eq "Running" )   -and ( $var3 -eq "Proceed" )) {   write-host "OK"   } else {   write-host "Not OK unable to Proceed"   } Output: OK One of the variable does not match: $var1 = "Online" $var2 = "Running" $var...