🌐 🇵🇱 Polski · 🇬🇧 EN
When there are two or more network interfaces in a system (as is the case with RHEL01), we are dealing with a multi-homed system. In such a case, you must decide which interface will serve as the gateway for traffic. To configure traffic routes, we will use the "route" command, which displays existing routes and allows for the addition of new ones.
Syntax of the route command: # route [options]
Route command options:
- add - Add a new route
- del - Delete an existing route
- flush - Clear temporary routes
TIP
A good tip when troubleshooting network issues is to check if a default gateway has been set.
Let's look at the current routing in the system:
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
172.168.1.0 * 255.255.255.0 U 0 0 0 eth1
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
The exit point for this system to the network is most likely a home router. If a default gateway has not been set, we can configure it using the route command.
Step 1 - Setting the default gateway if it does not yet exist:
# route add default gw 192.168.1.1 eth0
Step 2 - Verifying the changes with route
The output should include the following line:
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
CREATING STATIC ROUTES
In some situations, it is necessary to set a specific path to achieve network connectivity. To do this, you can configure static routes that direct traffic directly to a specific gateway or subnet. To create static routes, you must add entries to the following files:
/etc/sysconfig/network-scripts/route-ethX for example:
Default 192.168.1.1 dev eth0
172.168.1.0/24 via 172.168.1.1 eth1
This sets the default gateway to address 192.168.1.1, and any traffic destined for 172.168.1.1/24 will pass to the internal network via the eth1 interface.
Comments