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 Configure IP Address in Linux: A Step-by-Step Guide

Configuring an IP address is a fundamental task for network management and connectivity. In a Linux environment, this process is crucial for setting up servers, workstations, and other networked devices. This article will guide you through the steps to configure an IP address on a Linux system using both command-line tools and graphical interfaces. Understanding how to manage IP addresses in Linux can help ensure your network operates smoothly and efficiently.


Examples:


1. Using ifconfig (deprecated but still widely used):


   sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up

This command assigns the IP address 192.168.1.100 with a subnet mask of 255.255.255.0 to the eth0 network interface and brings the interface up.


2. Using ip command (recommended):


   sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set dev eth0 up

Here, 192.168.1.100/24 specifies the IP address and the subnet mask, and eth0 is the network interface.


3. Configuring a static IP address via /etc/network/interfaces (Debian/Ubuntu):


Edit the file /etc/network/interfaces:


   sudo nano /etc/network/interfaces

Add the following lines:


   auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

Save and close the file, then restart the networking service:


   sudo systemctl restart networking

4. Configuring a static IP address via netplan (Ubuntu 18.04 and later):


Edit the netplan configuration file, usually located at /etc/netplan/01-netcfg.yaml:


   sudo nano /etc/netplan/01-netcfg.yaml

Add the following configuration:


   network:
version: 2
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]

Apply the configuration:


   sudo netplan apply

5. Using nmcli (NetworkManager CLI):


   sudo nmcli con add type ethernet ifname eth0 con-name static-eth0 ip4 192.168.1.100/24 gw4 192.168.1.1
sudo nmcli con up static-eth0

This creates a new connection named static-eth0 with the specified IP address and gateway, and then activates the connection.


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.