Support > About independent server > The process and key details of setting static IP addresses in the Ubuntu system
The process and key details of setting static IP addresses in the Ubuntu system
Time : 2025-05-23 13:26:28
Edit : Jtti

When deploying a network on an Ubuntu server or desktop system, configuring a fixed static IP address is beneficial for ensuring stable communication of the system in the network. A static IP address helps prevent connection failures or service interruptions caused by dynamic changes in IP allocation. Especially in enterprise local area networks, data center environments or cloud host scenarios, the service uncertainty caused by dynamic addresses can affect the stability of individual structures. Static IP configuration is one of the skills that network administrators should learn. The static IP setting methods for different Ubuntu versions of the system also vary to some extent, which are specifically manifested as follows!

Ubuntu's newer versions (18.04 and later) default to using Netplan as the network configuration tool, which centrally manages network interfaces through YAML format configuration files. In older versions (such as 16.04 and earlier), the /etc/network/interfaces file is used for network definitions. In addition, for some Ubuntu desktop versions, Settings may also rely on the NetworkManager graphical interface. Therefore, in actual operation, it is necessary to determine which method to use based on the environment. On the server side or in an environment without a graphical interface, Netplan is currently the mainstream recommended method.

First, taking Netplan as an example, this article introduces how to configure static IP addresses in Ubuntu. The core configuration file of Netplan is located in the /etc/netplan/ directory. The file names are usually 01-netcfg.yaml or 50-cloud-init.yaml. The specific names vary depending on the system initialization method and the cloud service provider. To start configuring the static IP, you need to open the file using a text editor. For example, use the following command:

sudo nano /etc/netplan/01-netcfg.yaml

After opening, you can see the current network card configuration. Suppose the network card name is ens33 (the actual name can be viewed through the ip a command), we need to set the static IP address 192.168.1.100, the subnet mask to be 24 bits, the gateway to be 192.168.1.1, and the DNS servers to be 8.8.8.8 and 8.8.4.4. Then the configuration content is as follows:

network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]

After the input is completed, save the file and exit. Then run the following command to make the configuration take effect:

sudo netplan apply

At this point, the Ubuntu system will enable static IP based on the configuration. You can verify whether the Settings are successful by using the ip a or ping command to test the network connectivity. If the configuration is incorrect, Netplan may report an error when applied. You should recheck whether the YAML syntax (such as indentation, colons, Spaces, etc.) is standardized. Note that Netplan is highly sensitive to format errors. Common issues include the mixed use of tabs and Spaces, and the absence of CIDR tags in addresses. Any mistake in details can lead to network unavailability.

For users who use older versions of Ubuntu or are accustomed to traditional configuration methods, static IP Settings can also be achieved by modifying the /etc/net/interfaces file. First back up the original file, and then edit:

sudo nano /etc/network/interfaces

Add or modify the network card information as follows:

auto ens33
iface ens33 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
Dns-name Servers 8.8.8.8 8.8.4.4

After editing is completed, save and close the file, and then restart the network service to make the configuration take effect:

sudo systemctl restart networking

Or used in some versions:

sudo /etc/init.d/networking restart

After the configuration is successful, the current address information can also be confirmed through the ip a or ifconfig command. It should be noted that if Netplan and NetworkManager are installed in the system, it is recommended to use a unified way to manage the network to avoid configuration conflicts.

For the desktop version of Ubuntu, it is also very intuitive to set the static IP in a graphical way. Click the network icon in the upper right corner of the screen, select "Settings" under "Wired Connection" or "Wireless Connection", enter the corresponding network interface, change the method from "Automatic (DHCP)" to "Manual" in the "IPv4" TAB, then enter the IP address, subnet mask, gateway and DNS server, and save. After making modifications in the graphical interface, these configurations will be written into the configuration file managed by NetworkManager. It is recommended to use them separately from the Netplan configuration method.

In addition to the basic configuration, some edge scenarios also need to be considered, such as configuring multiple static IP addresses for multi-network card devices, using bridge network interfaces, VLAN binding, and interface configuration, etc. In these scenarios, the static IP Settings will be more complex. Netplan supports the definition of multiple Ethernet ports and achieves isolation and routing forwarding between different networks through custom routing rules. For situations where a DHCP server is used but some hosts need to maintain static addresses, a "pseudo-static IP" can also be achieved by binding MAC addresses on the DHCP server side. This approach is more suitable for centralized management of local area network deployments.

Overall, setting a static IP for the Ubuntu system is not complicated, but it requires standardized operation, understanding of configuration logic, and taking into account the differences in system versions. With the new version of Ubuntu increasingly promoting the network management method mainly based on Netplan, administrators should update the configuration ideas in a timely manner, master the basic YAML syntax and understand the underlying network behavior.

Relevant contents

What should you pay attention to when choosing a recording server How to choose the configuration of Don't Starve server: a comprehensive guide from beginner to advanced What are the core technologies of high-defense servers in the United States for identifying and defending against attacks Evaluation method for Bandwidth Requirements of Cross-border E-commerce websites What are the reasons for hiding the server IP and the specific practical methods Introduction to the method of blocking all access IP addresses from specified countries In which scenarios are the E5 and E3 servers respectively applicable? And analysis of specific architectural differences What are the benefits of the collaboration between video storage servers and CDN High-bandwidth servers are known as the core engine driving the digital age Deep Challenges and Solutions for Overseas High-defense Server Cores and IO Systems
Go back

24/7/365 support.We work when you work

Support