Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Configuring network settings in a Linux environment is a fundamental skill for systems engineers and administrators. Whether you are setting up a server, configuring a workstation, or managing a network, understanding how to configure network interfaces, DNS, and routing is essential. This article will guide you through the process of configuring network settings in Linux using command-line tools.
Examples:
Configuring a Static IP Address:
To configure a static IP address on a Linux system, you typically edit the network interface configuration file. The location and format of this file can vary depending on the Linux distribution. Here, we'll use an example for a Debian-based system like Ubuntu.
Open the network interfaces file with a text editor:
sudo nano /etc/network/interfaces
Add the following configuration for a static IP:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Save the file and restart the networking service:
sudo systemctl restart networking
Using nmcli
to Configure Network Settings:
nmcli
is a command-line tool for managing NetworkManager, which is available on many Linux distributions.
nmcli
:
sudo nmcli con mod "Wired connection 1" ipv4.addresses 192.168.1.100/24
sudo nmcli con mod "Wired connection 1" ipv4.gateway 192.168.1.1
sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con mod "Wired connection 1" ipv4.method manual
sudo nmcli con up "Wired connection 1"
Configuring DNS Settings:
DNS settings can be configured in the /etc/resolv.conf
file or through NetworkManager.
Edit the /etc/resolv.conf
file:
sudo nano /etc/resolv.conf
Add your DNS server addresses:
nameserver 8.8.8.8
nameserver 8.8.4.4
If using NetworkManager, you can set DNS servers with nmcli
:
sudo nmcli con mod "Wired connection 1" ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con up "Wired connection 1"
Adding a Route:
To add a static route, use the ip
command.
Add a route to the network 192.168.2.0/24 via gateway 192.168.1.1:
sudo ip route add 192.168.2.0/24 via 192.168.1.1
To make this route persistent across reboots, add it to the network configuration file or use a script that runs at startup.