Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

ifconfig 

- configure a network interface

Description

ifconfig command is used to configure the kernel-resident network interfaces. It is used at


boot time to set up interfaces as necessary. After that, it is usually needed to query and
manage network parameters. It is also required during debugging or when system tuning is
needed.

If no arguments are given, ifconfig command displays the status of the currently active


interfaces. If a single interface argument is given, it displays the status of the given interface
only; in case of -a option, it displays the status of all interfaces, even those that are down.
Otherwise, it configures an interface.
The ifconfig command prints an output when executed without arguments or with the
interface name only. If used with arguments, there is no output.
The basic ifconfig syntax looks like this
ifconfig [interface_name_optional] [arguments_optional]
Linux ifconfig Command Options

The ifconfig command works with arguments to achieve different results. Below is a list of


common ifconfig command options:

Option Description
-a Prints the configuration for all interfaces, not just the active ones.
-s Displays only a shortlist of all interfaces.
-v Prints a more detailed configuration for all interfaces.
Represents the interface's name and is accompanied by a unit number. Prints
interface_name
the configuration for a specific interface.
down Deactivates the interface.
up Activates the interface.
[IP_address_number] Assigns an IP address to a specified interface.
netmask [address] Changes the network mask for a specific interface.
broadcast [address] Sets the broadcast address for a specific interface.
mtu [number] Sets the Maximum Transfer Unit (MTU) of an interface.
promisc Enables promiscuous mode in which the interface receives all packets.
[-]promisc Disables promiscuous mode.
arp Enables the ARP protocol on a specific interface.
[-]arp Disables the ARP protocol on a specific interface.
Enables the all-multicast mode in which the interface receives all multicast
allmulti
packets.
[-]allmulti Disables the all-multicast mode.
CAT
Cat is short for concatenate. This command displays the contents of one or more files without
having to open the file for editing. It reads data from the file and gives their content as
output. It helps us to create, view, concatenate files.
1) To view a single file 
Command:  $cat filename
Output: It will show content of given filename
2) To view multiple files 
Command: $cat file1 file2
Output : This will show the content of file1 and file2.
3) To view contents of a file preceding with line numbers. 
Command: $cat -n filename
Output : It will show content with line number
4) Create a file 
Command: $ cat > newfile
Output : Will create a file named newfile
5) Copy the contents of one file to another file. 
Command: $cat [filename-whose-contents-is-to-be-copied] > [destination-filename]
Output : The content will be copied in destination file
6) Cat command can suppress repeated empty lines in output 
Command: $cat -s geeks.txt
Output : Will suppress repeated empty lines in output
7) Cat command can append the contents of one file to the end of another file. 
Command: $cat file1 >> file2
Output : Will append the contents of one file to the end of another file
8) Cat command can display content in reverse order using tac command. 
Command: $tac filename
Output: Will display content in reverse order
9) Cat command can highlight the end of line. 
Command: $cat -E "filename"
Output : Will highlight the end of line
10) If you want to use the -v, -E and -T option together, then instead of writing -vET
in the command, you can just use the -A command line option. 
Command : $cat -A "filename"
11) Cat command to open dashed files. 
Command: $cat -- "-dashfile"
Output : Will display the content of -dashfile
12) Cat command if the file has a lot of content and can’t fit in the terminal. 
Command: $cat "filename" | more
Output : Will show that much content, which could fit in terminal and will ask to show
more.
13) Cat command to merge the contents of multiple files. 
Command: $cat "filename1" "filename2" "filename3" > "merged_filename"
Output : Will merge the contents of file in respective order and will insert that content in
"merged_filename".
14) Cat command to display the content of all text files in the folder. 
Command: $cat *.txt
Output : Will show the content of all text files present in the folder.
15) Cat command to write in an already existing file. 
Command :$cat >> geeks.txt
Output: Will append the text "The newly added text." to the end of the file
The passwd command modifies passwords for user accounts and manages the password
validity period. passwd command in Linux is used to change the user account passwords.
The root user reserves the privilege to change the password for any user on the system,
while a normal user can only change the account password for his or her own account
Using the passwd command, a superuser changes and modifies settings for any user. Regular
users are only allowed to change their own password.

The general command is:

passwd <options> <username>

Options are

 -d, –delete
Delete a user’s password (make it empty). This is a quick way to disable a password
for an account. It will set the named account passwordless.
 -k, –keep-tokens
Indicate password change should be performed only for expired authentication tokens
(passwords). The user wishes to keep their non-expired tokens as before.
 -l, –lock
Lock the password of the named account.
 -u, –unlock
Unlock the password of the named account.
 -i, –inactive INACTIVE
This option is used to disable an account after the password has been expired for a
number of days. After a user account has had an expired password for INACTIVE
days, the user may no longer sign on to the account.
 -S, –status
Display account status information.
 -n, –mindays MIN_DAYS
Set the minimum number of days between password changes to MIN_DAYS.
 -x, –maxdays MAX_DAYS
Set the maximum number of days a password remains valid. After MAX_DAYS, the
password is required to be changed.
Password rule
As a general guideline, passwords should consist of 6 to 8 characters including one or more
characters from each of the following sets:
 lower case alphabetics
 digits 0 thru 9
 punctuation marks
File
 /etc/passwd
User account information.
 /etc/shadow
Secure user account information.
 /etc/pam.d/passwd
PAM configuration for passwd.
Exit values
The passwd command exits with the following values:
0 success
1 permission denied
2 invalid combination of options
3 unexpected failure, nothing done
4 unexpected failure, passwd file missing
5 passwd file busy, try again
6 invalid argument to option

EXAMPLES:
Change your own password
To change the current user’s password i.e. your own account password, just enter the passwd
command without any options.
Command: passwd
2. Create root password
Many Linux distributions come without a root password set. The only way to access root
account is through sudo or su commands. This is because a default password like ‘toor’
would make a system vulnerable to attackers. You must be a sudo user to create root
password:

Command: sudo passwd root

3. Change other user’s password


You can change user password in Linux using passwd command as root or with sudo.
Command: sudo passwd user_name
4. Check password status
You can check the status of a user’s password like this:
Command: sudo passwd -S user_name
5. Check password status for all accounts
You may also check the password status of all users accounts on your system:
Command: sudo passwd -Sa
6. Force user to change password at next login
You can use the -e option to expire user’s password immediately. This will force user to
change the password at next login.
Command: sudo passwd -e user_name
7. Lock or unlock user accounts
The -l option of passwd command allows you to lock a user account in Linux:
Command: sudo passwd -l user_name
8. Delete password from an account and make it password-less
I don’t see any practical use case for this but you can delete password for a certain account.
This way, that account won’t need password for accessing the system. This is not good for
security.
Command: sudo passwd -d user_name

PING
PING (Packet Internet Groper) command is used to check the network connectivity
between host and server/host. This command takes as input the IP address or the URL and
sends a data packet to the specified address with the message “PING” and get a response
from the server/host this time is recorded which is called latency. Fast ping low latency
means faster connection. Ping uses ICMP(Internet Control Message Protocol)  to send
an ICMP echo message to the specified host if that host is available then it sends ICMP
reply message. Ping is generally measured in millisecond every modern operating system
has this ping pre-installed.

The basic ping syntax includes ping followed by a hostname, a name of a website, or the


exact IP address.

ping [option] [hostname] or [IP address]

Some of the most useful and used options of the ping command are the following:

-c: With this option, you can specify how many packets to send.

-s: This option allows you to change the default size of the packets.

-v: verbose mode.

-w: Specifies a time in seconds that the execution of the command will end. No matter
how many packets the command has sent or received.

-i: With this option, you can specify the network interface to use

Now let see the PING command : 


PING Version: 
To get ping version installed on your system. 
 sudo ping -v
To stop pinging we should use ctrl+c otherwise it will keep on sending packets. 
 

 
 min: minimum time to get a response
 avg: average time to get responses
 max: maximum time to get a response
Controlling the number of pings: 
Earlier we did not define the number of packets to send to the server/host by using -c option
we can do so. 
 Controlling the size of packets send: 
Earlier a default sized packets were sent to a host but we can send light and heavy packet
by using -s option. 
Changing the time interval: 
By default ping wait for 1 sec to send next packet we can change this time by using -
i option.
To get only summary: 
To only get the summary about the network use -q option  
To Timeout PING: 
To stop pinging after sometime use -w option. 
Flooding with PING: 
To send packets as soon as possible. This is used to test network performance. 
 
To Add Timestamp 
It is current time of event recorded by a machine over a network. It works by using TS
option of IP packet. 
We have three option with it 
1. tsonly (timestamp only)
2. tsandaddr (timestamp and address)
3. tsprespec (timestamp pre-specified for multiple hosts)
 
Time to wait for response: 
Sets time to wait for a response.  
To fill packet with data: 
We can fill data in packet using -p option. Like -p ff will fill packet with ones. 
Path MTU discovery: 
It is a simple protocol to find out the maximum MTU(Maximum Transmission Unit) a TCP
path can take. 
We use an option with -m do (prohibit fragmentation), want (do PMTU discovery,
fragment locally when packet size is large), or dont (do not set DF flag). 
Specify TTL(Time To Live): 
It is maximum hop a packet can travel before getting discarded. A value 0 will restricts
packet to same host. 

You might also like