"Static route тохируулах"-ны өөр хувилбарууд
(Шинэ хуудас: <h2>Task: Display Current Routing Table Using ip command</h2><p>By using the ip command, you can setup and view static route. For example, to display current routing table you…) |
|||
8-р мөр: | 8-р мөр: | ||
ADDRESS1=10.164.234.132</pre><h4>How do I define static routing for network 10.0.0.0/8 via 10.9.38.65 router?</h4><p>Open /etc/sysconfig/network-scripts/route-eth0:<br> <code># vi /etc/sysconfig/network-scripts/route-eth0</code><br> Append following line:<br> <code>10.0.0.0/8 via 10.9.38.65</code><br> Save and close the file. Restart networking:<br> <code># service network restart</code><br> Verify new routing table:<br> <code># route -n</code><br> <a name="deb"></a><br></p><h3><span style="color: rgb(0, 153, 0);">Debian / Ubuntu Linux</span> Persistence Static Routing</h3><p>Open configuration file /etc/network/interfaces<br> <code># cat /etc/network/interfaces</code> | ADDRESS1=10.164.234.132</pre><h4>How do I define static routing for network 10.0.0.0/8 via 10.9.38.65 router?</h4><p>Open /etc/sysconfig/network-scripts/route-eth0:<br> <code># vi /etc/sysconfig/network-scripts/route-eth0</code><br> Append following line:<br> <code>10.0.0.0/8 via 10.9.38.65</code><br> Save and close the file. Restart networking:<br> <code># service network restart</code><br> Verify new routing table:<br> <code># route -n</code><br> <a name="deb"></a><br></p><h3><span style="color: rgb(0, 153, 0);">Debian / Ubuntu Linux</span> Persistence Static Routing</h3><p>Open configuration file /etc/network/interfaces<br> <code># cat /etc/network/interfaces</code> | ||
− | + | Output:</p><pre>auto eth0 | |
+ | iface eth0 inet static | ||
+ | address 192.168.1.2 | ||
+ | netmask 255.255.255.0 | ||
+ | gateway 192.168.1.254 | ||
+ | up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 | ||
+ | down route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1</pre><h5>Debian / Ubuntu Linux static routing for two interfaces:</h5><pre>auto lo | ||
+ | iface lo inet loopback | ||
+ | auto eth0 | ||
+ | iface eth0 inet static | ||
+ | address 10.9.38.76 | ||
+ | netmask 255.255.255.240 | ||
+ | network 10.9.38.64 | ||
+ | broadcast 10.9.38.79 | ||
+ | ### static routing ### | ||
+ | post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65 | ||
+ | pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65 | ||
+ | auto eth1 | ||
+ | iface eth1 inet static | ||
+ | address 204.186.149.140 | ||
+ | netmask 255.255.255.240 | ||
+ | network 204.186.149.128 | ||
+ | broadcast 204.186.149.143 | ||
+ | gateway 204.186.149.129 | ||
+ | # dns-* options are implemented by the resolvconf package, if installed | ||
+ | dns-nameservers 10.0.80.11 10.0.80.12 | ||
+ | dns-search nixcraft.in | ||
+ | </pre><p>Updated for accuracy.</p> | ||
[[Ангилал:Linux]] | [[Ангилал:Linux]] | ||
[[Ангилал:Сисадмин]] | [[Ангилал:Сисадмин]] |
14:15, 20 Наймдугаар сар 2015-ий байдлаарх одоогийн засвар
Task: Display Current Routing Table Using ip command
By using the ip command, you can setup and view static route. For example, to display current routing table you can type command:
# ip route show
Sample output:
192.168.2.0/24 dev eth1 proto kernel scope link src 192.168.2.1 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.2 default via 192.168.1.254 dev eth0
You can add static route using following command:
ip route add {NETWORK} via {IP} dev {DEVICE}
For example network 192.168.55.0/24 available via 192.168.1.254:
# ip route add 192.168.55.0/24 via 192.168.1.254 dev eth1
Alternatively, you can use old good route command:
# route add -net 192.168.55.0 netmask 255.255.255.0 gw 192.168.1.254 dev eth1
Linux Persistence Routes
The drawback of 'ip' or 'route' command is that, when Linux reboots it will forget static routes. So store them in configuration file. Static routing describes a system that does not implement adaptive routing. In these systems routes through a data network are described by fixed paths (statically). These routes are usually entered into the router by the system administrator
<a name="rhelf"></a>
Red Hat (RHEL) / CentOS / Fedora Linux Persistence Static Routing
You need to open /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface:
# cat /etc/sysconfig/network-scripts/route-eth0
Sample Output:
GATEWAY0=192.168.1.254NETMASK0=255.255.255.0 ADDRESS0=192.168.55.0 GATEWAY1=10.164.234.112 NETMASK1= 255.255.255.240
ADDRESS1=10.164.234.132
How do I define static routing for network 10.0.0.0/8 via 10.9.38.65 router?
Open /etc/sysconfig/network-scripts/route-eth0:
# vi /etc/sysconfig/network-scripts/route-eth0
Append following line:
10.0.0.0/8 via 10.9.38.65
Save and close the file. Restart networking:
# service network restart
Verify new routing table:
# route -n
<a name="deb"></a>
Debian / Ubuntu Linux Persistence Static Routing
Open configuration file /etc/network/interfaces
# cat /etc/network/interfaces
Output:
auto eth0 iface eth0 inet static address 192.168.1.2 netmask 255.255.255.0 gateway 192.168.1.254 up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1 down route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.2.1
Debian / Ubuntu Linux static routing for two interfaces:
auto loiface lo inet loopback auto eth0 iface eth0 inet static
address 10.9.38.76 netmask 255.255.255.240 network 10.9.38.64 broadcast 10.9.38.79### static routing ###
post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65 pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 10.9.38.65auto eth1 iface eth1 inet static
address 204.186.149.140 netmask 255.255.255.240 network 204.186.149.128 broadcast 204.186.149.143 gateway 204.186.149.129 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 10.0.80.11 10.0.80.12 dns-search nixcraft.in
Updated for accuracy.