Da3mon Computer
static ip address

Setting a Static IP Address for enp2s0 in Linux

Configuring a static IP address on a Linux machine.

Configuring a static IP address on a Linux machine can be crucial for various networking tasks, such as server setup, network troubleshooting, and consistent network configuration. In this tutorial, we’ll walk you through the steps to set a static IP address for the enp2s0 network interface. This guide is applicable to most Linux distributions that use systemd-networkd.

Step 1: Identify Your Linux Distribution

Before diving into the configuration, it’s important to know which Linux distribution you are using. This tutorial covers the general method, but specific paths and commands might vary slightly depending on whether you are using Ubuntu, Debian, CentOS, Fedora, or another distribution.

Step 2: Edit the Network Configuration File

The network configuration for systemd-networkd is typically located in the /etc/systemd/network/ directory. You’ll need to create or edit a configuration file for your network interface.

Open a terminal and use your preferred text editor to create or edit the configuration file. For this example, we’ll use nano:

sudo nano /etc/systemd/network/50-enp2s0.network

Step 3: Configure the Static IP Address

Add the following lines to the configuration file:

[Match]
Name=enp2s0

[Network]
Address=192.168.1.41/24
Gateway=192.168.1.1
DNS=8.8.8.8

Explanation:

  • [Match] Section:
  • Name=enp2s0: Matches the network interface named enp2s0.
  • [Network] Section:
  • Address=192.168.1.41/24: Sets the static IP address and subnet mask. Here, /24 denotes a subnet mask of 255.255.255.0, which is typical for home networks.
  • Gateway=192.168.1.1: Sets the IP address of your router or gateway.
  • DNS=8.8.8.8: Sets the IP address of your DNS server. You can add multiple DNS servers separated by spaces if needed.

Adjust these values to match your network configuration.

Step 4: Restart systemd-networkd

After saving the changes, restart the systemd-networkd service to apply the new configuration:

Step 5: Verify the Configuration

To ensure the new IP address has been correctly configured, run the following command:

This command displays the network interface configuration, including the assigned static IP address. You should see 192.168.1.41 listed as the IP address for enp2s0.

Conclusion

Setting a static IP address in Linux using systemd-networkd is a straightforward process. By following these steps, you can ensure that your network interface retains a consistent IP address, which is essential for network stability and certain network applications. Whether you are managing a server or a desktop, a static IP can help you maintain control over your network environment.


wpChatIcon
wpChatIcon