<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaLinux.com - สปาลีนุกซ์ &#187; linux static route</title>
	<atom:link href="http://spalinux.com/tag/linux-static-route/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>เพื่อชีวิตที่ผ่อนคลายของคนใช้ลีนุกซ์</description>
	<lastBuildDate>Sat, 12 May 2012 10:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>แก้ไข static route บนลีนุกซ์</title>
		<link>http://spalinux.com/2009/09/add_delete_static_route_on_linux</link>
		<comments>http://spalinux.com/2009/09/add_delete_static_route_on_linux#comments</comments>
		<pubDate>Sat, 26 Sep 2009 09:22:04 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Linux Installation]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[linux static route]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=932</guid>
		<description><![CDATA[บทความนี้อธิบายการแก้ไข static route บน ลีนุกซ์ โดยจะมีทั้งการแสดง routing tablle ที่มีอยู่ การเพิ่ม ลบ route รวมทั้งวิธีการคอนฟิกให้ตอนบู๊ตเครื่อง ให้คอนฟิก static route โดยอัตโนมัติ แสดง routing table ใช้คำสั่ง netstat -rn เพื่อแสดง routing table ของเครื่อง [root@fc11-64a ~]# netstat -rn Kernel IP routing table Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface 192.168.3.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0 0.0.0.0         192.168.3.1     0.0.0.0         UG        [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้อธิบายการแก้ไข static route บน ลีนุกซ์ โดยจะมีทั้งการแสดง routing tablle ที่มีอยู่ การเพิ่ม ลบ route รวมทั้งวิธีการคอนฟิกให้ตอนบู๊ตเครื่อง ให้คอนฟิก static route โดยอัตโนมัติ</p>
<p><span id="more-932"></span></p>
<h4>แสดง routing table</h4>
<p>ใช้คำสั่ง netstat -rn เพื่อแสดง routing table ของเครื่อง</p>
<pre>[root@fc11-64a ~]# <strong>netstat -rn
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.3.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         192.168.3.1     0.0.0.0         UG        0 0          0 eth0</pre>
<p>อีกคำสั่งหนึ่งที่ให้ผลลัพธ์ใกล้เคียงกันคือคำสั่ง route -n</p>
<pre>[root@fc11-64a ~]# <strong>route -n
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.3.1     0.0.0.0         UG    0      0        0 eth0</pre>
<h4>เพิ่ม static route</h4>
<p>การเพิ่ม static route ไปยัง subnet สามารถทำได้โดยใช้คำสั่ง route add ระบุออปชั่น &#8216;-net&#8217; ตามด้วย subnet และ netmask ที่ต้องการ สุดท้ายระบุว่าไปทาง router หรือ gateway ตามหลัง ออปชั่น &#8216;gw&#8217;</p>
<pre>[root@fc11-64a ~]# <strong>route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.3.2</strong></pre>
<pre>[root@fc11-64a ~]# <strong>netstat -rn
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
<span style="color: #0000ff;"><strong>192.168.5.0     192.168.3.2     255.255.255.0   UG    0      0        0 eth0
</strong></span>192.168.3.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.3.1     0.0.0.0         UG    0      0        0 eth0</pre>
<p>การเพิ่ม static route ไปยัง host หรือเครื่อง ip address ที่ระบุ ทำได้โดยใช้คำสั่ง route add ระบุออปชั่น &#8216;-host&#8217; ตามด้วย ip address ปลายทาง สุดท้ายระบุว่าไปทาง router หรือ gateway ตามหลัง ออปชั่น &#8216;gw&#8217;</p>
<pre>[root@fc11-64a ~]# <strong>route add -host 192.168.5.10 gw 192.168.3.3</strong></pre>
<pre>[root@fc11-64a ~]# <strong>netstat -rn
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
<strong><span style="color: #0000ff;">192.168.5.10    192.168.3.3     255.255.255.255 UGH       0 0          0 eth0
</span></strong>192.168.5.0     192.168.3.2     255.255.255.0   UG        0 0          0 eth0
192.168.3.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         192.168.3.1     0.0.0.0         UG        0 0          0 eth0</pre>
<p>การเพิ่ม default gateway ทำได้โดย ใช้คำสั่ง route add ระบุออปชั่น &#8216;default gw&#8217; แล้วตามด้วย ip address ของ gateway หรือ router</p>
<pre>[root@fc11-64a ~]# <strong>route add default gw 192.168.3.4</strong></pre>
<pre>[root@fc11-64a ~]# <strong>netstat -rn
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.5.10    192.168.3.3     255.255.255.255 UGH       0 0          0 eth0
192.168.5.0     192.168.3.2     255.255.255.0   UG        0 0          0 eth0
192.168.3.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
<strong><span style="color: #0000ff;">0.0.0.0         192.168.3.4     0.0.0.0         UG        0 0          0 eth0
</span></strong>0.0.0.0         192.168.3.1     0.0.0.0         UG        0 0          0 eth0</pre>
<h4>ลบ static route</h4>
<p>การลบ static route ไปยัง subnet สามารถทำได้โดยใช้คำสั่ง route del ระบุออปชั่น &#8216;-net&#8217; ตามด้วย subnet และ netmask ที่ต้องการลบ และ &#8216;gw&#8217; ที่ชี้ไป</p>
<pre>[root@fc11-64a ~]# <strong>route del -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.3.2</strong></pre>
<p>การลบ static route ไปยัง host หรือเครื่อง ip address ที่ระบุ ทำได้โดยใช้คำสั่ง route del ระบุออปชั่น &#8216;-host&#8217; ตามด้วย ip address ปลายทาง สุดท้ายระบุว่าไปทาง router หรือ gateway ตามหลัง ออปชั่น &#8216;gw&#8217;</p>
<pre>[root@fc11-64a ~]# <strong>route del -host 192.168.5.10 gw 192.168.3.3</strong></pre>
<p>การลบ default gateway ทำได้โดย ใช้คำสั่ง route del ระบุออปชั่น &#8216;default gw&#8217; แล้วตามด้วย ip address ของ gateway หรือ router ที่ต้องการลบ</p>
<pre>[root@fc11-64a ~]# <strong>route del default gw 192.168.3.4</strong></pre>
<h4>ไฟล์ static-routes</h4>
<p>หากต้องการให้เครื่องลีนุกซ์คอนฟิกเพิ่ม static routes ที่ต้องการตอนบู๊ตเครื่องโดยอัตโนมัติ สามารถทำได้โดยการใส่ ข้อมูล route ไว้ในไฟล์ /etc/sysconfig/static-routes</p>
<p>ตัวอย่างไฟล์ สำหรับเพิ่ม static-routes ไปยัง subnet และ host ตามตัวอย่างด้านบน ให้คอนฟิกตอนบู๊ตเครื่อง</p>
<pre>[root@fc11-64a ~]# <strong>cat /etc/sysconfig/static-routes
</strong>any net 192.168.5.0 netmask 255.255.255.0 gw 192.168.3.2
any host 192.168.5.10 gw 192.168.3.3</pre>
<p>สำหรับ default gateway ต้องใส่เป็น ตัวแปรชื่อ &#8220;GATEWAY&#8221; ไว้ในไฟล์ /etc/sysconfig/network หรือไฟล์ /etc/sysconfig/network-scripts/ifcfg-eth0 ตัวอย่างเช่น</p>
<pre>[root@fc11-64a ~]# <strong>cat /etc/sysconfig/network
</strong>NETWORKING=yes
HOSTNAME=fc11-64a.spalinux.com
<strong><span style="color: #0000ff;">GATEWAY=192.168.3.4</span></strong></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/02/configure_linux_to_be_router">คอนฟิกลีนุกซ์ทำหน้าที่เป็น Router</a></li>
<li><a href="http://spalinux.com/2008/10/configure_policy_based_routing_on_linux">คอนฟิก Policy Based Routing บนลีนุกซ์</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/09/add_delete_static_route_on_linux/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

