On NI Linux Real-Time systems, the ip route add command can be used to manually add a route to the kernel's IP routing table. This command specifies how the system should reach a particular IP address or network, including which interface or gateway to use.
The table below provides example IP addresses for two NICs, which will be used in the commands later in this guide.
| NIC 1 | NIC 2 |
| IP Address: 10.0.0.5 | IP Address: 10.0.1.5 |
| Subnet Mask: 255.255.255.0 | Subnet Mask:255.255.255.0 |
| Default Gateway: 0.0.0.0 (unspecified) | Default Gateway: 0.0.0.0 (unspecified) |
| Special Route: Use NIC 1 and gateway 10.0.0.1 to route to 192.168.0.x | Special Route: Use NIC 2 and gateway 10.0.1.1 to route to 192.168.1.x |
Linux shell command (Linux RT):
# Route traffic to 192.168.0.0/24 via gateway 10.0.0.1 using NIC1 (eth0)
ip route add 192.168.0.0/24 via 10.0.0.1 dev eth0
# Route traffic to 192.168.1.0/24 via gateway 10.0.1.1 using NIC2 (eth1)
ip route add 192.168.1.0/24 via 10.0.1.1 dev eth1
Command Breakdown:
- ip route add: Adds a new route to the system's routing table.
- 192.168.0.0/24: Specifies the destination network (subnet with a 255.255.255.0 mask).
- via 10.0.0.1: Defines the gateway IP address for reaching the destination network.
- dev eth0 / dev eth1: Indicates the network interface to use for the route.
You can verify if the routing is configured correctly by using the ip route show command.
To run these commands, you can refer to the NI guide titled Accessing the Shell on NI Linux Real-Time Devices