#
Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, June 28, 2020

Linux is essential for networking in future because of the rise of network automation and evolving concepts. I am writing this post as a reference of basic Linux commands and their outputs which you will come across in a Linux CLI / Bash environment.

Most people like to use an Ubuntu VM on top of VMware in their Windows PC's, I like to use the Ubuntu App in Windows 10 App Store for my networking work.

Because of this app, both my RAM and time are saved. I just need to open it like Windows command prompt and perform Linux tasks right away.


Switch User / Switch User to root
su <username>
su - or sudo su

You will have to give the password for the switching user.

Installing a Package
apt install

You can use -y at the end of the command to say Yes to any dialog there to be appear in installation.

Uninstalling a Package
apt purge 

If you specify a wildcard name Ex:- apt purge *impacket* will get rid of everything with impacket.

Go back and forth a directory
cd .. & cd

If the directory is not where you currently in, you should use '/' before the directory name.







Listing items in a directory
ls




See all files in long listing format with read/write capabilities
ls -la
Things starts with dots (.) are hidden files.

Let's analyze the permissions notation of the 1st raw.



The letter sequence drwxr-xr-x stands for permissions.
d means a directory, if a file it will be -
After d, next letters are grouped into 3 letter groups.
In the above example, 1st group 'rwx', 2nd group 'r-x' and the 3rd group is 'r-x'.

Within these 3 letter groups 1st letter is always r = read, 2nd letter is always w = write and the 3rd letter is x = executable. If the particular right is not set it will be marked as a dash -

1st group 'rwx' is for file / directory owner
2nd group 'r-x' is for group owner
3rd group 'r-x' all others

In the above example, group owner can read and execute but cannot write.

Note:-
When you try to execute python scripts etc in networking, they should have executable rights.

Making Permissions to a file or folder
chmod
chmod 777 will make the file rwx to everyone while chmod 755 will permit read and execute access for everyone and also write access for the owner of the file.


chmod +x new.text will make the file executable for everyone

Create a directory
mkdir





Remove an empty directory
rmdir

Remove a non empty directory
rm -rf

Create a new text file with a text
echo
View a text file content on CLI
cat
You can view this content in a text editor like nano using nano new.text command.




Copy a file or a folder
cp










Following command will rename the file at destination when you copy..






Moving file or folder
mv












You can see the file is gone from the original location..

Remove a file
rm






Find a file
locate
Newly created files or folders may not be seen by this command until you run updatedb command.



View Interface Configuration
ifconfig
for wireless interfaces and configuration, we can use iwconfig

Network Troubleshooting Commands

ping <ip address>

traceroute <ip address>

arp -a

View all the ports that are open and whats connected to that ports
netstat -ano

View Routing Table
route








View command history
history

You can use grep to find a matching command in command history.
Ex:- history | grep ping

Clone a Git Repository 
git clone <github link>

Start / Stop Service
service ssh start
service ssh stop

Above commands will start and stop ssh service.

You can view the manual / get help for any command using man <command>

Saturday, April 22, 2017

If you are going to use Linux and free software you will need a SSH client like SecureCRT to access your network devices remotely. SecureCRT is a widely used industrial SSH client but it is not free. Of course you can use the Linux terminal itself but you will face limitations like session management etc. Here is the free solution, PAC Manager.  Actually it is more advanced than SecureCRT..

Be the root user..
sudo su

Enter following commands..
wget -q -O - http://archive.getdeb.net/getdeb-archive.key | sudo apt-key add -

sh -c 'echo "deb http://archive.getdeb.net/ubuntu trusty-getdeb apps" >> /etc/apt/sources.list.d/getdeb.list'

Update the packages list..
apt-get update

Install the PAC Manager..
apt-get install pac

If a dependency problem occurred,
apt-get install -f

Now open the app..

















Click on New Connection & give the ip address and the username, pw.. Save and Close.



















Now click on the session name and you will log in..


Download the TeamViewer from their website through your web browser and you can install it via GUI.. My preferred method is to use the CLI..

Be the root 1st..
sudo su

Download TeamViewer 10 from here

Navigate to the directory where it is downloaded and Install the package..
dpkg -i teamviewer-10-0-36281-multi-ubu.deb

If the installation process stopped due to a dependencies problem enter the following command..
apt-get install -f 


Friday, April 21, 2017

Monitor plugin lets you to view the up/down status of your hosts at a glance.. It will sound an alarm when the devices go down using icmp pings or snmp up time..

If you want to install Cacti on Trusty workstation, please refer this.

Be the root user 1st..
sudo su

Get the plugin..
wget "http://docs.cacti.net/_media/plugin:monitor-v1.3-1.tgz"

Rename the downloaded file..
mv plugin\:monitor-v1.3-1.tgz monitor-v1.3-1.tgz

Move the file to the plugins folder..
cp monitor-v1.3-1.tgz /usr/share/cacti/site/plugins

Change the directory to the plugins folder..
cd /usr/share/cacti/site/plugins

Unzip the folder..
tar -zvxf monitor-v1.3-1.tgz

Everything done so far is shown in the following capture...
















Now log in to Cacti and go to Console -> Plugin Management
You will see something like below..




























You can see the blue icon in actions column.. Click on it

A new green icon will appear..
Click on it, it will turn to a red icon..


Now the plugin is added.. You will see a new tab for the plugin next to Console & Graphs..

Recently I was trying to create a free Network Administration Workstation for enterprises for a project. If it should be free of course Linux and Free software comes in handy. Also this machine should work 24/7 for years, so for this workstation, I tried with CentOS-07, Ubuntu 16.04, Ubuntu 14.04 aka Trusty.

From the above three, Trusty ends up winning. It was the easiest OS to install packages for this application. So this post is about installing the RRD-Tool (Round Robin Database Tool) Cacti which collects time series data such as network bandwidth, temperature, CPU load of network devices and which is used to monitor up/down status of devices/links with SNMP and which can act as a Syslog server too.. This is the 1st step of creating the Free Network Administration Workstation..

Download the Ubuntu 14.04 desktop from here and install it.
Don't upgrade the system to latest Ubuntu version..

Be the root user 1st..
sudo su

Enter the following commands to upgrade the packages..
apt-get update
apt-get upgrade

Install Apache web server, MySQL database, PHP..
apt-get install apache2 mysql-server php5 libapache2-mod-php5




Process will halt to ask for a MySQL root password..

Install RRD-Tool..
apt-get -y install rrdtool

Install SNMP..
apt-get -y install snmp snmpd

Install Cacti..
apt-get -y install cacti cacti-spine


Process will halt again to ask for the configuration parameters for the database..

Select apache2..


Hit Yes..


Enter the MySQL root password you gave in a previous step..


Enter a password for cacti to register with the MySQL database..

Start the SNMP service..
/etc/init.d/snmpd start

Now open the web browser and go to the following link..
http://<ip-address of the Trusty machine>/cacti   or
http://127.0.0.1/cacti























Hit Next..















Hit Next..








































Hit Finish..


Enter the username: admin
password: admin

It will then ask to reset the password..

Now you can give the password you want..

















To speed up the Poller process, select spine from Console -> Cacti Settings -> Poller















Do not update the system by update notifications. It will stop your SNMP function.

After the Cacti installation, go to System Settings > Software Updates > Updates and set it to be like the following to stop further unnecessary interrupting updates..


Saturday, October 1, 2016

As many electronic enthusiasts know, Raspberry Pi is a small credit card size computer which runs a Linux operating system called Raspbian which can be used in many ways to do computer engineering stuff. I am writing this post which I will use as a reference to my future posts regarding network solutions which can be provided using this small piece of electronics.

Get Hardware Fixed

Assemble Raspberry Pi into the casing with a fan. Because this is going to be a server, it is better to use a casing with a fan to reduce the heat caused by continuous long time operation. The only thing you need to know in fixing hardware is where to plug the fan. (click on the image to view full size)

Put it just like I have done on the long GPIO / Input Output line running on the board. 

Power (Red) must be connected to the 2nd pin from the left and the Ground (Black) must be connected to the 3rd pin from the left.





Format SD card

SD card is the hard disk of this machine.
You will also need a card reader if your PC does not have a SD card reader slot. Also before buying a SD card, check whether the card supports Raspberry Pi or not though most cards do support. 

To correctly format it use SDF Formatter from here











Go to Option and select Format Type as FULL (Erase) and Format Size Adjustment ON

Now go to My Computer and right click on the SD card and select Format.


This time select the File System as exFAT because it is more faster and select Quick Format and hit Start.


Now the Hard Disk is ready to install the OS.










Burn Raspbian OS to SD card

Now download Raspbian OS (Jessie) from Raspberrypi.org
Do not download Noobs if you do not have a HDMI cable and  a LCD Display because SSH is not active by default in Noobs. I'm going to do SSH to install a remote access software like VNC next.
So I need clean OS which the SSH is enabled by default.

Time to download Win32 Disk Imager from here.


Select the downloaded image and hit Write.

Now the SD card is fully ready to insert in to the Raspberry Pi.





Boot up, SSH & Update Packages

Now plug your Pi to a 2.5A power plug (which is recommended) and plug an Ethernet Cable to the Pi which is connected to your home router. Because DHCP is enabled by default on the Ethernet port, it is the easiest way. And aslo you can guess the ip address which it will get by looking at your PC's IP and if you know how many devices are connected. If you are not sure, download a scanner like Advanced IP Scanner from here.












You can see the IP address of my Pi is 192.168.1.7 which I'm going to SSH into.
Download Putty to do SSH. SecureCRT will not work because of a SSH version mismatch.
























Select port 22, SSH etc. Just normal terminal access.

Hit Open.

In the 1st time you SSH, it will prompt an Security Alert in Putty.
Hit Yes to ignore it and log in to the Pi.

Default Logins:-

Log in as: pi
Password: raspberry

After logged in, enter the following command in terminal to access Pi's software configuration tool.

sudo raspi-config

Select Expand Filesystem to use all the space in SD card for root partition.

Hit Ok for the next dialog box and it will ask to reboot. Hit Ok and start a new SSH session after reboot.

Now enter following commands to download & update packages.

sudo apt-get update
sudo apt-get dist-upgrade

To view the available space in memory enter following command anytime in terminal.

df -h

After packages are updated, enter following commands to clean the downloaded update packages to free space & reboot.

sudo apt-get clean
sudo reboot

Install TightVNC to Access Desktop

Enter following commands to install and run TightVNC

sudo apt-get install tightvncserver
tightvncserver

It will ask a password to the remote session. It will be used to login to the Pi via TightVNC. After confirming that it will ask a view only password. You can ignore that.

Remember to enter "tightvncserver" command to start a session with Pi everytime you reboot before accesing through TightVNC.

Now install TightVNC on your native PC from here.

Now open TightVNC from your PC and start a session to your Pi by giving IP address with a : followed by a 1 for the session like shown in the screen capture.


Hit Connect and it will ask the password. Give the password entered a short while ago and hit OK




Now you are on the desktop of the Pi.
Now it's only a GUI. You can move around easily and customize as you like.

From upper right hand corner, you can see the network icon on the tray. Click on it to connect Wifi network too using your Wifi Key. You can also give static IP from here too.





Go to Menu > Preferences > Raspberry Pi Configuration

You can change many important things here like Hostname, Password, Enable Interfaces, Overscan, Date and Time etc and reboot the Pi to make the changes effective.

Tuesday, April 19, 2016

I have only 1 pendrive of 16 GB. So I am going to create 3 types of partitions in it so that I can use my pendrive as a normal data traveler + Linux security toolbox which I can bring anywhere easily.

10 GB of NTFS for normal day to day use as the data traveler
3 GB of FAT32 to install Kali Linx
1.5 GB of ext4 to persistence use

If you don't want your pendrive to use as a data traveler, you need to create 2 types of partitions only. Which are the FAT32 one & the ext4 one. Since it is a 16 GB pendrive it is a waste of doing so.

Download Mini Partition Wizard from here.

Open Mini Partition Wizard. The 1st look will be like the following.
(click on the image to see the full size)



My pendrive is empty and it has a default NTFS partition.

Creating the 10 GB NTFS Partition as a Data Traveler

Right click on your pendrive & select Move/Resize

Give these settings & hit ok















Creating a 3 GB FAT32 Partition for Kali Linux


Right click on unallocated space & select create & click yes

Give these settings as in the screen shot and hit ok
















Creating a 1.5 GB ext4 Partition for Persistence

Right click on unallocated space & select create & click yes

Give these settings as in the screen shot and hit ok
















Now everything will be like this.










Now all the partitions have been created. Let's apply the changes now.

After applying the changes you may see that the drive letter D: of the FAT32 partition is gone. So without a letter Windows will not identify the partition. So we have to do some changes to make it work form here.

1st delete the NTFS partition & give a letter to the FAT32 partition & hit Apply.

Now It will be like the following.









In My Computer the drive will look like the following.



Installing Kali

Download Kali ISO from their website. I downloaded the 32-bit full version of 2.6 GBs wich is compatible with most computers.

Now download Universal USB Installer from here























Open it, Select the ISO file and other parameters like this capture and hit create.

Wait for few minutes till it completes its job.

Now go to Mini Partition Wizard again & right click on FAT32 partition & select change letter & select none. Right click on the FAT32 partition again and select set active. It is used to identify the partition with the OS boot files when you boot from the pendrive later.

Right click on unallocated space & select create & click yes
Give these settings as in the screen shot and hit ok






Now everything will be like following.









Booting Kali from Pendrive

Now it's the time to reboot the PC and select USB drive in boot options.

Choose the option "Live USB Persistence"















Now don't click on the "persistence" icon on the screen.

Go to terminal and enter the following commands

Make a directory on the filesystem to mount your USB
mkdir -p /mnt/usb

To findout which partition of your drive you'll use (for mine it's sdb3)
fdisk -l

Mount the partition on the directory you made
mount /dev/sdb3 /mnt/usb

Add a configuration file to enable persistence
echo "/ union" > /mnt/usb/persistence.conf

Unmount the partition and reboot
umount /dev/sdb3 && reboot





























After the reboot select USB drive in boot options & again choose the option "Live USB Persistence"
From now onward every config you do will be saved and it's more like using a dedicated Linux box.

Also you have your 10 GB pendrive for day to day use as a data traveler. cheers..!!