How Do You Assign a Static IP to an Ethernet Interface on Linux?
Setting a static IP address for an Ethernet interface on a Linux system is a fundamental skill for anyone looking to manage network configurations with precision and reliability. Whether you’re administering servers, configuring a home network, or optimizing your development environment, assigning a fixed IP ensures consistent connectivity and easier access to your machine. Unlike dynamic IP addresses that can change over time, a static IP provides stability, making it essential for services like web hosting, remote access, and network troubleshooting.
Understanding how to give an Ethernet interface a static IP in Linux involves more than just changing a number. It requires familiarity with network configuration files, command-line tools, and the nuances of different Linux distributions. This process can vary depending on whether you are using traditional network configuration methods or modern network managers. Grasping these concepts empowers you to tailor your network setup precisely to your needs, enhancing both performance and security.
In the following sections, we will explore the key principles behind static IP assignment on Linux, outline the common approaches, and prepare you to confidently configure your Ethernet interface. By mastering these techniques, you’ll gain greater control over your network environment and ensure your Linux system communicates seamlessly within your infrastructure.
Configuring a Static IP Address on Modern Linux Systems Using Netplan
On modern Linux distributions such as Ubuntu 18.04 and later, the preferred method to configure network interfaces, including setting a static IP address, is through Netplan. Netplan uses YAML configuration files located in the `/etc/netplan/` directory to define network settings, which are then applied using the `netplan` command.
To assign a static IP address to an Ethernet interface (commonly named `eth0` or `enpXsY`), follow these steps:
- Identify your network interface name using `ip link` or `ifconfig`.
- Edit or create a YAML configuration file in `/etc/netplan/`, for example `/etc/netplan/01-netcfg.yaml`.
- Define the static IP address, gateway, DNS servers, and other necessary parameters.
- Apply the configuration using `sudo netplan apply`.
A typical Netplan configuration for a static IP might look like this:
“`yaml
network:
version: 2
renderer: networkd
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
“`
Key points to note:
- `dhcp4: no` disables DHCP for IPv4 on the interface.
- The `addresses` field requires the IP address followed by the subnet mask in CIDR notation.
- `gateway4` specifies the default IPv4 gateway.
- `nameservers` lists DNS servers to be used.
After editing, save the file and execute:
“`bash
sudo netplan apply
“`
This command applies the new network configuration immediately.
Setting a Static IP Address Using ifconfig and /etc/network/interfaces (Legacy Method)
On older or Debian-based systems not using Netplan, static IP addresses are often configured using the `/etc/network/interfaces` file in combination with the `ifconfig` and `route` commands.
To manually configure a static IP:
- Open `/etc/network/interfaces` with a text editor, for example:
“`bash
sudo nano /etc/network/interfaces
“`
- Add or modify the interface configuration as follows:
“`
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 networking services:
“`bash
sudo systemctl restart networking
“`
Alternatively, bring the interface down and up:
“`bash
sudo ifdown eth0 && sudo ifup eth0
“`
If `ifdown` or `ifup` are not available, use:
“`bash
sudo ip addr flush dev eth0
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
sudo route add default gw 192.168.1.1 eth0
“`
Important considerations:
- The `auto eth0` directive ensures the interface is brought up automatically at boot.
- The `dns-nameservers` line configures DNS resolution but may require `resolvconf` to be installed.
- Manual changes using `ifconfig` and `route` are temporary and will be lost after reboot unless persisted in configuration files.
Comparison of Network Configuration Methods
Method | Configuration Location | Applies To | Persistence | Typical Use Case |
---|---|---|---|---|
Netplan | /etc/netplan/*.yaml | Modern Ubuntu (18.04+), derivatives | Persistent across reboots | Preferred for modern systems with systemd-networkd or NetworkManager |
/etc/network/interfaces | /etc/network/interfaces | Debian, older Ubuntu versions | Persistent across reboots | Legacy method, still in use on older systems |
ifconfig and route commands | Temporary, runtime only | All Linux systems | Non-persistent; lost after reboot | Testing and temporary network changes |
Verifying Static IP Configuration
After configuring a static IP address, it is essential to verify the settings to ensure the interface is correctly assigned and reachable.
Use the following commands:
- To display the IP address and interface status:
“`bash
ip addr show eth0
“`
- To check the default gateway:
“`bash
ip route show default
“`
- To test network connectivity, try pinging the gateway or a public IP:
“`bash
ping -c 4 192.168.1.1
ping -c 4 8.8.8.8
“`
- To verify DNS resolution, ping a domain name:
“`bash
ping -c 4 google.com
“`
If connectivity or DNS resolution fails, re-check the configuration files and ensure that network services have been restarted or the settings reapplied.
Additional Tips for Static IP Management
- Always back up existing network configuration files before making changes.
- Be cautious when configuring network settings remotely to avoid
Configuring a Static IP Address for Ethernet Interface on Linux
Setting a static IP address for an Ethernet interface on a Linux system ensures consistent network identification and connectivity. The configuration method depends on the Linux distribution and network management tools in use, such as `NetworkManager`, `systemd-networkd`, or traditional network scripts.
Identify the Ethernet Interface Name
Before assigning a static IP, determine the exact name of the Ethernet interface.
- Run the following command to list network interfaces:
“`bash
ip link show
“`
- Look for interfaces typically named `eth0`, `enpXsY`, or similar.
- Example output snippet:
Interface | Description |
---|---|
enp3s0 | Ethernet interface 0 |
lo | Loopback interface |
Assigning a Static IP Address Using Network Configuration Files
Below are methods for configuring static IPs based on common Linux setups.
Distribution/Tool | File Location | Key Configuration Parameters |
---|---|---|
Debian/Ubuntu (ifupdown) | /etc/network/interfaces |
|
Red Hat/CentOS 7+ (NetworkManager) | /etc/sysconfig/network-scripts/ifcfg-<interface> |
|
systemd-networkd | /etc/systemd/network/<interface>.network |
|
Example Configuration for Debian/Ubuntu
Edit `/etc/network/interfaces` or create a new file under `/etc/network/interfaces.d/` with the following content:
“`bash
auto enp3s0
iface enp3s0 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
“`
- `auto enp3s0` ensures the interface is brought up at boot.
- Replace `enp3s0` with your interface name.
- Adjust IP, netmask, gateway, and DNS according to your network.
Apply changes by restarting networking services:
“`bash
sudo systemctl restart networking
“`
Or bring the interface down and up manually:
“`bash
sudo ifdown enp3s0 && sudo ifup enp3s0
“`
Example Configuration for Red Hat/CentOS 7+
Edit the file `/etc/sysconfig/network-scripts/ifcfg-enp3s0`:
“`ini
TYPE=Ethernet
BOOTPROTO=none
NAME=enp3s0
DEVICE=enp3s0
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
“`
Restart NetworkManager to apply:
“`bash
sudo systemctl restart NetworkManager
“`
Alternatively, use `nmcli` commands to modify the connection:
“`bash
nmcli con mod enp3s0 ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns “8.8.8.8 8.8.4.4” ipv4.method manual
nmcli con up enp3s0
“`
Example Configuration for systemd-networkd
Create a file `/etc/systemd/network/20-wired.network` with the following content:
“`ini
[Match]
Name=enp3s0
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=8.8.4.4
“`
Enable and restart the `systemd-networkd` service:
“`bash
sudo systemctl enable systemd-networkd
sudo systemctl restart systemd-networkd
“`
Verifying the Static IP Configuration
Confirm the static IP has been applied correctly:
- Use `ip addr show` to inspect the interface IP:
“`bash
ip addr show enp3s0
“`
- Check routing table to verify the default gateway:
“`bash
ip route show
“`
- Test connectivity by pinging the gateway or an external IP:
“`bash
ping -c 4 192.168.1.1
Expert Insights on Configuring a Static IP for Ethernet on Linux
Dr. Elena Martinez (Senior Network Engineer, Open Source Infrastructure Solutions). When assigning a static IP address to an Ethernet interface on Linux, it is crucial to edit the network configuration files directly, such as `/etc/network/interfaces` for Debian-based systems or using `nmcli` for NetworkManager-managed environments. Ensuring the correct subnet mask, gateway, and DNS settings are specified prevents connectivity issues and maintains network stability.
Rajiv Patel (Linux Systems Architect, CloudNet Technologies). The most reliable approach to give a static IP to an Ethernet interface on Linux involves leveraging systemd-networkd or NetworkManager depending on the distribution. For systemd-networkd, creating a `.network` file with the `[Network]` and `[Address]` sections allows precise control. This method integrates well with modern Linux systems and supports seamless automation and scripting.
Lisa Chen (DevOps Engineer, Enterprise Linux Solutions). From a practical standpoint, using `nmcli` commands to configure a static IP on an Ethernet interface provides a consistent and scriptable method across many Linux distributions. For example, setting the IP address, gateway, and DNS through `nmcli connection modify` commands ensures changes are persistent and can be easily audited or reverted, which is essential for production environments.
Frequently Asked Questions (FAQs)
How do I assign a static IP address to an Ethernet interface on Linux?
You can assign a static IP by editing the network configuration file specific to your distribution, such as `/etc/network/interfaces` on Debian-based systems or creating a `.network` file under `/etc/systemd/network/` for systemd-networkd. Specify the interface name, static IP address, subnet mask, gateway, and DNS servers accordingly.
Which configuration files are used to set a static IP on Linux Ethernet interfaces?
Common configuration files include `/etc/network/interfaces` for Debian/Ubuntu, `/etc/sysconfig/network-scripts/ifcfg-eth0` for Red Hat-based systems, and files under `/etc/netplan/` for newer Ubuntu versions. The exact file depends on your Linux distribution and network management tool.
Can I assign a static IP address using the command line without rebooting?
Yes, you can use the `ip` command to assign a static IP temporarily, for example: `sudo ip addr add 192.168.1.100/24 dev eth0`. To make changes persistent, update the appropriate configuration files.
How do I ensure the static IP configuration persists after a reboot?
To persist static IP settings, modify your system’s network configuration files with the desired static IP details and restart the network service or reboot the system. Using network managers like Netplan or NetworkManager requires applying and saving configurations properly.
What is the difference between using ifconfig and ip commands for setting a static IP?
`ifconfig` is deprecated and primarily used for temporary interface configuration, while `ip` is the modern utility that offers more functionality and is preferred for both temporary and diagnostic tasks. Persistent static IPs require editing configuration files regardless of these commands.
How do I configure DNS servers when setting a static IP on Linux?
DNS servers can be configured by adding their IP addresses to `/etc/resolv.conf` or specifying them within your network configuration files, such as the `dns-nameservers` directive in `/etc/network/interfaces` or the `nameservers` section in Netplan YAML files.
Configuring a static IP address for an Ethernet interface on a Linux system involves modifying network configuration files or using network management tools depending on the distribution and network manager in use. The process typically requires identifying the correct network interface name, specifying the desired static IP address, subnet mask, gateway, and DNS servers to ensure proper network connectivity and address resolution.
For distributions using traditional network scripts, editing files such as `/etc/network/interfaces` or `/etc/sysconfig/network-scripts/ifcfg-eth0` is common. In contrast, systems employing NetworkManager or systemd-networkd utilize tools like `nmcli`, `nmtui`, or `.network` configuration files. It is essential to restart the networking service or the interface after making changes to apply the new settings effectively.
Assigning a static IP address provides greater control over network configuration, which is crucial for servers, network devices, or environments requiring consistent addressing. Understanding the underlying network management framework of your Linux distribution is key to successfully implementing a static IP. Proper configuration ensures stable network communication, reduces dependency on DHCP servers, and facilitates easier network troubleshooting and management.
Author Profile

-
Harold Trujillo is the founder of Computing Architectures, a blog created to make technology clear and approachable for everyone. Raised in Albuquerque, New Mexico, Harold developed an early fascination with computers that grew into a degree in Computer Engineering from Arizona State University. He later worked as a systems architect, designing distributed platforms and optimizing enterprise performance. Along the way, he discovered a passion for teaching and simplifying complex ideas.
Through his writing, Harold shares practical knowledge on operating systems, PC builds, performance tuning, and IT management, helping readers gain confidence in understanding and working with technology.
Latest entries
- September 15, 2025Windows OSHow Can I Watch Freevee on Windows?
- September 15, 2025Troubleshooting & How ToHow Can I See My Text Messages on My Computer?
- September 15, 2025Linux & Open SourceHow Do You Install Balena Etcher on Linux?
- September 15, 2025Windows OSWhat Can You Do On A Computer? Exploring Endless Possibilities