+5 votes
249 views
How to change IP address with Linux Terminal commands

in Linux / Unix by (551k points)
reopened | 249 views

1 Answer

+3 votes
Best answer

1. Know the name of the interface or network card in Linux
2. Change the IP address with commands in Linux
3. How to configure static IP address or DHCP on Linux
4. How to release and renew IP address in Linux

Each computer in a local network or an external network has a unique identifier called the IP (Internet Protocol) address, through which this device can be located on the network. We currently have two types of IP addresses , IPv4 and IPv6 and each has a different structure, with IPv4 being the most used today, but in a few years it will be IPv6 that dominates the world of networking due to the rapid growth of networks worldwide ..

When managing our Linux environment we must know how to execute different forms of network management and configuration. Network management is important to have well-configured connections that work effectively. Within the world of networks, the IP address is a base pillar that we must know and manage.

Functions of knowing IP addresses
Knowing the IP address of a device is ideal for tasks such as:
  • Control and administration of equipment in the organization.
  • Define what IP address can be distributed to other computers in the organization.
  • Detect the availability of a device on the network.
  • Create access or blocking rules to that IP address and many more tasks.

Normally, operating systems offer us the facility to verify your IP address graphically, but it is important to know that we have the possibility to verify and perform management tasks on the IP address from the terminal such as Linux distributions which TechnoWikis It will focus today..

Reasons to change the IP address
A question that arises is because we can change the IP address of the equipment, some reasons can be:
  • Need to reserve this IP address to a new device
  • Resolve connectivity failures
  • Administrative tasks, etc.

Next, we will see how we can carry out this process in Linux and for this we will use Ubuntu 17.10.

To keep up, remember to subscribe to our YouTube channel! SUBSCRIBE


1. Know the name of the interface or network card in Linux

Step 1

The first important point to keep in mind is to know what is the network interface, or card, in which the IP address we want to modify is assigned, for this we can use the following command:
In Ubuntu and Debian
 Ifconfig 
In CentOS
 ip add 
Step 2

As a result we will see the following: image
Step 3

We can see that the network interfaces of the equipment are displayed, since it can contain several, with specific information such as:
  • Interface name
  • Current IP address
  • Net mask
  • Propagation or broadcast address
  • Packages sent
  • Packages with errors and many more values.

2. Change the IP address with commands in Linux

Step 1

The ifconfig command will also be useful to set the new IP address of the device, for this we must take into account the following syntax:
 sudo ifconfig “Interface” “New IP address” netmask 255.255.255.0 
Step 2

For example, if we want to set the IP address 192.168.0.20 to the interface enp0s3, the current one of this equipment, we will execute the following line:
 sudo ifconfig enp0s3 192.168.0.20 netmask 255.255.255.0 
Step 3

Press Enter, enter the password and we can validate only with ifconfig that the new IP has been established: image
Step 4

Now, another of the options we have is to modify the network gateway, or Gateway, thanks to the route command, this is only necessary in the event that a new router is established in the company for some management task. For this we will use the following syntax:
 sudo route add default gw “New Gateway IP” “interface” 
Step 5

For example, we can execute the following line:
 sudo route add default gw 192.168.0.11 enp0s3 
image
Step 6

To see the new configuration, it will be necessary to display the routing table, and for this we can execute the following command. There we can see our new IP address in the defined gateway.
 route -n 
image

3. How to configure static IP address or DHCP on Linux


Within the world of networks and the Internet we find one of the most important elements of the IP address. The IP address is a communication protocol that allows different devices to connect over the Internet. It is the address we give to establish a communication. We can distinguish two types of IP addresses:
What is a fixed IP address?
Static IP addresses are those that are designated on the network card and that are then used on computers that offer some kind of service such as servers, on those that are responsible for some administration task or computers where a constant connection is needed .
What is dynamic IP address?
Dynamic IP addresses on the other hand, are designated through a DHCP server that is responsible for renewing these addresses every certain period of time. In devices and equipment where a fixed IP is required, having the dynamic mode configured could cause problems.

Let's see how we can configure a dynamic or static IP by commands in Linux..


4. How to release and renew IP address in Linux


When we work with IP addresses we have to control what we are using for good network management. If we are working with dynamic IP addresses, we sometimes need to modify it because we are having an error in the network. In order to change this dynamically assigned address we will use the following command with which to release the one we are using and renewing it for another:

To be able to renew and release an IP address we can use the following commands:

 sudo dhclient -r (Release IP address) sudo dhclient (Renew IP address) 

image

This manual also shows you how to do it on Windows, Mac or Linux.

In this way it will be practical to adjust the IP address in Linux environments in cases where it is necessary to perform some management of this type.


by (3.5m points)
edited

Related questions

+5 votes
1 answer
asked Jun 12, 2020 in Linux / Unix by backtothefuture (551k points) | 326 views
+5 votes
1 answer
asked Jun 5, 2020 in Linux / Unix by backtothefuture (551k points) | 335 views
+5 votes
1 answer
asked Nov 17, 2019 in Linux / Unix by backtothefuture (551k points) | 487 views
+3 votes
1 answer
+3 votes
2 answers
asked May 26, 2019 in Linux / Unix by backtothefuture (551k points) | 548 views
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users