A Red Hat Enterprise Linux system should have a single default gateway defined. However, sometimes, it does occur that a system has multiple default gateways. Here's information to detect multiple default gateways and how to get rid of them:
First, check the number of default gateways defined, by running the netstat command and looking for entries that start with 0.0.0.0:
In the example above, there are 2 default gateway entries, one to 192.168.0.1, and another one to 192.168.1.1.# netstat -nr | grep ^0.0.0.0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 em1 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 em2
Quite often, more than 1 default gateways will be defined on a RHEL system, if there are multiple network interfaces present, and a GATEWAY entry is defined in each of the network interface files in /etc/sysconfig/network-script/ifcfg-*:
On a system with multiple network interfaces, it is best to define the default gateway in file /etc/sysconfig/network instead. This file is global network file. Put the following entries in this file, assuming your default gateway is 192.168.0.1 and the network interface to be used for the default gateway is em1:# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg-* ifcfg-em1:GATEWAY=192.168.0.1 ifcfg-em2:GATEWAY=192.168.1.1
Next, remove any GATEWAY entries in any of the ifcfg-* files in /etc/sysconfig/network-scripts.GATEWAY=192.168.0.1 GATEWAYDEV=em1
Finally, restart the network service:
This should resolve multiple default gateways, and the output of the netstat command should now only show one single entry with 0.0.0.0.# service network restart
Note: If the netstat command is not available on the system, you may also determine the number of default gateways, by running:
# ip route show | grep ^default
If you found this useful, here's more on the same topic(s) in our blog:
- Creating an image_data resource without preserving mirrors for use with NIM
- Incrond
- Boxes and lines in NMON
- Resizing a Red Hat swap space
- NFS mounts on HACMP failing
UNIX Health Check delivers software to scan Linux and AIX systems for potential issues. Run our software on your system, and receive a report in just a few minutes. UNIX Health Check is an automated check list. It will report on perfomance, capacity, stability and security issues. It will alert on configurations that can be improved per best practices, or items that should be improved per audit guidelines. A report will be generated in the format you wish, and the report includes the issues discovered and information on how to solve the issues as well.
Interested in learning more?
Interested in learning more?