What is the best way to add a permanent route?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
3












I need to add a route that won't be deleted after reboot. I read these two ways of doing it :




Add up route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX to the file /etc/network/interfaces




or




Create the file /etc/network/if-up.d/route with:




#!/bin/sh
route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX


and make it executable :



chmod +x /etc/network/if-up.d/route


So I'm confused. What is the best way of doing it?










share|improve this question



















  • 1




    looks like you're focused on a Linux system? (we have AIX, HPUX, Irix, Solaris, ....) on the site.
    – Jeff Schaller
    Nov 7 '16 at 17:50










  • You are right sorry I didn't specify that it was on a linux Debian system. Thanks for reminding it to me.
    – Pozinux
    Nov 8 '16 at 9:21














up vote
5
down vote

favorite
3












I need to add a route that won't be deleted after reboot. I read these two ways of doing it :




Add up route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX to the file /etc/network/interfaces




or




Create the file /etc/network/if-up.d/route with:




#!/bin/sh
route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX


and make it executable :



chmod +x /etc/network/if-up.d/route


So I'm confused. What is the best way of doing it?










share|improve this question



















  • 1




    looks like you're focused on a Linux system? (we have AIX, HPUX, Irix, Solaris, ....) on the site.
    – Jeff Schaller
    Nov 7 '16 at 17:50










  • You are right sorry I didn't specify that it was on a linux Debian system. Thanks for reminding it to me.
    – Pozinux
    Nov 8 '16 at 9:21












up vote
5
down vote

favorite
3









up vote
5
down vote

favorite
3






3





I need to add a route that won't be deleted after reboot. I read these two ways of doing it :




Add up route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX to the file /etc/network/interfaces




or




Create the file /etc/network/if-up.d/route with:




#!/bin/sh
route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX


and make it executable :



chmod +x /etc/network/if-up.d/route


So I'm confused. What is the best way of doing it?










share|improve this question















I need to add a route that won't be deleted after reboot. I read these two ways of doing it :




Add up route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX to the file /etc/network/interfaces




or




Create the file /etc/network/if-up.d/route with:




#!/bin/sh
route add -net 172.X.X.0/24 gw 172.X.X.X dev ethX


and make it executable :



chmod +x /etc/network/if-up.d/route


So I'm confused. What is the best way of doing it?







debian centos rhel route






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 '16 at 18:01









Christopher

9,29032745




9,29032745










asked Nov 7 '16 at 17:36









Pozinux

3962720




3962720







  • 1




    looks like you're focused on a Linux system? (we have AIX, HPUX, Irix, Solaris, ....) on the site.
    – Jeff Schaller
    Nov 7 '16 at 17:50










  • You are right sorry I didn't specify that it was on a linux Debian system. Thanks for reminding it to me.
    – Pozinux
    Nov 8 '16 at 9:21












  • 1




    looks like you're focused on a Linux system? (we have AIX, HPUX, Irix, Solaris, ....) on the site.
    – Jeff Schaller
    Nov 7 '16 at 17:50










  • You are right sorry I didn't specify that it was on a linux Debian system. Thanks for reminding it to me.
    – Pozinux
    Nov 8 '16 at 9:21







1




1




looks like you're focused on a Linux system? (we have AIX, HPUX, Irix, Solaris, ....) on the site.
– Jeff Schaller
Nov 7 '16 at 17:50




looks like you're focused on a Linux system? (we have AIX, HPUX, Irix, Solaris, ....) on the site.
– Jeff Schaller
Nov 7 '16 at 17:50












You are right sorry I didn't specify that it was on a linux Debian system. Thanks for reminding it to me.
– Pozinux
Nov 8 '16 at 9:21




You are right sorry I didn't specify that it was on a linux Debian system. Thanks for reminding it to me.
– Pozinux
Nov 8 '16 at 9:21










2 Answers
2






active

oldest

votes

















up vote
7
down vote



accepted










You mentioned /etc/network/interfaces, so it's a Debian system...



Create a named routing table. As an example, I have used the name, "mgmt," below.



echo '200 mgmt' >> /etc/iproute2/rt_tables


Above, the kernel supports many routing tables and refers to these by unique integers numbered 0-255. A name, mgmt, is also defined for the table.



Below, a look at a default /etc/iproute2/rt_tables follows, showing that some numbers are reserved. The choice in this answer of 200 is arbitrary; one might use any number that is not already in use, 1-252.



#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#


Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.



source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The production network interface
auto eth0
allow-hotplug eth0
# iface eth0 inet dhcp
# Remove the stanzas below if using DHCP.
iface eth0 inet static
address 10.10.10.140
netmask 255.255.255.0
gateway 10.10.10.1

# The management network interface
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 172.16.100.10
netmask 255.255.255.0
post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.10 table mgmt
post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
post-up ip rule add from 172.16.100.10/32 table mgmt
post-up ip rule add to 172.16.100.10/32 table mgmt


Reboot or restart networking.



Update - Expounding on EL



I noticed in a comment that you were "wondering for RHEL as well."
In Enterprise Linux ("EL" - RHEL/CentOS/et al), create a named routing table as mentioned, above.



The EL /etc/sysconfig/network file:



NETWORKING=yes
HOSTNAME=host.sld.tld
GATEWAY=10.10.10.1


The EL /etc/sysconfig/network-scripts/ifcfg-eth0 file, using a static configuration (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=10.10.10.140
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255


THE EL /etc/sysconfig/network-scripts/ifcfg-eth1 file (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=172.16.100.10
NETMASK=255.255.255.0
NETWORK=172.16.100.0
BROADCAST=172.16.100.255


The EL /etc/sysconfig/network-scripts/route-eth1 file:



172.16.100.0/24 dev eth1 table mgmt
default via 172.16.100.1 dev eth1 table mgmt


The EL /etc/sysconfig/network-scripts/rule-eth1 file:



from 172.16.100.0/24 lookup mgmt





share|improve this answer






















  • Very complete answer. Thanks for adding this second part.
    – Pozinux
    Nov 21 '16 at 20:52






  • 1




    Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
    – nwildner
    Feb 21 at 17:12










  • post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
    – JohannesM
    2 days ago







  • 1




    @JohannesM Quite right. Nice catch, and thank you!
    – Christopher
    2 days ago

















up vote
3
down vote













On Debian based distro you can add a static route permanently as follows:



 echo "up route add -net 172.X.X.X/24 gw 172.X.X.X dev ethX" | sudo tee --append /etc/network/interfaces


On RHEL based distro:



echo "172.X.X.X/24 via 172.X.X.X" | sudo tee --append /etc/sysconfig/network-scripts/route-ethX





share|improve this answer


















  • 2




    The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
    – roaima
    Jan 12 '17 at 23:23






  • 1




    echo "sth" | sudo tee filename
    – JSBach
    Sep 15 '17 at 9:53










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f321687%2fwhat-is-the-best-way-to-add-a-permanent-route%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
7
down vote



accepted










You mentioned /etc/network/interfaces, so it's a Debian system...



Create a named routing table. As an example, I have used the name, "mgmt," below.



echo '200 mgmt' >> /etc/iproute2/rt_tables


Above, the kernel supports many routing tables and refers to these by unique integers numbered 0-255. A name, mgmt, is also defined for the table.



Below, a look at a default /etc/iproute2/rt_tables follows, showing that some numbers are reserved. The choice in this answer of 200 is arbitrary; one might use any number that is not already in use, 1-252.



#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#


Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.



source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The production network interface
auto eth0
allow-hotplug eth0
# iface eth0 inet dhcp
# Remove the stanzas below if using DHCP.
iface eth0 inet static
address 10.10.10.140
netmask 255.255.255.0
gateway 10.10.10.1

# The management network interface
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 172.16.100.10
netmask 255.255.255.0
post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.10 table mgmt
post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
post-up ip rule add from 172.16.100.10/32 table mgmt
post-up ip rule add to 172.16.100.10/32 table mgmt


Reboot or restart networking.



Update - Expounding on EL



I noticed in a comment that you were "wondering for RHEL as well."
In Enterprise Linux ("EL" - RHEL/CentOS/et al), create a named routing table as mentioned, above.



The EL /etc/sysconfig/network file:



NETWORKING=yes
HOSTNAME=host.sld.tld
GATEWAY=10.10.10.1


The EL /etc/sysconfig/network-scripts/ifcfg-eth0 file, using a static configuration (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=10.10.10.140
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255


THE EL /etc/sysconfig/network-scripts/ifcfg-eth1 file (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=172.16.100.10
NETMASK=255.255.255.0
NETWORK=172.16.100.0
BROADCAST=172.16.100.255


The EL /etc/sysconfig/network-scripts/route-eth1 file:



172.16.100.0/24 dev eth1 table mgmt
default via 172.16.100.1 dev eth1 table mgmt


The EL /etc/sysconfig/network-scripts/rule-eth1 file:



from 172.16.100.0/24 lookup mgmt





share|improve this answer






















  • Very complete answer. Thanks for adding this second part.
    – Pozinux
    Nov 21 '16 at 20:52






  • 1




    Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
    – nwildner
    Feb 21 at 17:12










  • post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
    – JohannesM
    2 days ago







  • 1




    @JohannesM Quite right. Nice catch, and thank you!
    – Christopher
    2 days ago














up vote
7
down vote



accepted










You mentioned /etc/network/interfaces, so it's a Debian system...



Create a named routing table. As an example, I have used the name, "mgmt," below.



echo '200 mgmt' >> /etc/iproute2/rt_tables


Above, the kernel supports many routing tables and refers to these by unique integers numbered 0-255. A name, mgmt, is also defined for the table.



Below, a look at a default /etc/iproute2/rt_tables follows, showing that some numbers are reserved. The choice in this answer of 200 is arbitrary; one might use any number that is not already in use, 1-252.



#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#


Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.



source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The production network interface
auto eth0
allow-hotplug eth0
# iface eth0 inet dhcp
# Remove the stanzas below if using DHCP.
iface eth0 inet static
address 10.10.10.140
netmask 255.255.255.0
gateway 10.10.10.1

# The management network interface
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 172.16.100.10
netmask 255.255.255.0
post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.10 table mgmt
post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
post-up ip rule add from 172.16.100.10/32 table mgmt
post-up ip rule add to 172.16.100.10/32 table mgmt


Reboot or restart networking.



Update - Expounding on EL



I noticed in a comment that you were "wondering for RHEL as well."
In Enterprise Linux ("EL" - RHEL/CentOS/et al), create a named routing table as mentioned, above.



The EL /etc/sysconfig/network file:



NETWORKING=yes
HOSTNAME=host.sld.tld
GATEWAY=10.10.10.1


The EL /etc/sysconfig/network-scripts/ifcfg-eth0 file, using a static configuration (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=10.10.10.140
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255


THE EL /etc/sysconfig/network-scripts/ifcfg-eth1 file (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=172.16.100.10
NETMASK=255.255.255.0
NETWORK=172.16.100.0
BROADCAST=172.16.100.255


The EL /etc/sysconfig/network-scripts/route-eth1 file:



172.16.100.0/24 dev eth1 table mgmt
default via 172.16.100.1 dev eth1 table mgmt


The EL /etc/sysconfig/network-scripts/rule-eth1 file:



from 172.16.100.0/24 lookup mgmt





share|improve this answer






















  • Very complete answer. Thanks for adding this second part.
    – Pozinux
    Nov 21 '16 at 20:52






  • 1




    Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
    – nwildner
    Feb 21 at 17:12










  • post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
    – JohannesM
    2 days ago







  • 1




    @JohannesM Quite right. Nice catch, and thank you!
    – Christopher
    2 days ago












up vote
7
down vote



accepted







up vote
7
down vote



accepted






You mentioned /etc/network/interfaces, so it's a Debian system...



Create a named routing table. As an example, I have used the name, "mgmt," below.



echo '200 mgmt' >> /etc/iproute2/rt_tables


Above, the kernel supports many routing tables and refers to these by unique integers numbered 0-255. A name, mgmt, is also defined for the table.



Below, a look at a default /etc/iproute2/rt_tables follows, showing that some numbers are reserved. The choice in this answer of 200 is arbitrary; one might use any number that is not already in use, 1-252.



#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#


Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.



source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The production network interface
auto eth0
allow-hotplug eth0
# iface eth0 inet dhcp
# Remove the stanzas below if using DHCP.
iface eth0 inet static
address 10.10.10.140
netmask 255.255.255.0
gateway 10.10.10.1

# The management network interface
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 172.16.100.10
netmask 255.255.255.0
post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.10 table mgmt
post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
post-up ip rule add from 172.16.100.10/32 table mgmt
post-up ip rule add to 172.16.100.10/32 table mgmt


Reboot or restart networking.



Update - Expounding on EL



I noticed in a comment that you were "wondering for RHEL as well."
In Enterprise Linux ("EL" - RHEL/CentOS/et al), create a named routing table as mentioned, above.



The EL /etc/sysconfig/network file:



NETWORKING=yes
HOSTNAME=host.sld.tld
GATEWAY=10.10.10.1


The EL /etc/sysconfig/network-scripts/ifcfg-eth0 file, using a static configuration (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=10.10.10.140
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255


THE EL /etc/sysconfig/network-scripts/ifcfg-eth1 file (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=172.16.100.10
NETMASK=255.255.255.0
NETWORK=172.16.100.0
BROADCAST=172.16.100.255


The EL /etc/sysconfig/network-scripts/route-eth1 file:



172.16.100.0/24 dev eth1 table mgmt
default via 172.16.100.1 dev eth1 table mgmt


The EL /etc/sysconfig/network-scripts/rule-eth1 file:



from 172.16.100.0/24 lookup mgmt





share|improve this answer














You mentioned /etc/network/interfaces, so it's a Debian system...



Create a named routing table. As an example, I have used the name, "mgmt," below.



echo '200 mgmt' >> /etc/iproute2/rt_tables


Above, the kernel supports many routing tables and refers to these by unique integers numbered 0-255. A name, mgmt, is also defined for the table.



Below, a look at a default /etc/iproute2/rt_tables follows, showing that some numbers are reserved. The choice in this answer of 200 is arbitrary; one might use any number that is not already in use, 1-252.



#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#


Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.



source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The production network interface
auto eth0
allow-hotplug eth0
# iface eth0 inet dhcp
# Remove the stanzas below if using DHCP.
iface eth0 inet static
address 10.10.10.140
netmask 255.255.255.0
gateway 10.10.10.1

# The management network interface
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 172.16.100.10
netmask 255.255.255.0
post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.10 table mgmt
post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
post-up ip rule add from 172.16.100.10/32 table mgmt
post-up ip rule add to 172.16.100.10/32 table mgmt


Reboot or restart networking.



Update - Expounding on EL



I noticed in a comment that you were "wondering for RHEL as well."
In Enterprise Linux ("EL" - RHEL/CentOS/et al), create a named routing table as mentioned, above.



The EL /etc/sysconfig/network file:



NETWORKING=yes
HOSTNAME=host.sld.tld
GATEWAY=10.10.10.1


The EL /etc/sysconfig/network-scripts/ifcfg-eth0 file, using a static configuration (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=10.10.10.140
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255


THE EL /etc/sysconfig/network-scripts/ifcfg-eth1 file (without NetworkManager and not specifying "HWADDR" and "UUID" for the example, below) follows.



DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=172.16.100.10
NETMASK=255.255.255.0
NETWORK=172.16.100.0
BROADCAST=172.16.100.255


The EL /etc/sysconfig/network-scripts/route-eth1 file:



172.16.100.0/24 dev eth1 table mgmt
default via 172.16.100.1 dev eth1 table mgmt


The EL /etc/sysconfig/network-scripts/rule-eth1 file:



from 172.16.100.0/24 lookup mgmt






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered Nov 7 '16 at 18:13









Christopher

9,29032745




9,29032745











  • Very complete answer. Thanks for adding this second part.
    – Pozinux
    Nov 21 '16 at 20:52






  • 1




    Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
    – nwildner
    Feb 21 at 17:12










  • post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
    – JohannesM
    2 days ago







  • 1




    @JohannesM Quite right. Nice catch, and thank you!
    – Christopher
    2 days ago
















  • Very complete answer. Thanks for adding this second part.
    – Pozinux
    Nov 21 '16 at 20:52






  • 1




    Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
    – nwildner
    Feb 21 at 17:12










  • post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
    – JohannesM
    2 days ago







  • 1




    @JohannesM Quite right. Nice catch, and thank you!
    – Christopher
    2 days ago















Very complete answer. Thanks for adding this second part.
– Pozinux
Nov 21 '16 at 20:52




Very complete answer. Thanks for adding this second part.
– Pozinux
Nov 21 '16 at 20:52




1




1




Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
– nwildner
Feb 21 at 17:12




Upvoted cause it's good to see people giving answers using ip route on Linux instead of using route add. People know for decades that iproute2 is deprecating all legacy network tools.
– nwildner
Feb 21 at 17:12












post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
– JohannesM
2 days ago





post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt the line src 172.16.100.1 should be 172.16.100.10. The Interface IP of eth1
– JohannesM
2 days ago





1




1




@JohannesM Quite right. Nice catch, and thank you!
– Christopher
2 days ago




@JohannesM Quite right. Nice catch, and thank you!
– Christopher
2 days ago












up vote
3
down vote













On Debian based distro you can add a static route permanently as follows:



 echo "up route add -net 172.X.X.X/24 gw 172.X.X.X dev ethX" | sudo tee --append /etc/network/interfaces


On RHEL based distro:



echo "172.X.X.X/24 via 172.X.X.X" | sudo tee --append /etc/sysconfig/network-scripts/route-ethX





share|improve this answer


















  • 2




    The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
    – roaima
    Jan 12 '17 at 23:23






  • 1




    echo "sth" | sudo tee filename
    – JSBach
    Sep 15 '17 at 9:53














up vote
3
down vote













On Debian based distro you can add a static route permanently as follows:



 echo "up route add -net 172.X.X.X/24 gw 172.X.X.X dev ethX" | sudo tee --append /etc/network/interfaces


On RHEL based distro:



echo "172.X.X.X/24 via 172.X.X.X" | sudo tee --append /etc/sysconfig/network-scripts/route-ethX





share|improve this answer


















  • 2




    The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
    – roaima
    Jan 12 '17 at 23:23






  • 1




    echo "sth" | sudo tee filename
    – JSBach
    Sep 15 '17 at 9:53












up vote
3
down vote










up vote
3
down vote









On Debian based distro you can add a static route permanently as follows:



 echo "up route add -net 172.X.X.X/24 gw 172.X.X.X dev ethX" | sudo tee --append /etc/network/interfaces


On RHEL based distro:



echo "172.X.X.X/24 via 172.X.X.X" | sudo tee --append /etc/sysconfig/network-scripts/route-ethX





share|improve this answer














On Debian based distro you can add a static route permanently as follows:



 echo "up route add -net 172.X.X.X/24 gw 172.X.X.X dev ethX" | sudo tee --append /etc/network/interfaces


On RHEL based distro:



echo "172.X.X.X/24 via 172.X.X.X" | sudo tee --append /etc/sysconfig/network-scripts/route-ethX






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 21 at 17:03









Community

1




1










answered Nov 7 '16 at 17:55









GAD3R

24.3k1749103




24.3k1749103







  • 2




    The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
    – roaima
    Jan 12 '17 at 23:23






  • 1




    echo "sth" | sudo tee filename
    – JSBach
    Sep 15 '17 at 9:53












  • 2




    The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
    – roaima
    Jan 12 '17 at 23:23






  • 1




    echo "sth" | sudo tee filename
    – JSBach
    Sep 15 '17 at 9:53







2




2




The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
– roaima
Jan 12 '17 at 23:23




The sudo is meaningless in both your two commands. Either you're already root, so the >> works, or you're not, in which case the >> is applied as your original user and only the echo is run as root. Also, this fails dismally if there are multiple interfaces defined in /etc/network/interfaces.
– roaima
Jan 12 '17 at 23:23




1




1




echo "sth" | sudo tee filename
– JSBach
Sep 15 '17 at 9:53




echo "sth" | sudo tee filename
– JSBach
Sep 15 '17 at 9:53

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f321687%2fwhat-is-the-best-way-to-add-a-permanent-route%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay