Packet routing with route command

Hey, everyone, how are you doing?

I’m posting a simple and very specific use of ‘route’ command. As always, I usually do not write too much for the sake of simplicity. 🙂

The problem statement is: You have one interface with IP address 10.0.1.117 and the default gateway is 10.0.1.254. Assuming you want to access another network, how to route packets via 10.0.1.254? Well, if you wanna route the entire network, you can do the following command:

# route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.1.254

After, if you type “route -n”, you will see something like this:

Kernel IP routing table
Destination     Gateway     Genmask         Flags Metric Ref    Use Iface
0.0.0.0       10.0.1.254    0.0.0.0         UG    0      0        0 enp4s0
10.0.1.0      0.0.0.0       255.255.255.0   U     0      0        0 enp4s0
192.168.1.0   10.0.1.254    255.255.255.0   UG    0      0        0 enp4s0

Try ‘ping’ to any IP address in the network 192.168.1.0/24. If everything is ok, so we’ve got success.

That’s all,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s