Adding default route permanently in Linux: A Guide

Abstract: Resolves loss of external connectivity after reboot by permanently configuring the default gateway in RHEL network scripts or NetworkManager.

Created: 2026-08-20 by
To add a default route permanently in Red Hat Enterprise Linux, you must configure the network interface file rather than using temporary command-line tools. This ensures that the routing table is restored automatically every time the system boots or the network service restarts. The standard method involves editing the configuration files located in the /etc/sysconfig/network-scripts/ directory for legacy systems or using NetworkManager dispatcher scripts for modern setups.

Understanding Default Routes

A default route acts as the gateway for all traffic that does not match a more specific rule in your routing table. In IP networking, this is typically represented as 0.0.0.0/0. When your server needs to communicate with an external network, such as the internet, it checks its routing table. If no specific path exists for the destination IP, it sends the packet to the default gateway. Without a permanent default route, your server will lose connectivity to external resources after every reboot or network interface failure, leading to significant downtime and service interruptions.

Configuring via Network Scripts (RHEL 7 and earlier)

For older versions of Red Hat Enterprise Linux, such as RHEL 7, the network configuration is managed through individual script files. You need to identify the active network interface name, which is often eth0, ens33, or similar, depending on your hardware and virtualization environment. You can list available interfaces by running ip link show or ls /sys/class/net/. Once you have identified the interface, navigate to the configuration directory using cd /etc/sysconfig/network-scripts/. Locate the file corresponding to your interface, typically named ifcfg-interface_name. Open this file with a text editor like vi or nano. You must add or modify the following directives within the file:
  • GATEWAY: Set this to the IP address of your router or upstream provider. For example, GATEWAY=192.168.1.1.
  • DEFROUTE: Ensure this is set to yes to designate this interface as the primary source for default traffic.
  • ONBOOT: Verify that this is set to yes so the interface activates at boot time.
After saving the changes, restart the network service to apply the new configuration immediately. Use the command systemctl restart network. To verify that the default route has been added correctly, run ip route show and look for the line starting with default via.

Configuring via NetworkManager (RHEL 8 and later)

In RHEL 8 and newer versions, NetworkManager is the primary tool for managing network connections. While you can still use the old-style scripts, they are often deprecated or handled differently. The recommended approach is to use the nmtui utility or direct nmtui commands. If you prefer the command line, you can use nmtui to edit connections interactively. Run nmtui, select "Edit a connection," choose your active connection, and navigate to the IPv4 CONFIGURATION section. Change the method from "Automatic" to "Manual" if necessary, and enter your IP address, netmask, and gateway. Ensure the "Default Route" checkbox is selected. Save the changes and exit the utility. Alternatively, you can modify the connection profile directly using nmcli. First, identify the connection name with nmcli connection show. Then, update the gateway setting using the following command structure:
nmcli connection modify <connection_name> ipv4.gateway <gateway_ip>
nmcli connection modify <connection_name> ipv4.method manual
nmcli connection up <connection_name>
This approach ensures that the configuration persists across reboots because NetworkManager writes these settings to its persistent storage. Always verify the result with ip route show to confirm the default route is present.

Verifying and Troubleshooting Connectivity

After applying the configuration, it is crucial to test the connectivity. A common issue arises when the gateway IP is incorrect or unreachable. If you cannot ping the gateway, check your physical cabling or virtual switch configurations. If you can ping the gateway but not external sites, there may be firewall rules blocking outbound traffic. You can also check the system logs for any errors related to network initialization. Look for messages in /var/log/messages or use journald with journalctl -u network. Additionally, ensure that your DNS settings are correct, as a missing default route is different from a DNS resolution failure. For further assistance with network-related issues, such as troubleshooting curl commands that fail due to network misconfigurations, refer to our guide on Troubleshooting curl not working on an RHEL8 Server. Another potential pitfall is conflicting routes. If multiple interfaces are configured with default gateways, the kernel might choose the wrong one based on metric values. You can view the metrics associated with each route using ip route show. Lower metrics take precedence. You can adjust the metric in your configuration files or via nmtui to prioritize the correct interface.

Frequently Asked Questions

How do I remove a default route temporarily?

You can remove the default route temporarily by running the command ip route del default. This change is not persistent and will disappear upon reboot or network service restart. Always verify the removal with ip route show to ensure the entry is gone.

What happens if I have two default gateways?

If multiple default gateways exist, the kernel uses the route with the lowest metric value. This can lead to asymmetric routing or connectivity issues. You should ensure only one interface has a default route configured, or explicitly set metrics to control traffic flow between interfaces.

Can I use nmcli to set a default route without restarting the service?

Yes, using nmtui or nmcli connection up applies changes immediately to the active connection. However, if you edit the raw configuration files directly, you may need to restart the NetworkManager service or reload the connection profile to see the changes take effect.

Why is my default route missing after a reboot?

This usually indicates that the configuration file was not saved correctly, the ONBOOT parameter is set to no, or the network service failed to start. Check the system logs for errors during boot and verify that the gateway IP specified in the config file matches your actual network infrastructure.

How do I check the current routing table?

Use the command ip route show or route -n to display the current routing table. Look for the line that begins with default or 0.0.0.0 to identify your active gateway. This output shows the gateway IP, the interface used, and the metric associated with the route.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More