Sign inSign up

marlabsdocker/lesson15

By marlabsdocker

•Updated over 8 years ago

Introduction to Linux. Lesson 15. Networking Commands Example in Unix and Linux

0

0

marlabsdocker/lesson15 repository overview

⁠Networking Commands Example in Unix and Linux.

These are most useful commands in my list while working on Linux server , this enables you to quickly troubleshoot connection issues e.g. whether another system is connected or not , whether another host is responding or not and while working for FIX connectivity for advanced trading system this tools saves quite a lot of time .

• finding host/domain name and IP address - hostname • test network connection – ping • getting network configuration – ifconfig • Network connections, routing tables, interface statistics – netstat • query DNS lookup name – nslookup • communicate with another hostname – telnet • outing steps that packets take to get to network host – traceroute • view user information – finger • checking status of destination host - telnet

⁠Example of Networking commands in Unix

let's see some example of various networking command in Unix and Linux. Some of them are quite basic e.g. ping and telnet and some are more powerful e.g. nslookup and netstat. When you used these commands in a combination of find and grep you can get anything you are looking for e.g. hostname, connection endpoints, connection status etc.

hostname hostname with no options displays the machine's hostname hostname –d displays the domain name the machine belongs to hostname –f displays the fully qualified host and domain name hostname –i displays the IP address for the current machine

ping It sends packets of information to the user-defined source. If the packets are received, the destination device sends packets back. Ping can be used for two purposes

  1. To ensure that a network connection can be established.
  2. Timing information as to the speed of the connection.

If you do ping www.yahoo.com⁠ it will display its IP address. Use ctrl+C to stop the test.

ifconfig View network configuration, it displays the current network adapter configuration. It is handy to determine if you are getting transmit (TX) or receive (RX) errors.

netstat Most useful and very versatile for finding a connection to and from the host. You can find out all the multicast groups (network) subscribed by this host by issuing "netstat -g"

netstat -nap | grep port will display process id of application which is using that port netstat -a or netstat –all will display all connections including TCP and UDP
netstat --tcp or netstat –t will display only TCP connection netstat --udp or netstat –u will display only UDP connection netstat -g will display all multicast network subscribed by this host.

nslookup If you know the IP address it will display hostname. To find all the IP addresses for a given domain name, the command nslookup is used. You must have a connection to the internet for this utility to be useful, e.g.

$nslookup blogger.com

You can also use the nslookup to convert hostname to IP Address and from IP Address from the hostname.

traceroute A handy utility to view the number of hops and response time to get to a remote system or website is traceroute. Again you need an internet connection to make use of this tool.

finger View user information, displays a user’s login name, real name, terminal name and write status. this is pretty old Unix command and rarely used nowadays.

telnet Connects destination host via the telnet protocol, if telnet connection establishes on any port means connectivity between two hosts is working fine.

$ telnet hostname port

will telnet hostname with the port specified. Normally it is used to see whether the host is alive and the network connection is fine or not.

⁠Finding IP address from hostname in UNIX and Linux

If you are working in UNIX network and have lots of machine in LAN (Local Area network), many times you want to know IP address of computers from hostname. Here are top 4 ways of getting IP address from hostname in Linux or UNIX machine

  1. IP address using hostname command in Unix/Linux

~/hostname -i

This is the easiest way of finding IP address of your computer but limitation is that sometime this option may or may not available in your UNIX machine e.g. I hardly find this command on Solaris and IBM AIX machines but they are mostly available on Linux Servers. also limitation of hostname is that you can not find IP address of any other machine. It's like finding IP address of localhost.

  1. IP address using ping command in UNIX or Linux

stock_trader@system:~/test ping trading_system Pinging trading_system.com [192.24.112.23] with 32 bytes of data: Reply from 192.24.112.23: bytes=32 time<1ms TTL=128 Reply from 192.24.112.23: bytes=32 time<1ms TTL=128 Reply from 192.24.112.23: bytes=32 time<1ms TTL=128

ping is another simplest way of finding IP address of localhost or any other host in network, if you know the hostname or computer-name just ping and it will display IP address associated with it. Normally pint command is used to check if a host is alive and connected with network. In above example IP address associated with trading_system is "192.24.112.23". Disadvantage of using ping command is that you can not convert IP address back to hostname.

  1. IP address using nslookup command in UNIX or Linux

stock_trader@system:~/test nslookup trading_system Name: trading_system.com Address: 192.24.112.23

nslookup is my favorite command for getting IP address form hostname, its very powerful and also available in many UNIX operating system e.g. Linux , Solaris, IBM AIX, Ubuntu or BSD. Another advantage of nslookup command is that , we can get either from hostname to IP address or from IP address to hostname. It can also be used to find IP address of your own host or any other machine in the network. In above example of nslookup we have displayed IP address associated with trading_system. If you want to find hostname form IP address you can just provide IP address instead of hostname

  1. How to find IP address using ifconfig command

ifconfig is another networking utility in UNIX or Linux which can be used to find IP address of your UNIX machine. ifconfig shows lot of information so I just grep on inet to find the IP address in below example, IP address associate with "trading_system.com" is "192.24.112.23".

trading_system.com $ /sbin/ifconfig -a | grep inet inet 192.24.112.23 netmask ffffff00 broadcast 192.24.112.255

⁠IP Address from hostname in Windows Linux and Unix.

⁠How to find IP address of your computer in Windows

Surprisingly some of above example of finding IP address from hostname will work is windows ditto. You can use ping andnslookup in exactly same way as shown above. Even hostname command is available in windows command prompt but I doubt about options "hostname -i". Another change is in command ifconfig , instead of ifconfig windows uses ipconfig command to find out the IP address of your computer in windows.

  1. How of use ipconfig command in windows to find IP address Here is an example of using ipconfig command in windows to find out IP address of our computer:

C:\Documents and Settings\stock_trader>ipconfig Windows IP Configuration Ethernet adapter Local Area Connection:

    Connection-specific DNS Suffix  . : trading_system.com
    IP Address. . . . . . . . . . . . : 192.24.112.23
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Default Gateway . . . . . . . . . : 192.24.112.254

Tag Summary

No tags have been pushed to this repository yet.