Subscribe Us

Tuesday, January 19, 2021

How to configure IP address in Linux tutorials

 

How to configure IP address in Linux

This tutorial explains how to configure an IP address in Linux. Learn how to use the nmcli, nmtui and nm-connection-editor in detail with practical examples.

IP configurations can be assigned to an interface in two ways; temporary and permanent. In previous parts of this article, we learned how to assign a temporary IP address along with how to view the current IP configuration.

In this tutorial, we will learn how to permanently configure or assign an IP address. To manage the IP configuration permanently, we have three tools or utilities; nmtui, nmcli, and nm-connection-editor. Let's understand how to use each of these tools.

Using the nmtui command for IP configuration

Access a root shell and run the nmtui command.

nmtui command

Select the "Edit a connection" option and press the Enter key.

nmtui selecting interface

Select that NIC from the left pane, on which you want to set the IP address and select the Edit option from the right pane and press the Enter key.

nmtui edit connection

Select the Automatic option from the IPv4 configuration option and press the Enter key.

nmtui automatic option

To obtain IP configuration from the DHCP Server, select the Automatic option. To set the IP configuration manually, use the Manual option.

connection type manual

Select the Show option and press the Enter key. Use the Tab key to switch between options.

nmtui show manual option

Set the IP address/subnet mask, Gateway IP address and DNS Server IP address.

set ip configuration manually

Select the OK option and press the Enter key to accept the change.

nmtui ip assigned

Select the Quit option and press the Enter key.

quit from nmtui interface

When we exit from the nmtui utility, it automatically applies the changes on related interfaces and updates the associated network configuration files. For instance in above task the nmtui updates the /etc/sysconfig/network-scripts/ifcfg-eno16777736 file as we assigned IP configuration to the eno16777736 interface.

An interface restart is required to apply the new configuration. To restart the interface, you can use the ifdown-[NIC] and ifup-[NIC] commands.

nmtui verified

We have successfully assigned the IP address from the nmtui utility.

Using the nm-connection-editor graphical utility

Now let's do the same task from the nm-connection-editor graphical utility. Access the root shell and execute the nm-connection-editor command.

From the opened window, select the appropriate NIC and click the Edit option

starting nm-connection-editor

Now use the following steps to add/update/edit IP configuration on the selected interface.

  • Switch to the IPv4 Settings.
  • Select the Manual option from the Method drop-down menu.
  • Click the Add button and configure IP addresses in respective fields.
  • Click the Save button.
  • Click the Close button at the main screen.

setting-up ip address on interface

Restart the interface and verify the new IP configuration.

IP-configuration verification

Using the nmcli command to assign the IP addresses

To assign IP address from command line, you can use the nmcli command. This command the following syntax.

#nmcli con mod [interface-name] ipv4.address [IP-address/subnet-mask]
#nmcli con mod [interface-name] ipv4.gateway [IP-address of gateway]
#nmcli con mod [interface-name] ipv4.dns [IP-address of DNS server]

To know the name of interface, you can use the "nmcli con show" or "show ip addr" commands.

The following image shows an example of the "nmcli con mod" command.

example of nmcli command

The commands, used in this example, are explained below.

nmcli con show:-
This command lists the available connections with their associated devices name.

A device is the network interface card and a connection is a configuration used by that device. A device can have multiple connections.

As the above image shows, the connection eno16777736 is associated with the Ethernet device named eno16777736. We modified this connection to set the new IP configuration.

nmcli con mod eno16777736 ipv4.addresses 192.168.1.100/24 :-
This command sets the new IP address and subnet mask on the eno16777736 interface.

nmcli con mod eno16777736 ipv4.gateway 192.168.1.1 :-
This command sets the new default gateway IP address for the eno16777736 interface.

nmcli con mod eno16777736 ipv4.dns 192.168.1.1 :-
This command sets the new DNS Server IP address for the eno16777736 interface.

As we know, new IP configuration applies when the interface is activated. The next two commands are used to restart the interface.

ifdown eno16777736 :-
This command shut down the interface.

ifup eno16777736 :-
This command brings up the interface back.

Key points
  • The nm-connection-editor is available only in the X-Window system. It provides less but sufficient features for end users to manage the network connections. Network administrators rarely use this tool for managing IP configuration.
  • Usually network administrators use the nmcli command and nmtui tool to manage the network connection.
  • Among these options, the nmcli command is the most powerful.
  • The nmcli command is little bit hard to learn and use but works in every situation.
  • In the exam, you can use the nmtui text tool instead of the nmcli command.

That's all for this tutorial. If you like this tutorial, please don't forget to share it from your favorite social networking site.

Monday, January 18, 2021

Basic Linux Commands for Network Testing tutorials

 

Basic Linux Commands for Network Testing

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.

ip neigh command

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.


Basic Linux Commands for Network Testing

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.

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.

show ip link command

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.

ip addr show 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.

removing ip configuration

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.

adding ip configuration to device

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.

activating interface

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.

activating and deactivating interface

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.

ip neigh command

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.

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.

ping command example

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.

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

ip route command

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.

ss command

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.

TaskFrom RHEL 7Before RHEL 7
To view the IP address and link status information of all network interfacesip addr show
ip [-s] link
ifconfig
To assign the IP address 192.168.1.1 and netmask 255.255.2555.0 to the eth0 interfaceip addr add 192.168.1.1/24 dev eth0Ifconfig eth0 192.168.1.1 netmask 255.255.255.0
To view the ARP tableip neigharp
To view the routing tableip routeroute netstat -r
To view all listening and non-listing socketsss -tupnanetstat –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.