Linux Networking: Configuring IP Addresses and DNS

浅夏微凉 2023-01-29 ⋅ 17 阅读

When it comes to networking, Linux provides a powerful and flexible platform that allows for seamless communication between devices. Configuring IP addresses and DNS (Domain Name System) is an essential part of setting up a network. In this blog post, we will delve into the process of configuring IP addresses and DNS in Linux.

IP Addresses

An IP address is a unique numerical identifier assigned to each device connected to a network. It serves as the device's address on the network, allowing other devices to communicate with it. Configuring IP addresses in Linux involves modifying the network interface configuration files.

To view the list of network interfaces on your system, you can use the following command:

$ ip addr show

Each interface listed will have a corresponding configuration file in the /etc/sysconfig/network-scripts/ directory. For example, the configuration file for the primary network interface (usually eth0 or ens33) is /etc/sysconfig/network-scripts/ifcfg-eth0.

To configure a static IP address for a network interface, you can edit the corresponding configuration file. Open the file using a text editor, such as vim or nano, and modify the following lines:

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

In the above example, replace eth0 with the desired network interface name. IPADDR is the static IP address you want to assign to the interface, NETMASK is the subnet mask, and GATEWAY is the default gateway of the network.

Save the file and restart the network service using the following command:

$ systemctl restart network

Your Linux system will now have the new static IP address assigned to the specified network interface.

DNS Configuration

DNS is a system that translates human-readable domain names to their corresponding IP addresses. DNS configuration in Linux involves modifying the /etc/resolv.conf file.

To configure DNS servers in Linux, open the /etc/resolv.conf file using a text editor and modify the following line:

nameserver 8.8.8.8

Replace 8.8.8.8 with the IP address of your preferred DNS server. You can also add multiple DNS servers by specifying additional lines with the nameserver keyword.

Save the file and restart the network service to apply the changes:

$ systemctl restart network

Your Linux system will now use the specified DNS server(s) for domain name resolution.

Conclusion

Configuring IP addresses and DNS in Linux is a crucial step in setting up a network. By following the steps mentioned in this blog post, you can assign static IP addresses to network interfaces and specify DNS servers for domain name resolution. This allows for seamless communication between devices and ensures efficient network operations.


全部评论: 0

    我有话说: