Professional Documents
Culture Documents
Basic Linux Networking Commands You Should Know
Basic Linux Networking Commands You Should Know
It's FOSS
Basic Linux Networking Commands You Should Know
Last updated September 8, 2016 By Abhishek Prakash (https://itsfoss.com/author/abhishek/)
(https://i0.wp.com/itsfoss.com/wp-content/uploads/2016/06/Basic-
Networking-Commands-Linux.jpg?ssl=1)
https://itsfoss.com/basic-linux-networking-commands/ 1/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
It’s not every day at It’s FOSS that we talk about the “command line side” of
Linux. Basically, I focus more on It's
the FOSS
desktop side of Linux. But as some of
you readers pointed out in the internal survey (exclusive for It’s FOSS
newsletter subscribers), that you would like to learn some command line
tricks as well. Cheat sheets were also liked and encouraged by most readers.
For this purpose, I have compiled a list of the basic networking commands in
Linux. It’s not a tutorial that teaches you how to use these commands,
rather, it’s a collection of commands and their short explanation. So if you
already have some experience with these commands, you can use it for
quickly remembering the commands.
You can bookmark this page for quick reference or even download all the
commands in PDF for o ine access.
I used FreeBSD in the computer networking course but the UNIX commands
should work the same in Linux also.
347
https://itsfoss.com/basic-linux-networking-commands/ 2/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
Connectivity:
It's FOSS
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.
https://itsfoss.com/basic-linux-networking-commands/ 3/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
It's FOSS
Suggested How Much Swap Should You Use in Linux?
read
(https://itsfoss.com/swap-size/)
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 tra c 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)
https://itsfoss.com/basic-linux-networking-commands/ 4/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
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 les 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
https://itsfoss.com/basic-linux-networking-commands/ 5/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
(https://itsfoss.com/how-to-solve-disk-mount-error-in-ubuntu/)
Switching:
ifcon g sl0 srcIP dstIP : con gure 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-con guration : to see the current con gurations
con gure terminal : to enter in con guration mode
exit : in order to go to the lower con guration 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
https://itsfoss.com/basic-linux-networking-commands/ 6/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
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
https://itsfoss.com/basic-linux-networking-commands/ 7/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
Share via:
347
https://itsfoss.com/basic-linux-networking-commands/ 8/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
It's FOSS
5 comments
Newest comments first
Comment as a guest:
per
9 months ago
helpful ;)
Vote:
DK
1 year ago
add one,
347
two example which can help to understand early
https://itsfoss.com/basic-linux-networking-commands/ 9/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
blogging-is-fun.com
2 years ago
Vote:
tom0mason
2 years ago
Your —
Vote:
347
https://itsfoss.com/basic-linux-networking-commands/ 10/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
Are you using something on your browser to stop scripts from running?
Vote:
Subscribe to comments
(https://www.facebook.com/i EPRGUJrEE1itjpH6A)
347
tsfoss/)
https://itsfoss.com/basic-linux-networking-commands/ 11/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
Privacy Policy
(https://itsfoss.com/privacy-
policy/)
347
https://itsfoss.com/basic-linux-networking-commands/ 12/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS
COPYRIGHT © 2019 IT'S F.O.S.S (PART OF CHMOD777 MEDIA TECH PVT LTD)· BUILT ON GENESIS FRAMEWORK
It's FOSS
(HTTP://WWW.SHAREASALE.COM/R.CFM?B=346198&U=747593&M=28169&URLLINK=&AFFTRACK=) AND POWERED BY
UPCLOUD (HTTPS://WWW.UPCLOUD.COM/REGISTER/?PROMO=ITSFOSS)
347
https://itsfoss.com/basic-linux-networking-commands/ 13/13