Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Set Up a Static IP Address in Linux

In a network environment, IP addresses are used to identify and communicate with devices. By default, most networks use dynamic IP addressing, where the IP address of a device is assigned automatically by a DHCP server. However, there are situations where it is necessary to assign a static IP address to a Linux machine. This can be useful for services that require a consistent IP address, such as web servers, DNS servers, or network printers.


Assigning a static IP address in Linux involves making adjustments to the network configuration files. In this article, we will explore the steps to set up a static IP address in a Linux environment.


Examples:


1. Determine the network interface name:
To set up a static IP address, we first need to identify the network interface name. Open a terminal and run the following command:


   ifconfig -a

This will display a list of network interfaces on your Linux machine. Note down the name of the interface you want to configure with a static IP address.


2. Edit the network configuration file:
Next, we need to edit the network configuration file for the chosen interface. The location of this file may vary depending on the Linux distribution you are using. In most cases, the file is located at /etc/network/interfaces.


Open the file using a text editor with root privileges. For example:


   sudo nano /etc/network/interfaces

Within the file, you will find a section for the chosen interface. It may look something like this:


   auto eth0
iface eth0 inet dhcp

Change the line iface eth0 inet dhcp to:


   iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

Replace eth0 with the actual interface name and specify the desired static IP address, netmask, and gateway. Save the file and exit the text editor.


3. Restart the network service:
To apply the changes, restart the network service. The command to restart the network service may vary depending on your Linux distribution. Here are a few common commands:


   sudo systemctl restart networking
sudo service networking restart
sudo /etc/init.d/networking restart

Use the appropriate command for your distribution.


4. Verify the static IP configuration:
After restarting the network service, verify that the static IP address has been successfully assigned. Run the following command:


   ifconfig

This will display the network interfaces along with their assigned IP addresses. Check if the desired static IP address is listed for the configured interface.


To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.