How do I make routing changes persistent across reboots?

2 Answer(s)

    To make route entry persistent in the Linux kernel routing table, you need to modify config file as per your Linux distributions.

    RHEL/CentOS/Fedora/Scientific Linux persistent routing configuration

    Edit /etc/sysconfig/network and set default gateway IP address:
    # vi /etc/sysconfig/network
    Sample outputs:

    ## setup default gateway ##
    GATEWAY=192.168.1.254

    You can add additional static route for eth0 by editing /etc/sysconfig/network-scripts/route-eth0 file as follows:

    10.0.0.0/8 via 10.10.29.65

    The above config sets static routing for network 10.0.0.0/8 via 10.9.38.65 router.

    Debian / Ubuntu Linux persistence static routing configuration

    Edit /etc/network/interfaces file, enter:
    # vi /etc/network/interfaces
    Append the following in eth0 section:

    up route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254
    down route del -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.254

    Save and close the file.

    Answered on August 22, 2021.
    Add Comment

      Here is the Generic method to add persistent static routing on Linux

      Edit /etc/rc.d/rc.local or /etc/rc.local, enter
      # vi /etc/rc.local
      Append the following line:

      /sbin/ip route add 192.168.1.0/24 dev eth0

      OR

      /sbin/ip route add 192.168.1.0/24 dev eth0

      Save and close the file in vim text editor.

      Answered on August 22, 2021.
      Add Comment

      Your Answer

      By posting your answer, you agree to the privacy policy and terms of service.