Network Commands in Linux

Network commands are very helpful in getting information on network interfaces, IP addresses, physical addresses, network connections, domain look up and troubleshooting network issues.

Here is the list of network commands in Linux.

curl command in Linux

curl command allows you to work with applications using HTTP, FTP, FTPS, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, FILE, POP3, IMAP, SMTP, RTMP and RTSP protocols. For example – If you want to download any file from the web server, you can use below command.

$ curl www.softpost.org

If curl is not installed on your Ubuntu machine, you can install it using below command.

$ sudo apt-get install curl

Here is the list of curl commands.

  1. $ curl www.softpost.org -> This command will download the home page of www.softpost.org and display it on standard output.
  2. $ curl -o index.html www.softpost.org -> If you want to save the file instead of viewing it on console, you can use -o option and provide the file name where you want to save downloaded file. Here -o stands for output.
  3. $ curl -O www.example.com/example.html -> If you want to save the downloaded file with same name as url, you can use -O option.
  4. $ curl https://securesite.com/login.html
  5. $ curl –insecure https://self-signed-cert.com/login.html

wget command in Linux

wget command is just like curl. Main difference is that wget command supports only HTTP, HTTPS and FTP protocols. Also curl is more widely used than wget. wget can get the urls recursively.

Here is the list of wget commands.

  1. $ wget www.softpost.org -> This command will download the home page of www.softpost.org and display it on standard output.
  2. $ wget -o index.html www.softpost.org -> If you want to save the file instead of viewing it on console, you can use -o option and provide the file name where you want to save downloaded file. Here -o stands for output.
  3. $ wget ‐‐input url-list.txt -> This command can be used to download multiple urls specified in url-list.txt file.

ping command in Linux

ping command is used to check the connection with other host
$ ping <host-name>

ping command sends the packets to  given host indefinitely. If you want to restrict the packets to be sent to the host, you can use below command. Here ping command will send only 4 packets to host.

$ ping -c 4 <host-name>

ifconfig command in Linux

ifconfig command shows the ip address and physical address of each network interface on the host.

$ ifconfig -a

Below image shows the sample output of ifconfig command. The number next to HWaddr is the physical address of network interface. The number next to inet addr is the IP address of network interface.

ifconfig-output

ifconfig-output

 

hostname command in Linux

$ hostname – This command can be used to print or set system name.

To change the name of your system, you will have to use below command.

$ hostname <new-host-name>

Also note that changes are temporary. To make the changes permanent, you will have to edit /etc/hostname file with the new host name.

dig/host/nslookup command in Linux

dig command is used for getting DNS information of domain name
$ dig www.softpost.org

Here is the sample output of dig command.

dig-command-in-linux

dig-command-in-linux

host and nslookup commands also provide similar information.

traceroute command in Linux

traceroute command is used to trace the route to Host.
$ traceroute www.softpost.org

If this command is not available in your Ubuntu system, you can use below command to install it.

$ sudo apt-get install traceroute

netstat command in Linux

netstat stands for network statistics. This command shows all network connections as well as network interface information.

To know about all tcp and udp connections, you can use below command. Here -t stands for TCP connection. -u stands for UDP connections.

$ netstat -tu

You can use below command to know all network connections on your system.

$ netstat -a

lsof command in Linux

Below command can be used to display the list of all open files including the ones used by network connections.

$ sudo lsof

To list only TCP and UDP connections, you can use below commands

$ lsof -i tcp

$ lsof -i udp

To list processes listening on specific port say 80, you can use below command.
lsof -i :80

ftp command in Linux
ftp command allows you to upload, download, manage files on FTP server

To connect to any server, type below command.
$ ftp <server-name>

Once the connection is established, you will have to enter user id and password.
Once you log in successfully, you can issue below commands.

  1. put filename – Upload a file to the server
  2. get filename – Download a file from the server
  3. mput *.txt – Put multiple files ending with .txt  on the server
  4. mget *.txt – Get multiple files ending with .txt from the server
  5. ls – Get a list of files in the current directory
  6. cd – Change directory
  7. quit – Close your ftp session

telnet command in Linux

telnet command can be used to manage the compute remotely. It is less secure as compared to ssh command. Data is transferred in plain text.

ssh command in Linux

ssh stands for Secure Shell Protocol. You can remotely login to computer and execute the commands using ssh command. Data is encrypted before transmission.

Below command will show ssh version you are using.

$ ssh -V

route/arp command in Linux

route command shows the kernel routing table. Here is the sample output.

route-command-in-linux

route-command-in-linux

arp stands for address resolution protocol. arp command shows all ARP entries in the system.

You may also like...