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
Open your primary netplan configuration file using a text editor like nano:
sudo
nano /etc/netplan/50-cloud-init.yaml
Replace
the existing contents with the following configuration block. Make sure to update the interface name IP subnet, gateway and DNS addresses to match your network topology.
Apply and Test the New Netplan
Configuration Settings
Once your edits are saved, validate and apply your changes using the try modifier. This safe-mode command automatically rollback your settings if you accidently lock yourself out of ssh session.
sudo netplan try
If the configuration initializes successfully without locking your session, press enter to commit the changes permanently. Alternatively you can apply them directly:
sudo
netplan apply
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 (NetworkManager)
RHEL based distributions manage persistent interfaces using NetworkManager while you can manually modify connection profile. The industry standard method on production environments is utilizing the nmcli command line tool.
Method A: Set Network Parameters 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:
Before executing configuration commands, verify your exact connection interface profile name:
nmcli
con show
Step 2: Set static IP, gateway and
DNS Using nmcli
Run the following commands in sequence to switch your active interface (replace ens160 with your interface name) from dhcp to static configuration. This
nmcli command will set the static IP, gateway and DNS on RHEL server. 
Output:
This is the ouput of above command:
Apply and Activate your Network Changes:
Unlike other configuration utilities, NetworkManager requires you to reload and reactivate the interface before the settings take effect on your running server hardware.
Bring the interface down and back up to commit the changes:
nmcli
con down ens160 && nmcli con up ens160
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 
Apply the changes:
sudo
systemctl restart NetworkManager 
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 
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 
Apply changes:sudo
netplan apply 
Verify Default Route
Configuration
Verify
gateway settings:
ip
route
or
route
-n 
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 
Apply changes:
nmcli
con up ens160 
How to Configure DNS
Servers on LinuxDNS
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.yaml
Apply changes:
sudo
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"
Restart the connection:
nmcli
con up ens160
Update resolv.conf manually
Temporary
DNS configuration:
nano
/etc/resolv.conf
Test DNS Resolution in
Linux
Test
DNS using dig:
dig
google.com
Or
use nslookup:
nslookup
google.com
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
ip
addr show ens33
# 2. Check the default
gateway
ip
route show
# 3. Check DNS
configuration
resolvectl
status
cat
/etc/resolv.conf
# 4. Test gateway
connectivity
ping
-c 4 192.168.1.1
# 5. Test internet/DNS
resolution
ping
-c 4 8.8.8.8
ping -c 4 google.com
# 6. Confirm hostname
hostnamectl
# 7. Check if the correct
interface is UP
ip
link show ens33
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.
Verify Your New Linux Network Settings
After applying your changes either on Ubuntu or RHEL-based systems, you must verify that the server successfully communicate with local network and resolve external internet domains. Run these validation commands to ensure every thing is working:
1. Test Internal Gateway Routing:
Ping your default gateway to verify local connectivity ( replace with your gateway IP):
ping -c 3 192.168.1.1
2. Test External DNS Resolution
Verify that your configured DNS servers are resolving domain names by pinging a public address:
ping -c 3 google.com
3. Check Final Hostname Status:
Ensure the system identity holds across active terminal shells:
hostname --fqdn
Troubleshooting Check list
If you lose connectivity or cannot ping external domains after applying these steps, walk through this quick emergency checklist:
Check Link State: Run ip link to ensure your interface is marked as up.
Verify Spacing (Ubuntu): re-open /etc/netplan/00-installer-config.yaml and check for accidental tab characters or misaligned lines.
Connection Profile (RHEL): ensure you ran nmcli connection up on the exact active profile name, not just the physical device name.
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.
0 Comments