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 Manage and Configure IP Addresses in Linux

IP addresses are fundamental to networking, serving as unique identifiers for devices on a network. In a Linux environment, managing and configuring IP addresses is crucial for network communication, troubleshooting, and administration. This article will guide you through the processes of viewing, configuring, and managing IP addresses using various Linux commands and tools.


Examples:


1. Viewing IP Addresses


To view the current IP addresses assigned to your network interfaces, you can use the ip command:


   ip addr show

This command will display detailed information about all network interfaces and their associated IP addresses.


Alternatively, you can use the ifconfig command, which is part of the net-tools package:


   ifconfig

2. Assigning a Static IP Address


To assign a static IP address to a network interface, you can use the ip command. For example, to assign the IP address 192.168.1.100 with a subnet mask of 255.255.255.0 to the eth0 interface, you would run:


   sudo ip addr add 192.168.1.100/24 dev eth0

To make this configuration persistent across reboots, you need to edit the network configuration file, typically found at /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-eth0 depending on your Linux distribution.


For Debian-based systems (e.g., Ubuntu):


   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

For Red Hat-based systems (e.g., CentOS, Fedora):


   sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0

Add or modify the following lines:


   DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes

3. Releasing and Renewing a DHCP Lease


If your network interface is configured to use DHCP, you might need to release and renew the IP address. This can be done using the dhclient command:


To release the current DHCP lease:


   sudo dhclient -r eth0

To renew the DHCP lease:


   sudo dhclient eth0

4. Checking Network Connectivity


To verify that your IP address configuration is correct and that you have network connectivity, you can use the ping command:


   ping -c 4 8.8.8.8

This command will send 4 ICMP echo requests to Google's public DNS server and display the results.


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.