0% found this document useful (0 votes)
205 views9 pages

Linux Command Cheat Sheet

This document provides a summary of basic Linux networking commands: - ping sends ICMP echo messages to check if a host is up. telnet connects to ports on remote hosts. arp translates IP addresses to MAC addresses. - netstat prints routing tables. route sets static routes. routed and gated run routing protocols. traceroute traces the route packets take. - nslookup translates between IP addresses and domain names. ftp transfers files between hosts. rlogin logs into remote hosts virtually.

Uploaded by

Pankaj Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
205 views9 pages

Linux Command Cheat Sheet

This document provides a summary of basic Linux networking commands: - ping sends ICMP echo messages to check if a host is up. telnet connects to ports on remote hosts. arp translates IP addresses to MAC addresses. - netstat prints routing tables. route sets static routes. routed and gated run routing protocols. traceroute traces the route packets take. - nslookup translates between IP addresses and domain names. ftp transfers files between hosts. rlogin logs into remote hosts virtually.

Uploaded by

Pankaj Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Linux Command Cheat Sheet

Basic Linux commands


Command Description
ls Lists all files and directories in the present working directory
ls -R Lists files in sub-directories as well
ls -a Lists hidden files as well
Lists files and directories with detailed information like
ls -al
permissions,size, owner, etc.
cd or cd ~ Navigate to HOME directory
cd .. Move one level up
cd To change to a particular directory
cd / Move to the root directory
cat > filename Creates a new file
cat filename Displays the file content
Joins two files (file1, file2) and stores the output in a new file
cat file1 file2 > file3
(file3)
mv file "new file path" Moves the files to the new location
mv filename new_file_name Renames the file to a new filename
Allows regular users to run programs with the security privileges
sudo
of the superuser or root
rm filename Deletes a file
man Gives help information on a command
Gives a list of all past commands typed in the current terminal
history
session
clear Clears the terminal
Creates a new directory in the present working directory or a at the
mkdir directoryname
specified path
rmdir Deletes a directory
mv Renames a directory
pr -x Divides the file into x columns
pr -h Assigns a header to the file
pr -n Denotes the file with Line Numbers
lp -nc , lpr c Prints “c” copies of the File
 lp-d lp-P Specifies name of the printer
apt-get Command used to install and update packages
Command Description
mail -s 'subject'
-c 'cc-address'
Command to send email
-b 'bcc-address'
'to-address'
mail -s "Subject"
Command to send email with attachment
to-address < Filename

File Permission commands


Command Description
ls -l to show file type and access permission
r read permission
w write permission
x execute permission
-= no permission
Chown user For changing the ownership of a file/directory
change the user as well as group for a file or
Chown user:group filename
directory

Environment Variables command


Command Description
echo $VARIABLE To display value of a variable
env Displays all environment variables
VARIABLE_NAME= variable_value Create a new variable
Unset Remove a variable
To set value of an environment
export Variable=value
variable

User management commands of linux


Command Description
sudo adduser username To add a new user
sudo passwd -l 'username' To change the password of a user
sudo userdel -r 'username' To remove a newly created user
sudo usermod -a -G GROUPNAME USERNAME To add a user to a group
sudo deluser USER GROUPNAME To remove a user from a group
Shows information of all the users logged
finger
in
Command Description
finger username Gives information of a particular user

Networking command
Command Description
SSH username@ip-address or hostname login into a remote Linux machine using SSH
To ping and Analyzing network and host
Ping hostname="" or =""
connections
Display files in the current directory of a remote
dir
computer
change directory to “dirname” on a remote
cd "dirname"
computer
put file upload ‘file’ from local to remote computer
get file Download ‘file’ from remote to local computer
quit Logout

Process command
Command Description
bg To send a process to the background
fg To run a stopped process in the foreground
top Details on all Active Processes
ps Give the status of processes running for a user
ps PID Gives the status of a particular process
pidof Gives the Process ID (PID) of a process
kill PID Kills a process
nice Starts a process with a given priority
renice Changes priority of an already running process
df Gives free hard disk space on your system
free Gives free RAM on your system
VI Editing Commands
Command Description
i Insert at cursor (goes into insert mode)
a Write after cursor (goes into insert mode)
A Write at the end of line (goes into insert mode)
ESC Terminate insert mode
u Undo last change
U Undo all changes to the entire line
o Open a new line (goes into insert mode)
dd Delete line
3dd Delete 3 lines
D Delete contents of line after the cursor
Delete contents of a line after the cursor and insert new text. Press ESC key to end
C
insertion.
dw Delete word
4dw Delete 4 words
cw Change word
x Delete character at the cursor
r Replace character
R Overwrite characters from cursor onward
s Substitute one character under cursor continue to insert
S Substitute entire line and begin to insert at the beginning of the line
~ Change case of individual character
Hope this Linux reference guide helps you!

List of basic networking commands in Linux


I used FreeBSD in the computer networking course but the UNIX commands should
work the same in Linux also.
Connectivity:

ping <host> —- sends an ICMP echo message (one packet) to a host. This may go
continually until you hit Control-C. Ping means a packet was sent from your machine
via ICMP, and echoed at the IP level. ping tells you if the other Host is Up.

telnet host <port> —- talk to “hosts” at the given port number. By default, the telnet
port is port 23. Few other famous ports are:
7 – echo port,
25 – SMTP, use to send mail
79 – Finger, provides information on other users of the network

Use control-] to get out of telnet.

Arp:

Arp is used to translate IP addresses into Ethernet addresses. Root can add and delete
arp entries. Deleting them can be useful if an arp entry is malformed or just wrong.
Arp entries explicitly added by root are permanent — they can also be by proxy. The
arp table is stored in the kernel and manipulated dynamically. Arp entries are cached
and will time out and are deleted normally in 20 minutes.

arp –a : Prints the arp table


arp –s <ip_address> <mac_address> [pub] to add an entry in the table
arp –a –d to delete all the entries in the ARP table

Routing:

netstat –r —- Print routing tables. The routing tables are stored in the kernel and used
by ip to route packets to non-local networks.
route add —- The route command is used for setting a static (non-dynamic by hand
route) route path in the route tables. All the traffic from this PC to that IP/SubNet will
go through the given Gateway IP. It can also be used for setting a default route; i.e.,
send all packets to a particular gateway, by using 0.0.0.0 in the pace of IP/SubNet.
routed —– The BSD daemon that does dynamic routing. Started at boot. This runs the
RIP routing protocol. ROOT ONLY. You won’t be able to run this without root access.
gated —– Gated is an alternative routing daemon to RIP. It uses the OSPF, EGP, and
RIP protocols in one place. ROOT ONLY.
traceroute —- Useful for tracing the route of IP packets. The packet causes messages
to be sent back from all gateways in between the source and destination by increasing
the number of hopes by 1 each time.
netstat –rnf inet : it displays the routing tables of IPv4
sysctl net.inet.ip.forwarding=1 : to enable packets forwarding (to turn a host into a
router)
route add|delete [-net|-host] <destination> <gateway> (ex. route add
192.168.20.0/24 192.168.30.4) to add a route
route flush : it removes all the routes
route add -net 0.0.0.0 192.168.10.2 : to add a default route
routed -Pripv2 –Pno_rdisc –d [-s|-q] to execute routed daemon with RIPv2 protocol,
without ICMP auto-discovery, in foreground, in supply or in quiet mode
route add 224.0.0.0/4 127.0.0.1 : it defines the route used from RIPv2
rtquery –n : to query the RIP daemon on a specific host (manually update the routing
table)

Others:

nslookup —- Makes queries to the DNS server to translate IP to a name, or vice versa.
eg. nslookup facebook.com will gives you the IP of facebook.com
ftp <host>water —– Transfer files to host. Often can use login=“anonymous” ,
p/w=“guest”
rlogin -l —– Logs into the host with a virtual terminal like telnet

Important Files:

/etc/hosts —- names to ip addresses


/etc/networks —- network names to ip addresses
/etc/protocols —– protocol names to protocol numbers
/etc/services —- tcp/udp service names to port numbers
Tools and network performance analysis

ifconfig <interface> <address> [up] : start the interface


ifconfig <interface> [down|delete] : stop the interface
ethereal & : it allows you open ethereal background not foreground
tcpdump –i -vvv : tool to capture and analyze packets
netstat –w [seconds] –I [interface] : display network settings and statistics
udpmt –p [port] –s [bytes] target_host : it creates UDP traffic
udptarget –p [port] : it’s able to receive UDP traffic
tcpmt –p [port] –s [bytes] target_host : it creates TCP traffic
tcptarget –p [port] it’s able to receive TCP traffic

Switching:

ifconfig sl0 srcIP dstIP : configure a serial interface (do “slattach –l /dev/ttyd0”
before, and “sysctl net.inet.ip.forwarding=1“ after)
telnet 192.168.0.254 : to access the switch from a host in its subnetwork
sh ru or show running-configuration : to see the current configurations
configure terminal : to enter in configuration mode
exit : in order to go to the lower configuration mode

VLAN:

vlan n : it creates a VLAN with ID n


no vlan N : it deletes the VLAN with ID N
untagged Y : it adds the port Y to the VLAN N
ifconfig vlan0 create : it creates vlan0 interface
ifconfig vlan0 vlan ID vlandev em0 : it associates vlan0 interface on top of em0, and
set the tags to ID
ifconfig vlan0  [up] : to turn on the virtual interface
tagged Y : it adds to the port Y the support of tagged frames for the current VLAN
UDP/TCP

socklab udp – it executes socklab with udp protocol


sock – it creates a udp socket, it’s equivalent to type sock udp and bind
sendto <Socket ID> <hostname> <port #> – emission of data packets
recvfrom <Socket ID> <byte #> – it receives data from socket
socklab tcp – it executes socklab with tcp protocol
passive – it creates a socket in passive mode, it’s equivalent to socklab, sock tcp,
bind, listen
accept – it accepts an incoming connection (it can be done before or after creating the
incoming connection)
connect <hostname> <port #> – these two commands are equivalent to socklab,
sock tcp, bind, connect
close – it closes the connection
read <byte #> – to read bytes on the socket
write (ex. write ciao, ex. write #10) to write “ciao” or to write 10 bytes on the socket

NAT/Firewall

rm /etc/resolv.conf – it prevent address resolution and make sure your filtering and
firewall rules works properly
ipnat –f file_name – it writes filtering rules into file_name
ipnat –l – it gives the list of active rules
ipnat –C –F – it re-initialize the rules table
map em0 192.168.1.0/24 -> 195.221.227.57/32 em0 : mapping IP addresses to the
interface
map em0 192.168.1.0/24 -> 195.221.227.57/32 portmap tcp/udp 20000:50000 :
mapping with port
ipf –f file_name : it writes filtering rules into file_name
ipf –F –a : it resets the rule table
ipfstat –I : it grants access to a few information on filtered packets, as well as active
filtering rules
I hope you find these basic Linux networking commands collection helpful. Questions
and suggestions are always welcomed.

You might also like