Linux Command Cheat Sheet
Linux Command Cheat Sheet
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!
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
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.
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:
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:
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.