Labels

Showing posts with label Linux Shell Commands. Show all posts
Showing posts with label Linux Shell Commands. Show all posts

Range of IPS on single Ethernet

How to create a range of ip addresses on ethx. Create a range file in /etc/sysconfig/network-scripts
[root@daddylinux~]# cd /etc/sysconfig/network-scripts 
[root@daddylinux~]# nano  ifcfg-eth0-range1 

Enter this Parameters
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:04:75:D4:C8:F9
IPADDR_START=192.168.0.6
IPADDR_END=192.168.0.10
CLONENUM_START=1
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet  


CLONENUM_START -- interface clone number to start using for this range. # eg "1"
Which would start at eth0:1

Change Default User Home Directory While Adding A New User

By default, when we create or add users to Linux System, user’s default home directory is created to /home. To change default directory to /opt/, we need to change few settings as mentioned below:

STEP 1: Open /etc/default/useradd

# nano /etc/default/useradd

The default home directory defined by HOME variable, find line that read as follows:

HOME=/home replace to HOME=/opt/

Save and close the file. Now you can add user using regular useradd command:

# useradd uddika
# passwd -d uddika

Verify user information:

# finger uddika
Output:
Login: uddika Name: uddika
Directory: /opt/uddika Shell: /bin/bash
Never logged in.
No mail.
No Plan.

route add in Linux

Route manipulates the kernel’s IP routing tables.  Its primary  use  is to  set up static routes to specific hosts or networks via an interface after it has been configured with the ifconfig program.

When the add or del options  are  used,  route  modifies  the  routing tables. Without these options, route displays the current contents of the routing tables.

Add static route using “route add”:
# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0

If you want persistent static route, you need to edit /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface.

# vim /etc/sysconfig/network-scripts/route-eth0
GATEWAY0=192.168.1.1
NETMASK0=255.255.255.0
ADDRESS0=192.168.100.0

Save and close the file. Restart networking:
# service network restart

Verify new routing table by,
# route –n or # netstat –nr

How To Setup Default umask Under Linux?

Umask is the number subtracted from the standard permissions when creating a file. Example: each new folder is by default created with 777, so when umask is set to 022, the result is that the permissions will be 777 – 022 = 755.

Most of the time umask will already be set by your distro to 022 but you can change it if you like. You can see what umask value is set with:

# umask
0022

If you want to change umask for temporally,

# umask 0044

Note: These value will stay until you log out and then return to its default value.
To make it permanent, edit /etc/bashrc or to your ~/.bash_profile.

For more information Click here

Assigning multiple Virtual IPs to a NIC

Assigning a virtual IPs to a NIC is a very easy task either you use the system-config-network tool or just do some text file editing. The script ifconfig can also be used to create a virtual network interface, but this would not be permanent since the changes ifconfig makes do not survive a reboot. Here we will use text based method to assign multiple IPs.

My default network configuration file is located at /etc/sysconfig/network-scripts/ifcfg-eth0 and looks like as below:

DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=00:00:00:00:00:00
IPADDR=192.168.0.1
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
TYPE=Ethernet
GATEWAY=192.168.0.254

Changing the primary IP address of a CentOS

How to change the primary/main IP address of a CentOS host in no-time! Open up the config for your primary network interface, most commonly called eth0:

[root@daddylinux~]#nano -w /etc/sysconfig/network-scripts/ifcfg-eth0

In there you'll find something along the lines of this:

DEVICE=eth0                                                                   
BOOTPROTO=static                                                              
HWADDR=XX:ee:7c:6e:XX:XX                                                      
IPADDR=XX.XX.XXX.XXX                                                           
NETMASK=255.255.255.0                                                         
ONBOOT=yes

NB: I have obfuscated the MAC address (HWADDR) and the IP address in this example, replacing some of the real numbers/letters with X's instead. Make sure to keep the HWADDR intact.

Now, to change the IP address of the host - we simply change the value for IPADDR, then save our file. (CTRL + X, y for yes, enter to keep the same filename.)

Note: If you are changing to an IP on a different subnet and need to change your default gateway, this can be configured under /etc/sysconfig/network

Look over any changes you have made to these files and make sure the information is absolutely correct. WARNING: Typo's here could leave your machine/server unavailable if you are connecting to it remotely and apply the changes (in the next step) without double checking them.

Once you have made your changes, you can restart the network service to apply the new IP address:

[root@daddylinux~]# service network restart

source : centosforge.com

Setting / Changing hostname of a CentOS host

This basic guide shows you how to change the hostname of a CentOS install using your favorite editor from the command line.

Open the file /etc/sysconfig/network using your favorite editor, auted as root or using sudo. We'll use nano for this example.

[root@daddylinux~]# nano -w /etc/sysconfig/network

The file will contain something along the lines of this:

NETWORKING="yes"
GATEWAY="10.0.0.1"
HOSTNAME="www.example.com"

User and Group management command

  • Create a new user account
[root@daddylinux~]# useradd uddika
[root@daddylinux~]# passwd uddika
Changing password for user uddika.
New UNIX password: ******
Retype new UNIX password: *****
passwd: all authentication tokens updated successfully.
  • Multisession Login(Users can login same time)
Alt+F2
Then give a username and password

Count the login users
[root@daddylinux~]# who

Command History

01. Last thousand command display
[root@daddylinux~]# history |more

02. Last ten command display
[root@daddylinux~]# history 10

Once you logout or shutdown your pc your current command history will be saved in to a hidden file in your home folder.

03. See a hidden file
[root@daddylinux~]# cd
[root@daddylinux~]# cat .bash_history

System Information Command

01. Print all information
[root@daddylinux~]# uname –a

02. Print the kernel name
[root@daddylinux~]# uname –s

03. Print the network node hostname
[root@daddylinux~]# uname –n

04. Print the kernel release
[root@daddylinux~]# uname -r

05. Print the kernel version
[root@daddylinux~]# uname -v

File Folder Searching Commands

01. Search for all data (System / Personal)
[root@daddylinux~]#locate filename

02. For any data
Syntax - [root@server ~]# find location option parameterAccordingToOption
[root@daddylinux~]# find / -name ‘inittab’

03. To search system files and there manuals
Syntax - [root@daddylinux~] #whereis filename
[root@daddylinux~]# whereis inittab

04. To locate system commands only
[root@daddylinux~]# which cal

Storage Device Capacity Measuring Commands

01. Hard Disk Drive Storage Measuring Commands
[root@daddylinux~]# df –hT /

02. Boot Partition Storage Measuring Commands
[root@daddylinux~]# df –hT /boot

Removable Media Storage Measuring Commands (First you have to mount it)

03. CD/DVD/CD-RW/DVD-RW Storage Measuring Commands
[root@daddylinux~]# df –hT /dev/scd0

04. Floppy Disk Drive Storage Measuring Commands
[root@daddylinux~]# df –hT /dev/fd0

05. USB Storage Measuring Commands
[root@daddylinux~]# df –hT /dev/sdb1

06. Folder Storage Measuring Commands
[root@daddylinux~]# du –h /etc (Display all file and folder details)
[root@daddylinux~]# du –hs /etc (Display folder details only)

07. File Storage Measuring Commands
[root@daddylinux~]# du –h /boot/grub/grub.conf

Mounting a USB pen

01. Create a mount point – A place to load the data structure of the storage device (One time only)
[root@daddylinux~]# mkdir /media/usb

02. See a mount point
[root@daddylinux~]# ls -l /media

03. Fix the pen and verify the device driver assigned (sdb, sdc, sdd)

04. Mounting the USB
[root@daddylinux~]# mount /dev/sdb1 /media/usb

05. See the pen drive data
[root@daddylinux~]# cd /media/usb
[root@daddylinux~]# ls –l

06. Before you unplug the pen
[root@daddylinux~]# cd
[root@daddylinux~]# umount /dev/sdb1

Mounting a Floppy Disk

01. Create a mount point – A place to load the data structure of the storage device (One time only)
[root@daddylinux~]# mkdir /media/floppy

02. See a mount point
[root@daddylinux~]# ls -l /media

03. Verify the device driver assigned to your Floppy Disk Driver
[root@daddylinux~]# ls -l /dev/fl*
eg - /dev/fd0 , /dev/fd1

04. Mounting the Floppy
[root@daddylinux~]# mount /dev/fd0 /media/floppy

05. See the floppy drive data
[root@daddylinux~]# cd /media/floppy
[root@daddylinux~]# ls –l

06. Before you take out the floppy
[root@daddylinux~]# cd
[root@daddylinux~]# umount /dev/fd0

Mounting a ROM drive

01. Create a mount point – A place to load the data structure of the storage device (One time only)
[root@daddylinux~]# mkdir /media/cdrom

02. See a mount point
[root@daddylinux~]# ls -l /media

03. Verify the device driver assigned to your ROM
[root@daddylinux~]# ls -l /dev/cd*
eg - /dev/scd0 , /dev/scd1 , /dev/scd2

04. Mounting the ROM
[root@daddylinux~]# mount /dev/scd0 /media/cdrom

05. See the ROM data
[root@daddylinux~]# cd /media/cdrom
[root@daddylinux~]# ls –l

06. To take out the media
[root@daddylinux~]# cd
[root@daddylinux~]# eject
[root@daddylinux~]# eject /dev/scd0

07. To take in the media
[root@daddylinux~]# eject –t
[root@daddylinux~]# eject -t /dev/scd0

Object management command

Files (Text Base)

Create new file

[root@daddylinux~]#nano filename
[root@daddylinux~]#nano /etc filename
[root@daddylinux~]#touch filename
[root@daddylinux~]#touch /etc filename

To edit file

[root@daddylinux~]#nano filename

Directory browsing and listing commands

Directory listing commands

01. See a current location (print work directory)
[root@daddylinux~]# pwd

02. List content in the folder
[root@daddylinux~]# ls
[root@daddylinux~]# tree

03. List all content in the folder (Hidden file)
[root@daddylinux~]# ls -a
[root@daddylinux~]# tree -a