CentOS Add Route Command

last updated in Categories

How do I add route (router IP 192.168.1.254) to my Centos Linux systems from the command line?

You need to use the route command or ip command to add a new route to your kernel routing table.

  • route command – show / manipulate the IP routing table
  • ip command – show / manipulate routing, devices, policy routing and tunnels

To add default gateway IP 192.168.1.254 using eth0, enter:
# route add default gw 192.168.1.254 eth0
And ip command can be used as follows
# ip route add 192.168.1.0/24 dev eth0
Edit /etc/sysconfig/network and make route persistence after reboot:
# vi /etc/sysconfig/network
Add / edit GATEWAY line as follows
GATEWAY=192.168.1.254

Further readings:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

2 comment

  1. # ip route add 192.168.1.0/24 dev eth0
    It’s not correct for Centos 6.8, because add not default route

    But this is OK
    # ip route add 0.0.0.0/0 via 192.168.1.254 dev eth0

    Have a question? Post it on our forum!