The IP address 10.100.123.6255.255.255.0 contains a critical syntax error because the octet value 6255 exceeds the maximum valid limit of 255 for IPv4 addresses. To configure this route correctly, you must first correct the destination IP to a valid format, such as 10.100.123.62 or a subnet mask like 255.255.255.0, and then use the standard
ip route command with your specific gateway. This guide explains how to diagnose and fix these invalid parameters to ensure proper network connectivity.
Understanding Valid IPv4 Address Structures
IPv4 addresses consist of four decimal numbers separated by dots, where each number represents an octet. Each octet must be an integer between 0 and 255 inclusive. The string provided in your query,
10.100.123.6255.255.255.0, appears to mix an IP address with a subnet mask incorrectly or contains a typo. The segment
6255 is impossible in standard dotted-decimal notation.
When configuring routes, you typically specify a destination network or host, followed by the gateway. A common mistake is appending the subnet mask directly to the IP without using CIDR notation (slash notation) or the
netmask keyword. For example,
10.100.123.62/24 is valid, whereas
10.100.123.62.255.255.255.0 is not. You must separate the host address from the mask clearly.
If you intended to route traffic to the specific host
10.100.123.62 with a /24 subnet, the correct representation is
10.100.123.62/24. If you meant a different IP, ensure all octets are below 256. This validation step is crucial before attempting any routing commands, as the kernel will reject malformed addresses immediately.
Correcting the Syntax Error
To resolve the immediate error, you need to identify the actual destination you want to reach. Let us assume the target is the host
10.100.123.62 on a local subnet. You should verify this IP exists on your network interface using tools like
ip addr show.
Once the valid IP is confirmed, you can construct the route command. The general syntax is:
ip route add <destination> via <gateway>
If you are dealing with a subnet rather than a single host, use CIDR notation. For instance, if the entire
10.100.123.0 network needs to be routed via gateway
10.100.123.1, the command would be:
ip route add 10.100.123.0/24 via 10.100.123.1
It is vital to distinguish between the destination network and the gateway. The gateway must be reachable via one of your existing active interfaces. If you cannot ping the gateway IP, the route addition will fail even with correct syntax. Always test connectivity to the gateway before adding static routes.
Implementing the Route Command
After correcting the IP address, execute the route addition command with administrative privileges. On most Linux distributions, you can use the following command structure:
sudo ip route add 10.100.123.0/24 via 192.168.1.1 dev eth0
Replace
10.100.123.0/24 with your corrected destination network,
192.168.1.1 with your actual gateway IP, and
eth0 with your active network interface name. The
dev parameter is optional but recommended for clarity, ensuring the kernel knows which physical or virtual interface to use for outgoing packets.
You can verify the route was added successfully by running:
ip route show
This command lists all current routes in the kernel routing table. Look for your newly added entry. If it appears, the configuration is active. If you encounter an error stating "File exists," the route may already be present. In that case, remove it first using
ip route del before re-adding it.
For persistent configurations across reboots, you should edit your network configuration files. On Ubuntu systems, this often involves editing
/etc/netplan/*.yaml or using
/etc/network/interfaces depending on the version. Refer to our guide on
How to Fix Kernel IP Routing Table is Empty Error if you face broader routing issues after making changes.
Troubleshooting Common Issues
Even with correct syntax, routes may not function as expected due to several factors. First, check if the gateway is reachable. Use
ping <gateway_ip> to confirm basic connectivity. If the ping fails, the issue lies with layer 2 connectivity or firewall rules, not the route itself.
Second, verify that no default route is overriding your specific route. The kernel uses the longest prefix match rule. If you have a default route
0.0.0.0/0 and a specific route
10.100.123.0/24, traffic to
10.100.123.x will follow the specific route. However, if your specific route has a wider mask than intended, it might catch unintended traffic.
Third, check for policy-based routing. If you have multiple routing tables defined, the default table (
main) might not be used for certain source IPs. Use
ip rule show to inspect policy rules.
Finally, ensure that your network interface is up. An inactive interface will prevent route resolution. Check interface status with
ip link show. If the interface is down, bring it up with
sudo ip link set <interface> up.
For more advanced scenarios involving virtual interfaces, see
How to Route Traffic for Specific IP Addresses through a Virtual Network Interface on Ubuntu 22.04.5 LTS to understand how traffic flows through non-standard paths.
Best Practices for Network Stability
Always document your static routes. Manual additions via
ip route are lost upon reboot unless saved to configuration files. Use netplan, systemd-networkd, or traditional ifupdown scripts to persist changes. This ensures network stability after system updates or restarts.
Avoid overlapping subnets in your routing table. Overlaps can cause unpredictable traffic behavior and make troubleshooting difficult. Regularly audit your routing table using
ip route to ensure it matches your network design documentation.
Test changes incrementally. Add one route at a time and verify connectivity after each addition. This method isolates problems quickly if something breaks. Keep a backup of your current routing table before making significant changes, allowing you to restore previous settings if necessary.
Frequently Asked Questions
Why does my route command fail with "Invalid argument"?
This error almost always indicates a malformed IP address or subnet mask. Ensure every octet in the IP address is between 0 and 255. Also, verify that your subnet mask uses valid CIDR notation (e.g., /24) or dotted-decimal format (e.g., 255.255.255.0).
How do I make a static route permanent?
Static routes added via the command line are temporary. To make them permanent, add the route definition to your distribution's network configuration file, such as Netplan YAML files on Ubuntu or the interfaces file on Debian-based systems.
Can I have multiple gateways for the same subnet?
Yes, you can configure multiple routes for the same destination with different metrics. The kernel will prefer the route with the lowest metric value. This setup is useful for load balancing or failover scenarios, though it requires careful planning to avoid routing loops.
What is the difference between a host route and a subnet route?
A host route targets a single IP address using a /32 mask, while a subnet route targets a range of addresses using a shorter mask like /24. Host routes are more specific and take precedence over subnet routes when both exist in the routing table.
How can I view all available routing tables?
Use the command
ip route show table all to display routes from all configured routing tables. This helps identify if a route is present in a non-default table that might be influencing traffic flow based on policy rules.