Why unable to add gateway using ip route shows Error: Nexthop has invalid gateway.
Environment
- Red Hat Enterprise Linux (RHEL)
- iproute
Issue
- Unable to add gateway using ip route
- Error getting while adding gateway,
Error: Nexthop has invalid gateway.
Resolution
- Check the IP address and subnet mask of the network interface, and make sure the
gateway IP addressis within thesame subnet. Refer to diagnostics steps for more information.
Root Cause
- Adding the
gatewayfrom adifferent networkwill fail because the gateway address would be unreachable from host. Hence while creating the route using iproute command results in the error"Nexthop has invalid gateway."
Diagnostic Steps
- The below following example shows, adding 192.168.124.1 as a gateway to the device enp1s0 will fail because the
gatewayis from adifferent subnet.
[abc@node2.example.com~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 900 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether aa:bb:00:cc:dd:ee brd ff:ff:ff:ff:ff:ff
inet 192.168.122.212/24 brd 192.168.122.255 scope global dynamic noprefixroute enp1s0
valid_lft 3378sec preferred_lft 3378sec
[abc@node2.example.com~]# ip route add 10.10.10.10/32 via 192.168.124.1 dev enp1s0
Error: Nexthop has invalid gateway.
[abc@node2.example.com~]# ip route add 10.10.10.10/32 via 192.168.122.1 dev enp1s0<-------
Checking the IP range of 192.168.122.212/24 subnet.
[abc@node2.example.com~]# ipcalc 192.168.122.212/24
Address: 192.168.122.212
Network: 192.168.122.0/24
Netmask: 255.255.255.0 = 24
Broadcast: 192.168.122.255
Address space: Private Use
Address class: Class C
HostMin: 192.168.122.1<---------- //Gateway IP should be within this range
HostMax: 192.168.122.254<--------
Hosts/Net: 254
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments