Linux Systems and Network Administration
Linux Systems and Network Administration
Table of Contents
Introduction 0
Linux Systems Administration 1
User and Group Managment 1.1
Configurations 1.1.1
Commands 1.1.2
Lab 101 : Managing Users and Groups 1.1.3
Process Management 1.2
Commands 1.2.1
Lab 102 : Process Management 1.2.2
Job Scheduling 1.3
Lab 103 : Scheduling Jobs 1.3.1
Localization - Date, Time, Locale 1.4
Essential Systems Services 1.5
NTP 1.5.1
Web Stack Administration 2
MySQL Administration 2.1
Lab 201: Install MySQL Server and Client 2.1.1
Lab 201-1: Reset MySQL Root Password 2.1.2
Lab 202: Generate MySQL Configs using Percona Wizard 2.1.3
Apache Administration 2.2
Lab 203 : Install and Configure and attach ssl certicate to apache Jobs 2.2.1
Lab 204 :Create self signed certificate 2.2.2
PHP Web Application 2.3
Lab 205 : Install php5 2.3.1
Lab 206 : Install and setup Wordpress with Apache with MySQL Backend
Lab 206-1 : Database Backup and Restore 2.3.3 2.3.2
Nginx Administration 2.4
Lab 208 : Install and configure nginx as a reverse proxy 2.4.1
Lab 209 : Create and attach ssl certificate to nginx 2.4.2
Tomcat Administration 2.5
2
Devops Foundation - Linux Systems and Network Administration
3
Devops Foundation - Linux Systems and Network Administration
A Devops Engineer is typically someone with systems operations background with specific
skills with new tools. He/She is responsible for enabling organizations with Devops Tools
and Practices and help other team members such as Developers/QA Professionals to setup
automated workflows. They are also responsible for building, deploying, automating and
maintaining the infrastructure which not only runs the applications that the dev team is
building, but also for setting up and maintaining the internal tools for CI/CD, Monitoring,
Performance Measurement, Automated Provisioning and Configuration Management etc.
He/She is also responsible optimizing applications and systems infrastructure. And when
there are issues, he/she typically is the one who does initial troubleshooting, triaging and
escalations.
To be a well rounded Devops Engineer, one has to have a knowledge on wide breadth of
tools. Devops Engineers are typically Jack of All Trades, Master of a few. And most
essentially, they should have a good understanding of underlying operating system. Even
though role of Devops Engineer is not limitd to one OS, in most likeliness, its some flavor
GNU/Linux. More over, today's systems are interconnected with complex networking
systems. Hence, understanding of Linux as well as Computer Networks, servers as two
essential skills when it comes to Devops Engineers. This book is been written to keeping this
in mind and should serve as a essential reference for practical skills on systems and network
administrators.
LICENSE
CC BY-NC-SA 4.0
AUTHORS
Gourav Shah
Deepak Jain
Introduction 4
Devops Foundation - Linux Systems and Network Administration
Ashwini Chaudhari
Druva Ram
Introduction 5
Devops Foundation - Linux Systems and Network Administration
User Commands
The following commands are used to create, modify, delete, manipulate the properties of a
user.
USERADD
This command Add/Creates user accounts in Linux. This command can be combined with
various options
useradd Devops - Adds a user named Devops. To unlock this account you need to set a
password for this user
passwd Devops - To set the password for the newly created user
Once a new user is created, /etc/passwd file gets a new entry regarding the user created.
cat /etc/passwd | grep Devops - Shows the entry created for user "Devops" in the
passwd file
Each line in the /etc/paaswd contains 7 columns which provides us the information about the
user. It can be interpreted in the following way -
Commands 8
Devops Foundation - Linux Systems and Network Administration
USERADD command can be combined with other options to customize user creation as per
the requirement. Some of the options are -
useradd -c "Devops User" Devops - Creates a user with "Devops user" as a comment in
UserInfo field as stated above
useradd -d /project/Devops Devops - Creates a user "Devops". Home directory for the
user "Devops" is set as /project/Devops
useradd -u 619 Devops - Creates a user "Devops". UserID for the user "Devops" is set
as 619
useradd -g 719 Devops - Creates a user "Devops". GroupID for the user "Devops" is set
as 719
useradd -g g0 -G g1,g2 Devops - Adds the user "Devops" to primary group g0 and to
multiple groups(g1 and g2). You can check about the user is a part of which groups by
using the command "id Devops"
useradd -e 2016-10-01 Devops - Creates a user "Devops" with account expiry date of
October 1st,2016. Date should be mentioned in YYYY-MM-DD format. By default it is 0,
never expires
useradd -s /sbin/nologin Devops - Will add a user ‘tecmint‘ without login shell i.e.
‘/sbin/nologin‘ shell
useradd -M Devops - Creates a user "Devops" with no home directory. When you
combine useradd -m it will make sure that "Devops" user is created with Home directory
if it does not exist
USERMOD
This command is similar to useradd except it takes actions on already existing users. It
modifies the properties of already existing users . You can use this command with almost
same options as you use with command useradd.
usermod -c "Am Devops User" -u 619 -e 2016-10-01 Devops - Modifies the user
"Devops" UserInfo property as stated in the above examples
Commands 9
Devops Foundation - Linux Systems and Network Administration
usermod -l Devops_ad Devops - Modifies the user login name from Devops to
Devops_ad
usermod -L Devops - Locks the user "Devops" account. After the account lock, Login is
disabled and you will see a ! added before the encrypted password in /etc/shadow file
means password is disabled an user account is locked
USERDEL
This command removes the user accounts and files associated to the user from
Server/Workstation
userdel -r Devops - Combining userdel with the -r option removes files in the user's
home directory along with the home directory itself and the user's mail spool
userdel -f Devops - This option forces the removal of the user account, even if the user
is still logged in. This option is dangerous and may leave your system in an inconsistent
state
ID
This command is used to get the system identifications of a specific user like UID, Groups a
user belong to.
Group Commands
The following commands are used to create, modify, delete, manipulate the properties of a
group.
Commands 10
Devops Foundation - Linux Systems and Network Administration
GROUPADD
Groups are a useful tool for permitting co-operation between different users. This command
is used to add a new group to the system.
groupadd friends - Adds a group named "friends" with default settings. You can gather
more information about the group from the file /etc/group
groupadd -g 719 friends - Creates a group named "friends" set its GroupID as 719.
When used with -g and GID already exists, groupadd refuses to create another group
with existing GID
groupadd -r friends - Creates a system group which are used for system purposes
which practically means that GID is allocated from 1 to 499 if not specified
NOTE :- If you want to add an existing user to the named group, you can make use of the
gpasswd command too instead of usermod and useradd. gpasswd is used to unlock the
group and set password on the group
gpasswd friends - Unlocks the group "friends" and sets the required password.
gpasswd -a Devops friends - Add the user "Devops" to group "friends". Replacing "-a"
with "-r" command removes the user "Devops" from group "friends"
GROUPMOD
Commands 11
Devops Foundation - Linux Systems and Network Administration
When a group already exists and you need to specify any of the options now, use the
groupmod command. The logic of using groupmod is identical to groupadd as well as its
syntax.
groupmod -g 819 friends - Modifies the GroupID for the group "friends" to 819
GROUPDEL
This command is used to delete the group. There are some conditions you should take care
of before deleting a group. You may not remove the primary group of any existing user; you
must remove the user before you remove that user's primary group.
groupdel friends - Deletes the group named "friends". Below is the error if friends is the
primary group of any user
Commands 12
Devops Foundation - Linux Systems and Network Administration
$ useradd --help
$ man id
$ id --help
$ man passwd
$ man usermod
$ man userdel
dipti
pooja
ramesh
suresh
$useradd -m dipti
$useradd -m ramesh
$useradd -m suresh
$useradd -m dipti
Expected Output:
dipti:x:501:501::/home/dipti:/bin/bash ramesh:x:502:502::/home/ramesh:/bin/bash
suresh:x:503:503::/home/suresh:/bin/bash pooja:x:504:504::/home/pooja:/bin/bash
Set Password
dipti:!!:16847:0:99999:7:::
New password: *
Validate
Logout as root user, and try logging in as the user you created password for.
Also verify the contents of /etc/shadow which should have a encrypted string instead of !!
dipti:$6$t99EyAX/$3VCh3O9qjBEA7aevcRtV57B0HVNSM3WkhIXK9fe2JQMUQrsj8pxz5pD
bmrnJIoDlJimes3kd.yXNUNqKpoGpa0:16847:0:99999:7:::
Process Management 15
Devops Foundation - Linux Systems and Network Administration
2)TOP
3)PSTREE
4)FREE
5)UPTIME
6)KILL
Commands 16
Devops Foundation - Linux Systems and Network Administration
Managing Processes
PS
PS - This command is used list/see the processes that are running on the Linux
system/server. Process is a running instance of a program. There are many commands
which are used to monitor and control these processes in Linux and ps is one such
command which is used to monitor them. Below are some of the examples which show their
practical applications.
• ps -ef - List all the processes that are currently running, where -e is used to display all the
process, -f is used to display full format listing
• ps -ef | grep ssh - List all the process which are related to ssh
• ps -f -u vagrant,postfix - List the process related users vagrant and postfix. You can use
UID too to find the process related to that particular user like (#ps -f -u 500)
ps -f -p 1307 - List the process which has PID of 1307. You can list multiple process by
listing multiple PIDs separated by commas in a single command
ps aux --sort pmem - Sorts the highest memory consuming process at the bottom. You
can further dig into that highest memory consuming PID/PPID and get the Memory
percentage. You may use this data to find a memory leak. Where -v gives the
components of virtual memroy
TOP
This command is much more interactive and real-time than the ps command. This also
provides the percentage of resources actually consumed by the system.
top - Opens up an interactive session which gives information about the resource usage
After the top command displays output screen, it is like an interactive session which require
you to feed the commands to get the desired output as below
5. top -u vagrant - List the process details for a specific user. In this case it is "vagrant"
PSTREE
This command shows the processes that are running on the system too. But it is better in a
visual way than ps command. This command shows the running processes in the form of a
tree. It requires no root privileges to run this command.
pstree -a vagrant - Display the command line arguments associated with a particular
FREE
This command gives us the total amount of Free, Used Physical memory and Swap memory
of the system. It also gives us the information about the Buffers used by the Kernel.
free -m - Displays the amount of memory in MegaBytes. Amount of memory can also be
seen in different units of Data. Following are the options
1. -b for bytes
2. -k for kilobytes
3. -m for megabytes
4. -g for gigabytes
5. --tera for terrabytes
UPTIME
This command gives you a one line display of current time, for how long the system is up,
how users are logged on, system load averages
KILL
This command is used to send Terminate, Stop, Trap, Interrupt etc., signals to the process.
kill -l - Displays the list of signal numbers that you can choose from
NOTE :- Signal number can be determined by using the above mentioned command kill -l.
Signal name can be found out by the same command too. The shorthand notation of the
signal name can be found by the command kill -l signalnumber. Below is the example :-
Scheduing Jobs
Job Scheduling 24
Devops Foundation - Linux Systems and Network Administration
• #date
• #date +%D -s YYYY-MM-DD - Changes the date of the system/server (#date +%D -s 2016-
04-01)
• #date +%T -s HH:MM:SS - Changes the time on the system/server(#date +%T -s 23:26:00
-u) where "-u" is used if your system clock is set to use UTC
.#date - Displays the date and current time and time zone and it is UTC currently
.#ls /usr/share/zoneinfo/Asia - Lists all the timezones available in Asia. If you list the folder
/usr/share/zoneinfo/, you can see all the Zones available. You can choose the timezone
accordingly
.#ln -s /usr/share/zoneinfo/Asia/Calcutta localtime - Link the Calcutta file from Asia directory
to file "localtime"
.#date - Displays time from IST timezone and your timezone is changed
Below are the steps to configure NTP server on your local machine -
• #yum install ntp - Installs the NTP package on your local machine
• #vi /etc/ntp.conf - Edit the configuration as per the requirement. I have removed server
3.centos.pool.ntp.org and added the loopback address,so that even if my Internet network
goes down, I can fetch the time my local network or the hardware clock from my machine.
Further, you need to allow clients from your networks to synchronize time with this server. To
accomplish this, add the following line to NTP configuration file, where restrict statement
controls, what network is allowed to query and sync time. REPLACE NETWORK IPs
ACCORDINGLY
chkconfig ntpd on - To make NTP daemon persistent even if the machine reboots, use
chkconfig
system-config-firewall - Configure the firewall for port 123 which is used by ntp on the
NTP server/current server
NTP 28
Devops Foundation - Linux Systems and Network Administration
ntpstat - To check if the ntp service is up and running. From the image you can see
there is difference of 111ms which will reduce gradually to lower values. Another way to
cross check the service is by the command #ntpq -p which shows the pool of ntp
servers your server is connected to.
vi /etc/ntp.conf - Enter the IP address of NTP server we have configured above, in the
ntp.conf file of Client server. Add "prefer" in the entry you make in the ntp.conf file to use
configured NTP server. Rest of the servers are used just as backup if your NTP server
goes down.
chkconfig ntpd on - To make NTP daemon persistent even if the machine reboots
ntpstat - With this you can see that your Client server is synchronised with your own
NTP server
NTP 29
Devops Foundation - Linux Systems and Network Administration
MySQL
1. Install MySQL Server
2. Examine the MySQL Configurations
3. Generate MySQL Server Configurations using Percona’s Tool.
4. Install and Configure MySQL Admin
5. Connect to MySQL Database
6. Create a database and Tables
7. Query Data - SELECT
8. Modify Data - UPDATE/ALTER
9. Backup MySQL Database
Apache
10. Install Apache Web Server with Default Virtual host
11. Examine Apache Configurations
12. Create Virtual Hosts
13. Add Redirect and Rewrite Rules with Apache
14. Configure SSL with Apache
PHP Application
15. Install PHP
16. Configure PHP with Apache
17. Install and setup Wordpress with Apache with MySQL Backend
Nginx
18. Install Nginx
19. Examine Nginx Configurations
20. Configure Nginx as Load Balancer/ Reverse Proxy
21. Configure SSL Certificate with Nginx
Tomcat
Web Stack Administration 30
Devops Foundation - Linux Systems and Network Administration
Validate
sudo service mysqld status
d to logout
Validate
Visit to Percona
site(https://tools.percona.com)
Percona Tools
Install apache
sudo yum install httpd
Note :- if you are not able to access check firewall(iptables). Sudo service iptables
stop .
Lab 203 : Install and Configure and attach ssl certicate to apache Jobs 38
Devops Foundation - Linux Systems and Network Administration
<VirtualHost *:80>
ServerAdmin root
ServerName schoolofdevops.org
ServerAlias www.schoolofdevops.org
DocumentRoot /var/www/schoolofdevops/
</VirtualHost>
Lab 203 : Install and Configure and attach ssl certicate to apache Jobs 39
Devops Foundation - Linux Systems and Network Administration
<VirtualHost *:443>
ServerAdmin root
ServerName schoolofdevops.org
ServerAlias www.schoolofdevops.org
DocumentRoot /var/www/schoolofdevops/
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key
</VirtualHost>
Lab 203 : Install and Configure and attach ssl certicate to apache Jobs 40
Devops Foundation - Linux Systems and Network Administration
Note:- you will be asked to enter a specific passphrase. Be sure to note this
phrase carefully
"Common Name" :- Enter your official domain name here or, if you don't have one yet,
your site's IP address.
Note:- In the event that nginx crashes or needs to reboot, you will always have to
re-enter your passphrase to get your entire web server back online. So to avoid it
remove the passphrase
Install php
2. installed mysql-server
follow this lab to install and configure mysql
3. install php5
follow this link to install php5
cd /var/www/html
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
chown -r apache:apache wordpress
rm -rf latest.tar.gz
Lab 206 : Install and setup Wordpress with Apache with MySQL Backend 44
Devops Foundation - Linux Systems and Network Administration
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');
Lab 206 : Install and setup Wordpress with Apache with MySQL Backend 45
Devops Foundation - Linux Systems and Network Administration
Lab 206 : Install and setup Wordpress with Apache with MySQL Backend 46
Devops Foundation - Linux Systems and Network Administration
USE mysql
DROP DATABASE WORDPRESS;
Restore
mysql -u root -p < /opt/wordpress_backup.sql
#!/bin/bash
current_date=`date +%Y-%m-%d`
sudo mkdir -p ~/wordpress_backup
cd ~/wordpress_backup
sudo mysqldump -u root -ppassword wordpress > wrodpress_backup_${current_date}.sql
Restart Apache and validate service httpd restart netstat -pan | grep 8080
[Output: tcp 0 0 :::8080 :::* LISTEN 10170/httpd]
2. Install nginx
sudo yum install nginx
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:8080/; #add you IP of apche server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
4. Do a configuration test
sudo service nginx configtest
ssl on;
ssl_certificate /etc/httpd/ssl/server.crt;
ssl_certificate_key /etc/httpd/ssl/server.key;
location / {
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Note:- if you are using 443 port on apache then change the port to something else like
listen 445
1. install java
sudo yum install java-1.7.0-openjdk
2. install tomcat
sudo yum install tomcat
Note:- now if you click on server setup or other option it you will have to pass the
above credential
Placeholder
Networking 59
Devops Foundation - Linux Systems and Network Administration
placeholder
Lab
ping, ping6:-
send ICMP ECHO_REQUEST to network hosts. It is use to find connectivity between two
nodes. Ping uses ICMP protocol. ping6 is IPv6 version of ping, and can also send Node
Information Queries (RFC4620).
Usage:-
ping [-aAbBdDfhLnOqrRUvV] [-c count] [-F flowlabel] [-i interval] [-I interface] [-l preload] [-m
mark] [-M pmtudisc_option] [-N node‐info_option] [-w deadline] [-W timeout] [-p pattern] [-Q
tos] [-s pack‐ etsize] [-S sndbuf] [-t ttl] [-T timestamp option] [hop ...] destination
Options:-
1. ping IP_addr/domain_name
By default ping without any option uses to check network connection between two nodes by
sending & receiving packet to & from nodes.
2. ping –a IP_addr/domain_name
Ex. ping –a www.google.com
Audiable ping, it gives beep after every packet transmittion & reception.
3. ping domain_name
Ex. ping www.google.com
This is used to ping increase/decrese time interval, as mention in command. By default ping
takes 1sec interval to send packets but with this utility we can increase/decrease its time
interval.
command cannot stop automatically we have to terminate it with CTRL+c. But with this utility
we can specify no. of packet count ping can send , once it done it stop automatically.
6. ping –f IP_addr/domain_name
Ex. ping –f www.google.com
Flood ping. here it send “.” For every ECHO_REQUEST & received backspace for every
ECHO_REPLY. So increases output, ping can send thousands of packets in few seconds.
If preload option is specified then ping sends that many packets only not waiting for reply.
Preload value more than 3 sudo privileges requires.
You may specify up to 16 ``pad'' bytes to fill out the packet you send. This is useful for
diagnosing data-dependent problems in a network. For example, -p ff will cause the sent
packet to be filled with all ones.
This extends ping to send a packet out based on a given mark using -m option. Useful with
policy routing to take different paths to same destination.
Ping specified with q option nothing print on screen when we terminate command it prints
only ping statistics summary.
Ping with s option , we can modify packet size of ping command. By default its range
between 56 to 100. Ping has header size is ‘28’ so packet bytes send by ping in total is =
ping packet size + ping header size.
Ping by default gives continuous output ,it cannot terminate itself , if we specify ‘w’ g with
time then ping will stop automatically after specified time interval given in command.
Time
=3998ms(@4sec)
Ping with option ‘R’ we can record & prints the network routes through which packets is sent
& received.
Select Path MTU Discovery strategy. Their are three parameter provided with MTU
discovery do/don’t/want. These are use along with packet size ,if packet size is greater than
maximum data payload depend on MTU parameter specified it takes decision to fragment
packet or not.
We can specify path to reach ping packet to destination address. But here its important if
any one path is not reachable then the ping fails to send packet to destination address.
It prints time stamp before each line in format (unix time + microseconds as in gettimeofday)
18. ping –V
This show the the current version of ping on your machine.
Lab
Tenlet:-
User interface to the TELNET protocol. telnet command belongs to DAPRA command set,
allow you to log on to remote machine. It is used for interactive communication with remote
host. When telnet command with host IP address hit on command line it open telnet
command prompt & require a password to login to another host machine. As long as we
logged in with remote machine your machine is act like dumb terminal it just provide
interface to logged in to remote machine.
With escape character there is facility we can switch between remote machine & local
machine .Default Escape character : " Ctrl + ] " Once you press this you can work with
your local machine just at start of every command you have to press exclamatory mark '!' .
we can end remote session with exit command after that we bacl to our local machine.
Telnet not secure - everything is sent in plain text be it over a local network or over the
Internet. So any one can hack your information including your password. It is old - text based
only, there are no graphics provided.
telnet is not in built functionality we have to install it from yum or apt repository.
Usage:-
telnet [-468ELadr] [-S tos] [-b address] [-e escapechar] [-l user] [-n tracefile] [host [port]]
1. telnet IP_addr
ex. telnet 192.168.2.5
with this command your able to login to remote machine provided login infirmation &
password. your local machine provide a terminal to work on remote machine using telnet
command.
3. telnet -E IP_addr
it disables the escape character functionality.If ths functionality removes it is not possible to
swich between remote machine & local machine.
with this "-l" option we can login to remote host with specific user name which must me
present at remote machine. with this command it directly promt you for password as it
already have user name with it.
6. telnet -r IP-addr
Emulate rlogin(1). In this mode, the default escape character is a tilde. Also, the
interpretation of the escape character is changed: an escape character followed by a dot
causes telnet to disconnect from the remote host. A ^Z instead of a dot suspends telnet, and
a ^] (the default telnet escape character) generates a normal telnet prompt. These codes are
accepted only at the beginning of a line.
Lab
Nmap :-
Nmap (“Network Mapper”) is an open source tool for network exploration and security
auditing. Namp determine what hosts are available on the network, what services offering by
host, what type of operating system running, type of firewall in use. It is useful uitility for
network & system administrators. The output from Nmap is a list of scanned targets, with
information on each depending on the options used. nmap command line tool to scan a
host / network, security scanning, finding open port. Nmap is available in package
repository of most of linux distributions. We have to install it.
options:-
1. nmap IP_addr.
Ex. nmap 192.168.2.8
Namp with IP address scan IP address & gives you information of services, open port, mac
address.
2. nmap domain_name
ex. nmap www.google.com
nmap scan server name & gives you IP address, list out services, open port information,
mac address.
3. nmap -v IP_addr/domain_name
Gives details information of remote host.verbose dispaly.
With the wildcard character enter we can scan entire IP address range & subnet. gives all
information of hosts which are up & down.
With nmap we can scan multiple IP address just by specifying last octect as shown in
example.
With nmap command we can scan IP address range as specified in above example.
7. nmap –A IP_addr
With option “A” menstion along with nmap it gives script scanning output, traceroute, OS
version of provided host
8. nmap -O IP_addr
[O =-osscan guess]
With option ‘O’ it gives OS information & its version of remote host.
With this command as shown in example we can exclude the IP address from scanning as
we used wildcard character to scan all 256 host in last octect.
Localhost
192.168.2.2
192.168.22.1
With file menstion along with nmap command we can scan all the IP address server host
names included in that .
With this we can scan which host are up, it find only running hosts. Its like ping utility.
with “-p” option we scan fot a specific port . we cam menstioned port no directly inside
command or we can also find along with port type AS TCP,UDP, multiple port also scan on
single command line
With this command we can find out network interfaces & route information. It is useful during
debugging.
nmap PU 192.168.2.
ex:-
Lab
Netstat:-
Print network connections, routing tables, interface statistics, masquerade connections, and
multicast memberships. It prints the information related to Linux networking subsystem. It
shows which ports are open & close, it is most useful command for network troubleshooting.
This command is useful for network administration & system administration people.
Option:-
1. netstat
netstat displays a list of open sockets. If you don't specify any address families, then the
active sockets of all configured address families it listed
Its output like that but much big in length so just pipe it with more so you can go thgough all
the list.
2. netstat –t
it shows list of programs which already have established TCP connection but, not those
which are waiting for TCP connection
3. netstat –a
4. netstat –at
it list out all the programs which are listening & established TCP connection only.
5. netstat –u
it list out all the programs which have already established UDP connection only not listening
one.
6. netstat –au
it list out all the programs which are listening & established UDP connection only.
7. netstat –l
it shows all listening sockets.(whose which are omitted by default)
8. netstat -s
Display summary statistics for each protocol. Default protocol list are TCP,UDP,ICMP & IP.
9. netstat –r
Dispaly kernel IP routing table.
10. netstat –i
Display kernel interface table. It shows network interface packet usage with MTU size.
11. netstat –c
It print the netstat information continuously. If we menstion no along with then it print after
that much duration of time
12. netstat –p
IT shows the list of services with their PID no which uses network sockets.
14. netstat –g
It displays the multicast gropup membership information for IPv4/IPv6
15. netstat –F
Print routing information from the FIB. (This is the default.)
16. netstat –n
Show numerical addresses instead of trying to determine symbolic host, port or user names.
17. Netstat –M
Display a list of masqueraded connections.
18. netstat –V
shows the current version of netstat on system.
Lab
Traceroute:-
Print the route packets trace to network host.
Usage:-
Options:-
1. traceroute domain_name/IP_addr
ex. traceroute www.google.com
It gives the route information to reach destination address. Maximum 30 hops are their whin
that limit only it provide route information. If we get asterisks * signs its because some ICMP
packets block by firewall or not respond in timely manner.(here its because i use virtualbox).
same command i run on my local machine it gives me full path as shown below:-
It gives information of mtu(maximum trasmistion unit) for hop, if firewall settings not blocking
it. In the form of F=number.
3. traceroute –V
It tells the version traceroute used on your local machine.
We know maximunm hop count is 30 we can limit that with this command with option m &
providing count along with it,so it only show that no of hops. It count from starting
incremental manner.
as shown below it just look upto first 3 hosts.(its virtual machine so its unable to dermine
path)
same output on my local machine (as its windows so "-h" oprion used with traceoute)
5. traceroute –n domain_name/IP_addr
ex. traceroute -n www.google.com
With –n option it eliminates FKDN only shows ip address, only shows output in numerical
form.
as its output on windows machine "d" option i used , as shown below its just show IP
address No FKDN .
traceroute -6 www.google.com
Explicitly force to use IPv4 or IPv6 addressing scheme for tracerouting. By default it
automatically choose protocol & resolve name.
7. traceroute -I domain_name/IP_addr
ex. traceroute -I www.google.com
8. traceroute -T domain_name/IP_addr
ex. traceroute -T www.google.com
9. traceroute -q domain_name/IP_addr
ex. traceroute -q www.google.com
Lab
Tcptraceroute:-
Is a traceroute implementation using TCP packets. Normal traceroute command uses
ICMP or UDP protocol ECHO packet with TTL. But now a days most modern machine has
firewall configured which blocks the ICMP & UDP protocol , so its not possible to trace out
destination path. However firewall allowes inbound TCP packets , so with tcptraceroute
utility it is possible to trace destination path.
It is worth noting that tcptraceroute never completely establishes a TCP connection with the
destination host. If the host is not listening for incoming connections, it will respond with an
RST indicating that the port is closed. If the host instead responds with a SYN|ACK, the port
is known to be open, and an RST is sent by the kernel tcptraceroute is running on to tear
down the connection without completing three-way handshake. This is the same half-open
scanning technique.
Usage:-
tcptraceroute [-nNFSAE] [-i ] [-f ] [-l ] [-q ] [-t ] [-m ] [-pP] ] [-s ] [-w ] [destination port] [packet
length]
Options:-
1. tcptreaceroute IP_addr/domain_server
ex. tcptraceroute www.google.com
It gives the route information to reach destination address using TCP packets.
2. tcptraceroute -n IP_addr/domain_name
It gives information in numerical form it dont display FQDN information associated with
hosts.
we can set source address from which packets send to destination address to trace route
from.
We know maximunm hop count is 30 we can limit that with this command with option m &
providing count along with it,so it only show that no of hops. It count from starting
incremental manner.
8. tcptraceroute –F domain_name/IP_addr
ex. tcptraceroute -F www,google.com
9. tcptraceroute domain_name/IP_addr
ex. tcptraceroute www.google.com 110
Set the total packet length to be used in outgoing packets. If the length is greater than the
minimum size required to assemble the necessary probe packet headers, this value is
automatically increased.
Lab
Whois:-
client for the whois directory service. it provide owner,technical contact of virtually any public
domain name. whois is protocol use for searching server of specified object. whois searches
for an object in a RFC 3912 database.If no guess can made then it will connect to
whois.networksolutions.com for NIC handles or whois.arin.net for IPv4 addresses and
network names.
Usage:-
whois [OPTION]... OBJECT..[-h host] [-p port] [-alLMmcxbBGdKrR] [-i ATTR] [-T type]
Options:-
1. whois domain_name/IP_addr
ex. whois ubuntu.com
2. whois --version
Gives version information.
4. whois –v domain_name
Verbose display. It display output in detailed manner , what is being done.
5. whois –H domain_name
It use to hide legal disclaimers information.
6. whois --help
Use for online help.
Reading List
Command Line Fu: http://www.commandlinefu.com/commands/browse
Command Line Cookbook: https://www.gitbook.com/book/minhhh/command-line-
cookbook
Ops School : http://www.opsschool.org/en/latest/
The Linux Cookbook : http://dsl.org/cookbook/cookbook_toc.html
Kernel and Systems Programming: https://www.gitbook.com/book/0xax/linux-
insides/details
References 96