Static Routes: Difference between revisions

From Leo's Notes
This page was last edited on 7 March 2017, at 05:35.
Created page with " == Temporary Route == {{highlight|lang=terminal|code= # ip route add 136.159.9.1 dev eth1 # ip route add 10.0.0.0/8 via 136.159.9.1 }} This will be wiped if the network gets..."
 
windows
Line 1: Line 1:
How to set static routes on Linux and Windows.


== Temporary Route ==
== Linux ==
=== Temporary Route ===
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
# ip route add 136.159.9.1 dev eth1
# ip route add 136.159.9.1 dev eth1
Line 8: Line 10:
This will be wiped if the network gets restarted or if the machine reboots.
This will be wiped if the network gets restarted or if the machine reboots.


== Persistent ==
=== Persistent Routes (RedHat Based) ===
To make your route survive a reboot, ensure that there is a gateway set in {{code|/etc/sysconfig/network-scripts/ifcfg-eth1}}. Eg:
To make your route survive a reboot, ensure that there is a gateway set in {{code|/etc/sysconfig/network-scripts/ifcfg-eth1}}. ''Eg:''
{{highlight|lang=text|code=
{{highlight|lang=text|code=
DEVICE="eth1"
DEVICE="eth1"
Line 25: Line 27:
10.0.0.0/8 via 136.159.9.1 dev eth1
10.0.0.0/8 via 136.159.9.1 dev eth1
}}
}}
== Windows ==
Use the {{code|route}} command.
=== Temporary ===
To make 9.11.9.11 route to 10.1.2.2:
{{highlight|lang=terminal|code=
C:>route add 9.11.9.11 mask 255.255.255.255 10.1.2.2
OK!
}}
This route will be lost on a reboot.
=== Persistent ===
To make a rule persistent, just add {{code|-p}} to the route command.
''Eg:''
{{highlight|lang=terminal|code=
C:>route -p add 9.11.9.11 mask 255.255.255.255 10.1.2.2
OK!
}}


[[Category:Linux]]
[[Category:Linux]]
[[Category:Windows]]

Revision as of 05:35, 7 March 2017

How to set static routes on Linux and Windows.

Linux

Temporary Route

# ip route add 136.159.9.1 dev eth1
# ip route add 10.0.0.0/8 via 136.159.9.1

This will be wiped if the network gets restarted or if the machine reboots.

Persistent Routes (RedHat Based)

To make your route survive a reboot, ensure that there is a gateway set in /etc/sysconfig/network-scripts/ifcfg-eth1. Eg:

DEVICE="eth1"
BOOTPROTO="static"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=136.159.9.9
GATEWAY=136.159.9.1
NETMASK=255.255.255.0

Then, define the static routes in /etc/sysconfig/network-scripts/route-eth1:

default 136.159.9.1 dev eth1
10.0.0.0/8 via 136.159.9.1 dev eth1

Windows

Use the route command.

Temporary

To make 9.11.9.11 route to 10.1.2.2:

C:>route add 9.11.9.11 mask 255.255.255.255 10.1.2.2
 OK!

This route will be lost on a reboot.

Persistent

To make a rule persistent, just add -p to the route command.

Eg:

C:>route -p add 9.11.9.11 mask 255.255.255.255 10.1.2.2
 OK!