How to Configure Hostname, static IP, Gateway and DNS on Linux Production Servers

Linux production server network configuration showing hostname, static IP address, gateway and DNS settings

 Introduction
One of the most critical tasks for any Linux system administrator or DevOps engineer is properly configuring network settings on production servers. Whether you are setting up a brand new server, migrating infrastructure or troubleshooting connectivity issues, knowing how to configure a static IP, set the hostname, define the gateway and manage DNS settings on Linux is an essential skill.

In this Linux server network setup guide, we will walk through every step from changing the hostname permanently to configuring DNS with systemd-resolved covering all major distributions including Ubuntu Server, RHEL, Alma Linux and Rocky Linux.

By the end of this tutorial, you will know:

• How to set and change the hostname permanently in Linux
• How to configure a static IP on Ubuntu and RHEL based servers
• How to set a default gateway on Linux server
• How to set DNS using the command line on a Linux server
• How to verify network settings after applying these settings

Before configuring hostname, static IP addresses, gateways and DNS servers, it is important to understand the fundamentals of Linux networking. Read our guide on Linux Networking Basics for Beginners to learn key networking concepts used in Linux environments.

Why Proper Network Configurations Matter on Production Servers
Production servers require static and reliable network configurations. Dynamic IP addresses are not suitable for enterprise systems because applications, monitoring tools, firewalls and DNS records rely on static network settings.

Proper network configuration helps administrators:

• Maintain reliable connectivity
• Improve server management
• Prevent network conflicts
• Ensure DNS resolution works correctly
• Support automation and monitoring tools
• Improve infrastructure stability

Common Use Cases in Enterprise Linux Environments
network configuration on Linux is normally required for:

• Web servers
• Database servers
• Kubernetes nodes
• Virtual machines
• Cloud instances
• Backup servers
• Mail servers
• Monitoring systems
• DNS servers
• Proxy servers

Understanding Temporary vs Permanent Network Changes in Linux

Temporary Network settings
Some Linux networking commands apply changes only to the running system. These temporary network settings are stored in memory and are lost after reboot or when network service is restarted. Actual purpose of these settings is to test changes before applying permanently.                                         Temporary network settings in Linux using runtime commands that do not persist after reboot

Permanent Network Configurations
Permanent network configuration settings are saved in network configuration files or managed by tools such as Netplan and Network Manager. These network configurations permanently remain after the system reboot.                                     Linux network configuration that persists after reboot

Prerequisites before Configuring Linux Network Settings
Before making network changes, ensure you have administrative access and understand your current network setup.

Root access is required or a user with sudo privileges. Most network configuration tasks require root privileges. I have used both the root and a user with sudo privileges just to show how the settings take place with both users.

Switch to the root user:
sudo -i

or

su -

Linux networking skills are essential for system administrators, cloud engineers and DevOps professionals. Learn why Linux remains one of the most valuable technologies in modern IT by reading our guide on Why Learn Linux? Real World Uses, Career Opportunities and Practical Benefits.

Identify Your Active Network Interfaces
Check available network interfaces:
ip addr showOutput of ip addr show command displaying network interfaces and IP addresses in Linux

Common interface names you will encounter:
Interface Name Description
eth0 Traditional Ethernet interface naming used on older Linux systems
ens3, ens33 Predictable network interface names commonly found on VMware and KVM virtual machines
enp0s3 PCI based Ethernet interface often seen on physical hardware and VirtualBox virtual machines
eno1 Onboard Network Interface Card (NIC) commonly found on enterprise servers such as Dell PowerEdge systems
Pro tip: Use ip link show to see all interfaces including ones that are down.

Backup Existing Network Configuration Files
Always back up network configuration files before making changes.

1. Ubuntu Netplan backup:
cp /etc/netplan/00-installer-config.yaml  /root/

2. RHEL based backup:
cp /etc/NetworkManager/system-connections/ens160.nmconnection /root/

How to Check Current Network Configuration in Linux
Before changing settings, verify the existing network configuration.

1. Check Current Hostname
Use the following command:
hostnamectl
Output of hostnamectl command displaying hostname and system information in Linux

2. View IP Address Information
Check current IP addresses using this command:
ip addr showLinux server network configuration output from ip addr show command

3. Check Default Gateway settings
Check the default route with this command:
ip route
Linux server routing configuration shown with ip route command

4. Verify Configured DNS Servers

Check DNS configuration:
cat /etc/resolv.confOutput of cat /etc/resolv.conf command displaying DNS server configuration in Linux

How to Configure Hostname on Linux Servers
Hostnames are important in enterprise Linux environments because they help to identify systems in monitoring tools, logs, SSH sessions and DNS records. Modern Linux distributions use the hostnamectl command. Change Hostname Using hostnamectl

Set a new hostname:
hostnamectl set-hostname seeklinuxLinux hostname configuration using hostnamectl command on a production server

Update Hostname Permanently
The hostnamectl command sets the system hostname permanently and there is no need to reboot the system.

Verify the change:
Verify Hostname Changes using this command
hostnamectl

You can also verify with:
hostname

or
Update the hosts file
nano /etc/hostsEditing the /etc/hosts file to configure hostname resolution in Linux

Why this matters: Many applications (Java apps, Kubernetes, some databases) resolve the local hostname. If /etc/hosts is not synchronized then you will see slow startup times or DNS lookup errors.

How to Configure Static IP Address on Linux
Static IP configuration is important for Linux production servers. Different Linux distributions use different network management tools.

Configure Static IP Address Using Netplan on Ubuntu
Ubuntu 18.04 and later use Netplan as the default network configuration tool. It uses YAML files to define network settings, which are then applied by either systemd-networkd or NetworkManager. 

Locate the Netplan Configuration File
ls /etc/netplan/Listing Netplan configuration files in the /etc/netplan directory on Ubuntu Linux

You will typically see a file such as 00-installer-config.yaml or 01-netcfg.yaml. In my case file name is 50-cloud-init.yaml.

Edit the Netplan Configuration File
sudo nano /etc/netplan/50-cloud-init.yamlEditing the Netplan configuration file 50-cloud-init.yaml to configure a static IP address on Ubuntu Linux

Replace the IP address, gateway and DNS as per your required settings and save the file.

Apply the Netplan Configuration Settings
sudo netplan applyApplying Netplan configuration changes on Ubuntu Linux using the netplan apply command

For debugging issues, use:
sudo netplan --debug apply

Important: YAML is indentation sensitive. Use spaces instead of tabs because a single indentation mistake will prevent netplan from loading the configuration.

Configure Static IP Address on RHEL / CentOS / AlmaLinux / Rocky Linux
Red Hat based distributions use Network Manager as a primary network management daemon. You can configure it via nmcli (command line), nmtui (text UI) or by editing connection files directly.

Method A: Using nmcli (Recommended for Production)
The nmcli command is the most reliable and scriptable way to manage network connections on RHEL based systems.

Step 1: List available connections:
nmcli con showOutput of nmcli con show command displaying active network connections in Linux  Alternatives

Step 2: Set static IP, gateway and DNS
This nmcli command will set the static IP, gateway and DNS on RHEL server. Below is the output configuration file.                                                       Modifying NetworkManager connection settings for interface ens160 using nmcli on Linux

Output:
Output of NMCLI commands showing static IP address, gateway, and DNS configuration on a Linux server

Restart the connection:
nmcli con down ens160 && nmcli con up ens160Restarting a NetworkManager connection using NMCLI to apply network configuration changes on Linux

Method B: Edit Direct Connection File
On RHEL 8/9, connection files are stored at /etc/NetworkManager/system- connections/ens160.nmconnection:
sudo nano /etc/NetworkManager/system-connections/ens160.nmconnection                     Editing the NetworkManager connection file ens160.nmconnection to configure static IP, gateway, and DNS settings on Linux

Apply the changes:
sudo systemctl restart NetworkManager                                                             Restarting the NetworkManager service to apply network configuration changes on Linux

Note: On RHEL 9 and Rocky Linux 9 connection profiles are stored under /etc/NetworkManager/system-connections/ as .nmconnection files. Use nmcli command to manage them and avoid editing these files manually unless necessary.

How to Configure Default Gateway on Linux Servers
The gateway allows Linux servers to communicate with external networks and the internet.

Add a Default Gateway (Temporary for testing)
sudo ip route add default via 192.168.1.1 dev ens160                                                            Adding a temporary default gateway in Linux using the ip route add default command

This remains till reboot. Use it just for a live testing before committing changes to a configuration file.

Configure Gateway with Netplan on Ubuntu
sudo nano /etc/netplan/50-cloud-init.yaml                                                              Netplan configuration file showing default gateway settings on an Ubuntu Linux server

Apply changes:
sudo netplan apply                                                                               Applying Netplan configuration changes using the netplan apply command on Ubuntu Linux

Verify Default Route Configuration
Verify gateway settings:
ip route

or

route -n                                                                                      Output of the route -n command displaying the Linux routing table and default gateway

Set Gateway Using NMCLI on RHEL 9
To configure the gateway using nmcli, you can modify the connection profile and then reactivate it.
nmcli con mod ens160 ipv4.gateway 192.168.1.1                                                                             Configuring the default gateway on interface ens160 using the nmcli command in Linux

Apply changes:
nmcli con up ens160                                                                                      Activating the NetworkManager connection on interface ens160 using the nmcli con up command

How to Configure DNS Servers on Linux
DNS configuration is important for production Linux servers because applications depend on hostname resolution.

Configure DNS Using Netplan on Ubuntu
To configure a dns using Netplan on Ubuntu, edit the Netplan YAML file (usually in /etc/netplan/).
sudo nano /etc/netplan/50-cloud-init.yamlNetplan configuration file showing DNS server settings on an Ubuntu Linux server

Apply changes:
sudo netplan applySuccessfully applying static IP address, gateway, and DNS configuration with netplan apply

Configure DNS with NMCLI on RHEL 9
This is a most common method used on modern RHEL, Rocky Linux, AlmaLinux and CentOS to set dns using nmcli command.
nmcli con mod ens160 ipv4.dns "8.8.8.8 1.1.1.1"Configuring DNS servers on interface ens160 using the nmcli command in Linux

Restart the connection:
nmcli con up ens160Activating interface ens160 after network configuration changes

Update resolv.conf manually
Temporary DNS configuration:
nano /etc/resolv.confManually updating DNS server settings in the /etc/resolv.conf file on Linux

Test DNS Resolution in Linux
Test DNS using dig:
dig google.comUsing the dig command to test DNS resolution for google.com on a Linux server

Or
 use nslookup:
nslookup google.comUsing the nslookup command to verify DNS resolution for google.com on a Linux server

How to Apply and Verify Network Changes
After configuring Linux network settings always verify connectivity.

Restart Networking Services

1. Restart NetworkManager:
systemctl restart NetworkManager

2. Restart systemd-networkd
systemctl restart systemd-networkd

Complete Verification Checklist
# 1. Check IP address
ip addr show ens33Output of the ip addr show ens33 command displaying IP address and network interface details in Linux

# 2. Check the default gateway
ip route showOutput of the ip route show command displaying the default gateway and routing table in Linux

# 3. Check DNS configuration
resolvectl status

cat /etc/resolv.confOutput of the /etc/resolv.conf file displaying configured DNS servers on a Linux system

# 4. Test gateway connectivity
ping -c 4 192.168.1.1Testing connectivity to the default gateway using the ping command

# 5. Test internet/DNS resolution
ping -c 4 8.8.8.8Linux server connectivity test using Google's DNS server

ping -c 4 google.comTesting DNS resolution and network connectivity using ping google.com

# 6. Confirm hostname
hostnamectl
Output of the hostnamectl command displaying hostname and system information on a Linux server

# 7. Check if the correct interface is UP
ip link show ens33Output of the ip link show ens33 command displaying the network interface status on a Linux server

Quick Reference Table
What to Check Command
IP Address ip addr show
Default Gateway ip route show
DNS Servers resolvectl status
Hostname hostnamectl
Interface Status ip link show
DNS Resolution Test dig google.com

Common Errors and How to Fix Them

1. Error: "Network unreachable" after applying static IP address

Cause: Wrong subnet mask or gateway IP Address

Fix: Double check your network range. If your network is 192.168.1.0/24, your gateway must also be in the 192.168.1.x range.

2. Error: DNS resolution is unsuccessful, ping connects to IP address

Reason: DNS servers are unreachable or improperly configured

Fix: Test DNS manually
dig @8.8.8.8 google.com

# Check if systemd-resolved is running
systemctl status systemd-resolved

3. Error: Netplan apply fails with YAML error

Cause: Incorrect indentation or syntax error

Fix: Verify settings in the YAML file before applying changes
sudo netplan generate

4. Error: nmcli changes not persisting after reboot

Cause: connection.autoconnect is set to no

Fix: sudo nmcli con mod ens33 connection.autoconnect yes

5. Error: hostname reverts back to previous after reboot

Cause: hostname command was used instead of hostnamectl

Fix: Always use sudo hostnamectl set-hostname your-hostname

Best Practices for Production Linux Server Networking
Production Linux servers should follow standard networking best practices.

·  Use Static IPs for Production Systems because Static IP addresses minimize connectivity and infrastructure management issues
·  Document Network Changes
·  Maintain records of IP addresses, Gateways, DNS servers, VLANs and Hostnames
·  Always configure primary and secondary DNS servers
·  Avoid Manual Changes to Auto-Generated Files
·  Always use standard configuration tools
·  Test Connectivity before Reboot the system
·  Verify SSH connectivity before restarting remote production servers

Security Considerations of Linux Production Servers
Linux production server security should include proper network management practices.

·  Restrict Unauthorized Network Changes
·  Limits sudo access to trusted administrators only
·  Monitor Network Configuration Changes
Track configuration changes using:
• Git repositories
• Configuration management tools
• Monitoring systems
• Audit logs
·  Use Proper Hostname Naming Conventions
·  Use standard names as hostname

Example:
·  web-prod-01
·  db-prod-01
·  proxy-prod-01

Linux process and service management based on proper network configuration. Learn more in our guide on Linux Process Management for Beginners - Complete Guide.

Difference between Netplan and NetworkManager
A common question when switching between distros is: which tool should I use?
Feature Netplan Network Manager
Default On Ubuntu 18.04+ RHEL, CentOS, Fedora
Configuration Format YAML files INI files or nmcli
Backend systemd-networkd or NetworkManager NetworkManager daemon
Best For Servers (with networkd) Desktops and servers
Scripting YAML based nmcli commands
Apply Changes netplan apply nmcli con up
Both are solid choices. On Ubuntu servers, stick with netplan + networkd. On RHEL based systems use nmcli.

Frequently Asked Questions (FAQs)

Q1: How to set a static IP address without rebooting in Linux?
Ans: Use ip addr add 192.168.1.100/24 dev ens33 and ip route add default via 192.168.1.1 for a live change then update your Netplan or nmcli configuration for permanent changes.

Q2: How to change the hostname permanently in Linux?
Ans: Run sudo hostnamectl set-hostname new-hostname and update the /etc/hosts. The change immediately takes effect.

Q3: What is the difference between Netplan and NetworkManager?
Ans: Netplan is the default on Ubuntu servers and uses YAML config files. Network Manager is default on RHEL/CentOS and is managed via nmcli. Ultimately both configure the same kernel networking stack.

Q4: How do I configure DNS on Ubuntu 22.04 server?
Ans: Either set DNS in your Netplan YAML under nameservers addresses or configure /etc/systemd/resolved.conf and restart systemd-resolved.

Q5: How to verify network settings in Linux?
Ans: Use ip addr show for IP, ip route show for gateway, resolvectl status for DNS and hostnamectl for hostname.

Conclusion
Properly configuring hostname, static IP, gateway and DNS on Linux production servers is the foundation for stable and secure infrastructure. Whether you are using Netplan on Ubuntu or nmcli on RHEL, the principles are the same:

•   Assign a static and meaningful IP address
   Set the correct default gateway for your subnet
   Configure secure DNS servers
   Set a descriptive and permanent hostname
   Always verify before log off

Mastering these Linux sysadmin skills gives you full control over your server's network identity and connectivity and prevents the kind of outages that come from relying on DHCP in production.

If you found this guide helpful, keep visiting seeklinux for more Linux tutorials, server administration guides and troubleshooting tips.

Author: Aqeel Anwar

SeekLinux Author
SeekLinux Team
Linux Engineers | DevOps | Security Enthusiasts

SeekLinux Team shares practical Linux tutorials, SSL/TLS certificate guides, commands and DevOps solutions. Our goal is to simplify system administration and help you master real-world server and security tasks.

Learn more about us →

Post a Comment

Previous Post Next Post