Configure static server IP
This page describes how to configure a static IP address on an Ubuntu server.
As Ubuntu servers typically lack a graphical user interface, this procedure requires basic familiarity with command-line operations and should be performed by experienced technicians.
Overview
To configure a static IP, you will create a new Netplan configuration file in the /etc/netplan directory. This file will define the static IP address and routing rules for your server’s network interfaces.
Configuration process
The steps below outline how to configure a static IP address for your server’s network interfaces.
1. Identify network interfaces
Before creating the Netplan configuration file, determine the names of your server’s network interfaces. Run the following command:
ip a
This command lists all available interfaces (e.g., eno1, eno2). Note the interface names you wish to configure.
2. Create and configure the Netplan file
Go to the directory:
cd /etc/netplan
Create a new Netplan configuration file with the following name:
sudo nano 99-static-config-vas.yaml
(Or use your preferred text editor to create the file.)
Add the following content to the file, adjusting the values to match the specifics of your network and server configuration.
The following configuration is only a sample. Adapt the values to match your specific setup.
network:
version: 2
ethernets:
eno1:
dhcp4: true
eno2:
dhcp4: false
addresses:
- 192.168.99.30/24
routes:
- to: 192.168.99.0/24
via: 192.168.99.1
Configuration legend:
network: Top-level key defining network configuration.version: 2: Specifies the Netplan configuration version.ethernets: Declares the wired network interfaces.eno1:dhcp4: true: Configured to use DHCP for dynamic IP allocation.
eno2:dhcp4: false: Configured with a static IP address.addresses: Specifies the static IP address and subnet mask (e.g.,192.168.99.30/24).routes: Defines routes for the network. In this example:to: Specifies the destination network (e.g.,192.168.99.0/24).via: Specifies the gateway IP (e.g.,192.168.99.1).
Notes:
The interface names (
eno1,eno2) may differ based on your server. Replace these with the names identified in Step 1.If configuring a static IP for the primary interface (
eno1), and it should serve as the default route, the routes section would be configured as follows:CODEroutes: - to: default via: 192.168.99.1
3. Apply the configuration
Apply the configuration using the following command:
sudo netplan try
The
trycommand activates the configuration temporarily and provides a two-minute window to confirm the changes.If you do not confirm within two minutes, the configuration will automatically revert to the previous state.
If everything works as expected, press Enter to confirm the changes.
4. Verify the configuration
Check the status of the network interfaces to ensure they are configured correctly:
ip a
Additional Information
Avoid internet connectivity loss: If the primary interface (
eno1) provides internet access, ensure that secondary interfaces with static IPs do not override the default route.Customizing gateways: The gateway IP in the
viafield should match the customer’s network setup.
For more examples and advanced configuration options, visit the Netplan documentation.