This tutorial explains basic Linux networking commands in detail through practical examples. Learn the essential Linux networking commands used for network testing and troubleshooting.
Viewing the IP addresses and MAC addresses of interfaces
The \”ip addr show\” command displays the current configuration and status of all network interfaces.
This command is used to know or view the following information.
Current status: – whether the interface is up or down.
Mac address: – physical address of the interface.
IPv4 address: – IPv4 address of the interface.
IPv6 address: – IPv6 address of the interface.
Following image shows how to read/view above information from the output of the \”ip addr show\” command.
This command supports auto completion feature. It means, you can also use this command in abbreviated from such as ip a, ip a s, ip addr, etc.
Knowing the state of interfaces
The \”ip link show\” command displays the current status of interfaces. Besides the IP configuration,
this command provides exactly same information which the \”ip addr show\” provides.
Following image shows both commands with output.
If you are only interested in the link state information of interfaces or just want to know whether a
particular interface is up or not, you can use this command.
Viewing information only about a specific interface
By default, both \”ip addr show\” and \”ip link show\” commands display information about all connected interfaces.
To view information only about a specific interface, you can specify that interface’s name or ID with these commands.
For example, following commands display information about the \”eno\” interface.
Removing or flushing the IP configuration from an interface
To remove or flush the existing IP configuration from an interface, you can use the following command.
#ip addr flush dev [device]
For example to remove IP configuration from the device/interface \”eno16777736\”, use the following command.
#ip addr flush dev eno16777736
Following image shows an example of removing IP configuration from the interface.
Adding the IP configuration to an interface
To assign IP address to an interface, you can use the following command.
#ip addr add [IP address/netmask] dev [name]
For example, the following command sets the IP address 172.168.0.1/16 to the Ethernet eno16777736.
#ip addr add 172.168.0.1/16 dev eno16777736
Following image shows the above command with example.
Activating and deactivating an interface
To deactivate an interface, use the following command.
#ip link set dev [interface] down
To activate an interface, use the following command.
#ip link set dev [interface] up
Following image shows both commands with example.
Besides the ip command, you can also use the ifup and ifdown commands to activate and deactivate network adapters.
To use these commands, use the following syntax.
#ifdown [adapter] #ifup [adapter]
These commands deactivate and activate interface in more graceful manner. To shut down and start the interface,
these commands call appropriate configuration files from the /etc/sysconfig/network-scripts directory.
Following image shows the use of ifup and ifdown commands.
Viewing ARP Table
ARP table contains hardware address (MAC address) and software address (IP address)
of other systems available in LAN network. By default, a system builds and uses this table to connect with other systems in LAN network.
To view this table, you can use the ip neigh command.
#ip neigh
Following image shows this command with sample output.
In output: –
- First column shows the IP address of remote system.
- Second column shows the name of local interface to which the remote system is attached.
- Third column shows the hardware address of local interface to which the remote system is attached.
- Fourth column shows whether the remote system is reachable or not.
Remote system is any other system of the local network.
System uses the ARP protocol to build the ARP table. ARP protocol works only in local network.
It means, you will not see the IP address of any system that is not available in local network or connected with local
network through the router.
Checking connectivity between two systems
To check connectivity between two computers, you can use the ping command. The ping command uses the following syntax.
#ping [ip address or name of remote system]
By default, the ping command works continuously. To stop this command, press the ctrl+c keys.
If you get reply from the remote system, both systems are connected.
Following image shows practical examples of the ping command.
Viewing or tracing the path
To view or track the route path to a destination, you can use the traceroute command. This command uses the following syntax.
#traceroute -n [ip address or hostname of remote system]
Following image shows the sample output of this command.
The trceroute command requires root privilege. If you do not have sufficient rights or permissions to execute this command,
you can use the tracepath command. This command also serve the same purpose and does not require any special permission.
Viewing the default gateway IP
To view routing table or to view the IP address of default gateway, you can use the ip route command. This command uses the following syntax.
#ip route
This command prints routing table with the IP address of default gateway.
Any data packets with a destination other than networks listed in routing table are sent to the default gateway.
Following image shows the ip route command with sample output.
Displaying open network connections
To view the currently opened network connections along with TCP and UDP sockets, you can use the following command.
#ss -tupna
Following image shows this command with sample output.
Compatibility with earlier versions
RedHat made significant changes in RHEL7. All commands explained above work only on RHEL 7 or higher version.
If you have a previous version, use the appropriate command from the following table.
Task | From RHEL 7 | Before RHEL 7 |
To view the IP address and link status information of all network interfaces | ip addr show ip [-s] link |
ifconfig |
To assign the IP address 192.168.1.1 and netmask 255.255.2555.0 to the eth0 interface | ip addr add 192.168.1.1/24 dev eth0 | Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 |
To view the ARP table | ip neigh | arp |
To view the routing table | ip route | route netstat -r |
To view all listening and non-listing sockets | ss -tupna | netstat –tulpna |
Changes are temporary
Changes made in IP configuration through the ip command are temporary. To make these changes permanent, either you have to use
a dedicated IP management tool (such as the nmcli) or have to make changes in related configuration files manually.
To learn about the network configuration files and the way in which they are modified or updated, check the next parts of this article.
That’s all for this part. In next part of this tutorial, we will learn how to configure or set IP configuration permanently. If you like this tutorial, please don’t forget to share it with friends through your favorite social network.
Full Version EX300 Dumps
Try EX300 Dumps Demo