You are on page 1of 13

1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS

It's FOSS
Basic Linux Networking Commands You Should Know
Last updated September 8, 2016 By Abhishek Prakash (https://itsfoss.com/author/abhishek/)

Related: Daily Bread Mailbag: Crawford-Loma, Charlos, Andre Ward, More

(https://i0.wp.com/itsfoss.com/wp-content/uploads/2016/06/Basic-
Networking-Commands-Linux.jpg?ssl=1)

Brief: A collection of most important and yet basic Linux networking


commands an aspiring Linux SysAdmin and Linux enthusiasts must know.
 347    

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 had this list of Linux networking commands when I was a student of


Communication System Engineering. It helped me to get the  top score in
Computer Networks course. I hope it helps you in the same way.

Exclusive bonus: Download Linux networking command cheatsheet for


future reference. You can print it or save it for o ine viewing.

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.
 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

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
347 to delete all 
the entries in the
 ARP table  

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)

route add|delete [-net|-host] <destination> <gateway> (ex. route add


192.168.20.0/24 192.168.30.4) to add a route
route
 ush : it removes
347  all the routes  

https://itsfoss.com/basic-linux-networking-commands/ 4/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS

route add -net 0.0.0.0 192.168.10.2 : to add a default route


It's FOSS
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 de nes the route used from RIPv2
rtquery –n : to query the RIP daemon on a speci c 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 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

Tools and network performance analysis

ifcon g <interface> <address> [up] : start the interface


ifcon g <interface> [down|delete] : stop the interface
ethereal
 347 & : it allows you
 open ethereal
 background 
not foreground 

https://itsfoss.com/basic-linux-networking-commands/ 5/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS

tcpdump –i -vvv : tool to capture and analyze packets


It's FOSS
netstat –w [seconds] –I [interface] : display network settings and statistics
udpmt –p [port] –s [bytes] target_host : it creates UDP tra c
udptarget –p [port] : it’s able to receive UDP tra c
tcpmt –p [port] –s [bytes] target_host : it creates TCP tra c
tcptarget –p [port] it’s able to receive TCP tra c

Suggested [How To] Solve Disk Mount Error in Ubuntu


read

(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

ifcon g vlan0 create : it creates vlan0 interface


ifcon g vlan0 vlan ID vlandev em0 : it associates vlan0 interface on top of
em0,and
347 set the tags to
 ID   

https://itsfoss.com/basic-linux-networking-commands/ 6/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS

ifcon g vlan0  [up] : to turn on the virtual interface


It'ssupport
tagged Y : it adds to the port Y the FOSS 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


ltering and rewall rules works properly
ipnat
 –f347 le_name – it
writes lteringrules into le_name
 

https://itsfoss.com/basic-linux-networking-commands/ 7/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS

ipnat –l – it gives the list of active rules


It's table
ipnat –C –F – it re-initialize the rules FOSS
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 le_name : it writes ltering rules into le_name
ipf –F –a : it resets the rule table
ipfstat –I : it grants access to a few information on ltered packets, as well
as active ltering rules

I hope you nd these basic Linux networking commands collection helpful.


Questions and suggestions are always welcomed.

Share via:

352  Facebook 347  Twitter 0  Google+ 1  LinkedIn 1  Reddit 1


Shares

Abo ut Abh i she k P rak a sh


I am a professional software developer, and founder of It's FOSS. I am
an avid Linux lover and Open Source enthusiast. I use Ubuntu and
believe in sharing knowledge. Apart from Linux, I love classic
detective mysteries. I'm a huge fan of Agatha Christie's work.

 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:

Notify me when someone replies to my comment

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

Vote: It's FOSS

blogging-is-fun.com
2 years ago

nice post , lots of thing new for me!

Vote:

tom0mason
2 years ago

Your —

Exclusive bonus: Download Linux networking command cheatsheet for


future reference. You can print it or save it for offline viewing.

Link fails to go anywhere — the the address is https://itsfoss.com/basic-linux-


networking-commands/# (https://itsfoss.com/basic-linux-networking-
commands/#)

Vote:

 347    

https://itsfoss.com/basic-linux-networking-commands/ 10/13
1/16/2019 Basic Linux Networking Commands You Should Know - It's FOSS

Abhishek Prakash (https://itsfoss.com/)


It's FOSS
2 years ago

Are you using something on your browser to stop scripts from running?

Vote:

Add your comment...

Subscribe to comments

About Pages Stay in Touch with It's Communities


FOSS
About It's FOSS Exclusive Telegram Channel
(https://itsfoss.com/about/) Follow us on Facebook (https://t.me/joinchat/AAAAA

(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

Meet the team Join LinkedIn Community


(https://itsfoss.com/its-foss- Follow It's
us onFOSS
Google Plus (https://www.linkedin.com/g
team/) (https://plus.google.com/+its roups/8597839)
foss)
We Donate to FOSS Projects Linux Users Group on
(https://itsfoss.com/donatio Follow us on Instagram Facebook
ns-foss/) (https://www.instagram.com (https://www.facebook.com/
/itsfoss/) groups/LinuxUsersGroupO
cial/)
Follow us on Pinterest
Contact Pages (https://www.pinterest.fr/its Linux Users Group on
_foss/) Google Plus
Contact Us
(https://plus.google.com/co
(https://itsfoss.com/contact- Follow us on Twitter
mmunities/11634081775885
us) (https://twitter.com/itsfoss2)
8417493)

Get Featured on It's FOSS Follow us via RSS Feed


Linux Users Group on Reddit
(https://itsfoss.com/get- (https://itsfoss.com/feed)
(https://www.reddit.com/r/Li
featured-on-its-foss/)
nuxUsersGroup/)
Subscribe to Newsletter
Request a tutorial (https://itsfoss.com/subscrib
(https://itsfoss.com/request- e-to-newsletter/)
tutorial/) Policies
Subscribe to YouTube
Channel A liate Policy
(https://www.youtube.com/c (https://itsfoss.com/a liate-
/itsfoss?sub_con rmation=1) policy/)

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

You might also like