Updated April 18, 2023
Introduction to IP Command in Linux
The following article provides an outline for the various IP Commands in Linux. IP stands for Internet Protocol. It is a numerical value to indicate a device location and its identification in a network. The IP command is used on Linux operating systems to assign an address to a network interface and/or to configure parameters of the network interface. This command replaces the old great and now outdated command of ifconfig on modern Linux distributions. The IP command is a powerful tool that any Linux system administrator should know about configuring network interfaces. It can be used to upload or down interfaces, assign and remove ARP cache addresses and routes, and much more.
Networking Commands
Given below are some basic networking commands:
1. For getting information about the host,
- hostname: It will display a machine hostname.
- hostname -i: It will display the IP address for the current machine.
2. For knowing the connection to and fro with the host.
- netstat -g: It will display all the multicast networks subscribed by this network.
- netstat -l: It will display all listening ports.
- netstat -t: It will display all TCP connections.
3. To check connections with hosts and IP address if that is alive of not by sending packets.
ping: www.google.co.in
Here, we saw 0% packet loss, which means that the connection is established and working properly.
4. To know current network configurations:
ifconfig -a: View all configuration and settings.
5. To discover the hostname and IP address:
nslookup www.google.co.in
6. To know the number of hops and response time to get to a remote system or website:
traceroute: www.google.co.in
IP (Internet protocols), it is of two types:
- IPV4: Internet Protocol version 4 has a storage capacity of a 32-bit number. The growth of the internet and security concerns depleted IPV4 so IPV6 came into the picture.
- IPV6: Internet Protocol version 6 uses a 128-bit number as storage capacity.
So generally, an IP uniquely identifies a host or device on a network. IP ranges are divided into A, B, C, D, E classes which I am surely not going into details about as it is mostly theoretical. For example, the dotted-decimal private IP address of C class 192.168.123.132 is (in binary notation) the 32-bit number 110000000101000111101110000100. This number will be hard to make sense of, so divide it into four parts of eight binary digits. The first part of this IP address is used as a network address, the last part as a host address. If you take example 192.168.123.132 and divide it into these two parts you get the following:
192.168.123.0 is a network address. 0.0.0.132 is a host address.
Important IP Command in Linux
Using IP command we can know the device addresses and the network in which our devices reside.
Syntax:
IP OBJECT or IP AbbreviatedForm
So, below are the command list that we can use for the above syntax:
Object | Abbreviated Form | Purpose |
link | l | Network device in network. |
address | a | IPv4 or IPv6 address on a device. |
addr | ||
addrlabel | addrl | Label configuration for protocol address selection. |
neighbor | n | ARP or NDISC cache entry. |
neigh | ||
route | r | Routing table entry. |
rule | ru | Rule in routing policy database. |
maddress | m | Multicast address. |
maddr | ||
mroute | mr | Multicast routing cache. |
For example, when we run the below command:
Code:
IP Address or IP Addr
Additionally, you can use “man ip” which will list down the options available for IP command.
Uses of IP
There are many protocols that use IP addresses.
1. SSH
This protocol is used to connect a remote computer securely. This might require a password and private key file(.PEM).
Code:
$ssh -i xyz.pem username@ip-address
Now you can normal Unix commands like ls (to list the directory), cd (to change the directory) and other commands
2. FTP
File transfer protocol is used for establishing a connection with the remote hosts by login and transfer files. You will be prompted to give a password.
Code:
$ ftp 19.168.123.32
You can use the “get” command to get files and put a command to “put” files on the remote host. FTP is also used to browse the content of directories. Then, you can press the exit if you are finished with transferring of files.
Below are lists of useful commands related to FTP.
3. TELNET
This protocol is used to remotely control a host and administer them. It is similar to Remote desktop found in window machines. Compared to SSH, TELNET is less secured.
Code:
$telnet <ip-address/my_host.com>
Attempts to open a connection to the remote host my_host.com. If a connection is established, then the host will prompt for a login name and password.
Code:
$telnet -l my_username my_host.com 5555
Attempts to open a connection to the remote host my_host.com on port 5555, using the login name my_username. If successful, the host will prompt my_username’s password. Opens a local telnet> prompt, where you may enter any of the commands listed above.
For example, entering the below command at the prompt:
Code:
telnet> open my_host.com
..will attempt to open a connection to my_host.com, as in our first example. Once authenticated, you may execute commands just like you have done so far, using the Terminal. The only difference is, if you were connected to a remote host, the commands will be executed on the remote machine and not your local machine. You can exit the telnet connection by entering the command ‘logout’.
Telnet uses at least HOME, SHELL, DISPLAY, and TERM environment variables. Other environment variables may be propagated to the other side via the TELNET ENVIRON option.
- Two hosts must be on the same Ethernet/LAN to Communicate Using IP.
- Each host must have a good connection with the Ethernet. Verify a good connection to the Ethernet using
- various tools like mii-tool.
- Each host should have the same network address, netmask, and broadcast address.
- Each host must have a unique IP address.
- Neither of the hosts must block the other’s IP packets.
Important Usage of IP Command
Given below are some important usage of IP command in Linux:
- It is used to find which interfaces are configured on the system and query the status of an IP interface.
- Configure Ethernet, local loop-back and other IP interfaces.
- Modify default and also configure static routing.
- It is used to set up a tunnel over IP and list down ARP cache entry.
- Used to delete, assign and setup routes, subnet, IP address, and other IP info to IP interfaces.
- It is used to display IP and its property.
- Display all status of network and multicast IP addresses information.
- Also, it is used to display neighbor object and manage ARP cache information.
- Delete and manage the routing entry.
Recommended Articles
We hope that this EDUCBA information on “IP Command in Linux” was beneficial to you. You can view EDUCBA’s recommended articles for more information.