How to Configure Static IP Addressing on Linux
Aug 01, 2025 am 06:35 AMIdentify your network interface using ip a. 2. Determine your network manager by checking for Netplan, NetworkManager, ifupdown, or systemd-networkd. 3. Configure the static IP via Netplan (edit /etc/netplan/*.yaml and apply with sudo netplan apply), or ifupdown (edit /etc/network/interfaces and restart networking), or NetworkManager (use nmcli to modify connection settings), or systemd-networkd (create a .network file and restart the service). 4. Verify with ip a, ping the gateway and internet, and test DNS resolution, ensuring all responses are successful.
Setting a static IP address on Linux gives you full control over your network configuration—useful for servers, network devices, or when you need consistent network settings. While the exact method depends on your Linux distribution and network management tool, here’s how to do it correctly across common setups.

1. Identify Your Network Interface
Before making changes, find out the name of your network interface:
ip a
Look for your active interface—common names include eth0
, ens33
, enp0s3
, or wlan0
for Wi-Fi. You’ll need this name for configuration.

2. Check Which Network Manager You're Using
Modern Linux systems use one of several network configuration systems:
- Traditional method: Editing
/etc/network/interfaces
(Debian/Ubuntu with ifupdown) - Netplan: Default on Ubuntu 17.10 and later
- NetworkManager: Common on desktop systems (Fedora, RHEL, CentOS, some Ubuntu)
- systemd-networkd: Used in minimal or server setups
Use this to determine your system:

ls /etc/netplan/ # If files exist, you're likely using Netplan systemctl is-active NetworkManager # Check if NetworkManager is running cat /etc/network/interfaces # Check for ifupdown config
3. Configure Static IP Based on Your System
Option A: Netplan (Ubuntu 18.04 )
Netplan uses YAML files in /etc/netplan/
. Edit the main config:
sudo nano /etc/netplan/01-netcfg.yaml
Example configuration for a static IP:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: no addresses: - 192.168.1.100/24 gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 1.1.1.1]
Apply changes:
sudo netplan apply
? If you get errors, test with
sudo netplan --debug apply
to see what's wrong.
Option B: /etc/network/interfaces (Debian with ifupdown)
Used on older Debian or Ubuntu systems. Edit the file:
sudo nano /etc/network/interfaces
Modify the interface section:
auto enp0s3 iface enp0s3 inet static address 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 1.1.1.1
Restart networking:
sudo systemctl restart networking
Option C: NetworkManager (via nmcli)
If you're on a desktop using NetworkManager, use nmcli
:
First, list your connection:
nmcli connection show
Then modify it (replace YourConnectionName
and interface):
nmcli connection modify "YourConnectionName" ipv4.addresses 192.168.1.100/24 nmcli connection modify "YourConnectionName" ipv4.gateway 192.168.1.1 nmcli connection modify "YourConnectionName" ipv4.dns "8.8.8.8 1.1.1.1" nmcli connection modify "YourConnectionName" ipv4.method manual
Restart the connection:
nmcli connection down "YourConnectionName" nmcli connection up "YourConnectionName"
Option D: systemd-networkd (Minimal or Custom Systems)
Create or edit a .network
file:
sudo nano /etc/systemd/network/10-static-eth0.network
Add:
[Match] Name=enp0s3 [Network] Address=192.168.1.100/24 Gateway=192.168.1.1 DNS=8.8.8.8 DNS=1.1.1.1
Enable and restart:
sudo systemctl enable systemd-networkd sudo systemctl restart systemd-networkd
4. Verify Your Configuration
After applying changes:
- Check IP:
ip a
- Test gateway:
ping 192.168.1.1
- Test internet:
ping google.com
- Check DNS:
nslookup google.com
Make sure everything responds.
Final Notes
- Always keep a backup SSH session open when testing remotely—mistakes can disconnect you.
- Use IP addresses that don’t conflict with your router’s DHCP range.
- The netmask (e.g.,
/24
) determines your network size—match it to your local network.
Basically, pick the method that matches your system and stick to correct syntax—especially with YAML in Netplan. Once set, your machine will always use the same IP.
The above is the detailed content of How to Configure Static IP Addressing on Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To tune MySQL into a Chinese interface, it can be implemented through MySQLWorkbench or command line tools. 1) In MySQLWorkbench, open "Preferences", select the "Appearance" tab, and then select "Chinese(Simplified)" in the "Language" drop-down menu, and restart. 2) When using command line tools, set the operating system locale variables, such as using "exportLANG=zh_CN.UTF-8" on Linux or macOS, and then run the mysql client.

Linux and Windows have their own advantages and disadvantages in CPU and memory usage: 1) Linux uses time slice-based scheduling algorithms to ensure fairness and efficiency; Windows uses priority scheduling, which may cause low-priority processes to wait. 2) Linux manages memory through paging and switching mechanisms to reduce fragmentation; Windows tends to pre-allocate and dynamic adjustment, and efficiency may fluctuate.

Linux's cost of ownership is usually lower than Windows. 1) Linux does not require license fees, saving a lot of costs, while Windows requires purchasing a license. 2) Linux has low hardware requirements and can extend the service life of the device. 3) The Linux community provides free support to reduce maintenance costs. 4) Linux is highly secure and reduces productivity losses. 5) The Linux learning curve is steep, but Windows is easier to use. The choice should be based on specific needs and budget.

LinuxoftenoutperformsWindowsinI/Operformanceduetoitscustomizablekernelandfilesystems,whileWindowsoffersmoreuniformperformanceacrosshardware.1)LinuxexcelswithcustomizableI/OschedulerslikeCFQandDeadline,enhancingperformanceinhigh-throughputapplications

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.

Linux usually performs better in web server performance, mainly due to its advantages in kernel optimization, resource management and open source ecosystem. 1) After years of optimization of the Linux kernel, mechanisms such as epoll and kqueue make it more efficient in handling high concurrent requests. 2) Linux provides fine-grained resource management tools such as cgroups. 3) The open source community continuously optimizes Linux performance, and many high-performance web servers such as Nginx are developed on Linux. By contrast, Windows performs well when handling ASP.NET applications and provides better development tools and commercial support.
