|
|
|
¸®´ª½ºÆÁ Go Unix Power Tools Online Book
Go Bash Guide
|
|
Read No. 141 article |
2002-04-29 03:54:26 |
|
|
|
|
NickName |
Ç®ºñ´© |
Subject |
Advanced Routing HOWTO ¿ä¾à |
|
|
¿ø¹® : http://kltp.kldp.org/stories.php?story=01/10/03/7562565
±Û¾´ÀÌ : mysupper
http://linuxdoc.org/HOWTO/Adv-Routing-HOWTO.html
ÀÌ ¿øº» ÀÔ´Ï´Ù. ÇÙ½É Àç¹Ô´Â ³»¿ë¸¸ Ã߷ǽÀ´Ï´Ù. »ç½Ç ÀÌ°Ô °ÅÀÇ ´ä´Ï´Ù.
kldp¿¡ ¿Ã¸±±î 1ÃÊ »ý°¢Çß´Ù°¡ 100Ãʸ¸¿¡ docbook¸¦ ¸øÇÏ°í ¹è¿ì±âµµ
±¸ÂùŸ´Â °á·Ð³»°í ¸¶ ¿©±â ¿Ã¸³´Ï´Ù.
===============
±âº»±â ºÎÅÍ º¾´Ï´Ù.
===============
¾Æ·¡±ÛµéÀº ·¹µ«±âÁØÀÌ ¾Æ´Õ´Ï´Ù.
·¹µ«Àº /sbin/ip, /sbin/tc ¿¡ À§Ä¡ÇÏ°í ÀÖ´Â Á¡À» °¨¾ÈÇϼ¼¿ä
ip link list
ÀÎÅÍÆäÀ̽º,¸Æ¾îµå·¹½ºµîÀÇ Á¤º¸¸¦ º¸¿©ÁØ´Ù.
ip address show
ip ÁÖ¼Ò°ü·Ã Á¤º¸ Áß½ÉÀ¸·Î º¸¿©ÁØ´Ù.
ip route show
¶ó¿ìÆðü·Ã Á¤º¸¸¦ º¸¿©ÁØ´Ù.
ip¸í·É¾îÀÇ ¿É¼ÇÀº
/sbin/ip addr help
Usage: ip addr {add|del} IFADDR dev STRING
ip addr {show|flush} [ dev STRING ] [ scope SCOPE-ID ]
[ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ]
IFADDR := PREFIX | ADDR peer PREFIX
[ broadcast ADDR ] [ anycast ADDR ]
[ label STRING ] [ scope SCOPE-ID ]
SCOPE-ID := [ host | link | global | NUMBER ]
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG := [ permanent | dynamic | secondary | primary |
tentative | deprecated ]
¿Í °°Àº ¹æ¹ýÀ¸·Î ÀÚ¼¼ÇÑ »ç¿ë¹ýÀ» º¼¼ö ÀÖ½À´Ï´Ù.
man ÆäÀÌÁö´Â º¸Áö ¸¶½Ê½Ã¿ä. »è¸¸ Á×½À´Ï´Ù.
man ÆäÀÌÁö´Â ÀÌ ¹®¼ ´Ù ÀÐ°í º¸½Ã¸é µµ¿òÀÌ µÉ ¼öµµ ÀÖ½À´Ï´Ù.
=============
¶ó¿ìÆà ·êÀÇ Á¶Á¤
=============
µðÆúÆ® ¶ó¿ìÆà ·ê º¸±â
ip rule list
¶óÀÌÆà ·ê Á¶Á¤ ¿¹Á¦
°¡Á¤ ; 2°³ÀÇ ÄÉÀÌºí ¸ðµ©ÀÌ ÀÖÀ¸¸ç µÑ´Ù linux NAT masquerading router¿¡ ¿¬
°áµÇ¾î ÀÖ´Ù.
°í°´ÀÌ 2¸íÀε¥, ¼º°Ý³ª»Û johnÀº hotmail ¸¸ º¸´Â Á¤µµ·Î¸¸ »ç¿ëÇÏ°í ¼Óµµ°¡
´À¸° ÄÉÀ̺í¸ðµ©¿¡´Ù ºÙÀδÙ.
ÄÉÀÌºí ¸ðµ© µÎ°³Áß ¼Óµµ°¡ ºü¸¥ ³ÑÀº 212.64.94.251ÀÇ ip·Î¼ 212.64.91ÀÇ
ppp·Î ¿¬°áµÈ´Ù.
´À¸° ÄÉÀÌºí ¸ðµ©Àº 212.64.78.148 ÀÇ ip·Î¼ 195.96.98.253À¸·Î ¿¬°áµÈ´Ù.
linux NAT masquerading routeÀÇ ±âº» ¼¼ÆÃÀÌ ¾Æ·¡¿Í °°Àº °æ¿ì
[ahu@home ahu]$ ip route list table local
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
local 10.0.0.1 dev eth0 proto kernel scope host src 10.0.0.1
broadcast 10.0.0.0 dev eth0 proto kernel scope link src 10.0.0.1
local 212.64.94.251 dev ppp0 proto kernel scope host src 212.64.94.251
broadcast 10.255.255.255 dev eth0 proto kernel scope link src 10.0.0.1
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
local 212.64.78.148 dev ppp2 proto kernel scope host src 212.64.78.148
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
[ahu@home ahu]$ ip route list table main
195.96.98.253 dev ppp2 proto kernel scope link src 212.64.78.148
212.64.94.1 dev ppp0 proto kernel scope link src 212.64.94.251
10.0.0.0/8 dev eth0 proto kernel scope link src 10.0.0.1
127.0.0.0/8 dev lo scope link
default via 212.64.94.1 dev ppp0
À§ »óÅ¿¡¼ johnÀ» À§ÇÑ Å×À̺íÀ» Ãß°¡ÇÏ¸é µÇ°Ù´Ù.
# echo 200 John >> /etc/iproute2/rt_tables
# ip rule add from 10.0.0.10 table John
# ip rule ls
0: from all lookup local
32765: from 10.0.0.10 lookup John
32766: from all lookup main
32767: from all lookup default
Ãß°¡ ÇÑ ÈÄ johnÀÇ Å×À̺íÀ» ¶ó¿ìÆà Å×ÀÌºí¿¡ ³Ö°í ¶ó¿ìÆà ij½¬¸¦ »õ·Î ¸¸µé
¸é
johnÀÌ ¾²±â ½ÃÀÛÇÒ ¼ö ÀÖ´Ù.
# ip route add default via 195.96.98.253 dev ppp2 table John
# ip route flush cache
==============
tunneling
==============
¾à°£ÀÇ ±âº»±âºÎÅÍ º¸ÀÚ
ÅͳθµÀº ¸®´ª¼ ¼¼°¡Áö´Ù. ; ip in ip ¹æ½Ä, GRE ¹æ½Ä, Ä¿³Î¿ÜºÎÀÇ ÅͳÎ
À߸ø ¼¼ÆÃÇÏ¸é ³¸®³ª¹Ç·Î µðÆúÆ® ¶ó¿ìÆà Å×À̺íÀ» Åͳθµ µð¹ÙÀ̽º·Î º¸³»Áö
¸»°Í.
Åͳθµ½Ã ip header¿¡ 20byte°¡ Ãß°¡ µÇ¹Ç·Î ´ëÇü ³×¶±¼´Â IP packet
fragmentation/reassemblyÀ» È®ÀÎÇØ µÑ°Í.
°¡Àå ºü¸¥ ÅͳθµÀº ¾çÂÊÀ» ¸ðµÎ ÅͳθµÇÏ´Â °ÍÀÌ´Ù.
¿©±â¼´Â IPv4 GRE Åͳθµ¸¸ À̾߱âÇغ»´Ù. ½ÇÁ¦·Î À̰ɷεµ ÃæºÐÇÏ´Ù.
°¡Á¤ ;
3°³ÀÇ ³×¶±ÀÌ ÀÖ°í a - c -bÀÇ ÇüÅ·Π¿¬°áµÈ´Ù.
network a:
network 10.0.1.0
netmask 255.255.255.0
router 10.0.1.1
network b:
network 10.0.2.0
netmask 255.255.255.0
router 10.0.2.1
c´Â aÂÊÀ¸·Î ip 172.16.17.18·Î ¿¬°áµÇ°í À̸¦ neta¶ó ¸í¸íÇÏ°í
b ÂÊÀ¸·Î ip 172.19.20.21·Î ¿¬°áµÇ¸ç À̸¦ netb¶ó ºÎ¸£ÀÚ.
À̶§ gre tunnelingÀ¸·Î ¿¬°áÇÏ·Á¸é,
aÂÊ¿¡¼
ip tunnel add netb mode gre remote 172.19.20.21 local 172.16.17.18 ttl
255
ip addr add 10.0.1.1 dev netb
ip route add 10.0.2.0/24 dev netb
ÀÌ °ÍÀº °á±¹,
ùÁÙ¿¡¼ ÅͳÎÀåÄ¡ netb¸¦ ¸¸µé°í GREÅͳθµÀ» ÀÌ¿ëÇÏ°Ô Çؼ netb°¡
172.16.17.18¿¡¼
¿À´Â ÆÐŶÀº 172.19.20.21·Î º¸³»°Ô ÇÑ´Ù. (TTL Àº 255)
µÑ°ÁÙ¿¡¼ ùÁÙ¿¡¼ ¸¸µç netb¿¡ ip ÁÖ¼Ò 10.0.0.1À» ÇÒ´çÇÞ´Ù.
¼Â°ÁÙ¿¡¼ netbÀÇ ÆÐŶÀÌ ³×¶± b ·Î¸¸ ¿¬°áµÇ°Ô ³×¶± b ÀÇ ³×Æ®¿÷ÀÎ
10.0.2.0/24·Î ¿¬°á½ÃÄÖ´Ù.
b ÂÊ¿¡¼ °°Àº ¹æ½ÄÀ¸·Î,
ip tunnel add neta mode gre remote 172.16.17.18 local 172.19.20.21 ttl
255
ip addr add 10.0.2.1 dev neta
ip route add 10.0.1.0/24 dev neta
ÇØÁÖ¸é ¶¯ÀÌ´Ù.
ÅͳθµÀ» Á×À϶§´Â
aÀÇ °æ¿ì
ip link set netb down
ip tunnel del netb
bÀÇ °æ¿ì
ip link set neta down
ip tunnel del neta
ÇØÁÖ¸é ¶¯ÀÌ´Ù.
==========================
CBQ¸¦ ÀÌ¿ëÇؼ ´ë¿ªÆø Á¦ÇÑÇϱâ
==========================
¸®´ªÀÌ ¿³ª Á¸°ÍÀ» Áõ¸íÇÒ ¶§´Ù.!!
Ä¿³Î ÄÄÆÄÀϽÃ
[*] QoS and/or fair queueing (EXPERIMENTAL)
< > CBQ packet scheduler (NEW)
< > SFQ queue (NEW)
¸¦ ²À ³Ö¾î¾ß ÇÑ´Ù.
±âº»±â ºÎÅÍ º¸ÀÚ.°£´ÜÇÏ´Ù.
filter¸¦ ÀÌ¿ëÇؼ ÆÐŶµéÀ» queue·Î º¸³»°í queue°¡ ÆÐŶµéÀ» º¸³¾Áö ¸»Áö ¾î
¶² ¼ø¼·Î º¸³¾Áö¸¦ °áÁ¤Çؼ º¸³½´Ù.
filter ·Î¼ fwmark, u32¸¦ º¸Åë ¾²´Âµ¥,
fwmark´Â ¸®´ªÀÇ ³ÝÇÊÅÍ Äڵ带 ¹Þ´Âµ¥ ¾²°í
u32´Â ¾Æ¹«´ë³ª ´Ù ¾µ¼ö ÀÖ´Ù.
¿¹¸¦ µé¾î Çغ¸ÀÚ
10¸Þ°¡ ¼ÓµµÀÇ ¶óÀÎÀ» ³»°¡°®°íÀÕ´Ù.
±×·³ ÀÌ ÇϳªÀÇ ¶óÀÎÀ» ¸®´ª½º ¹Ú½º¸¦ ÀÌ¿ëÇؼ µÎ°³ÀÇ ¼·Î ´Ù¸¥ »ç¿ëÀÚ
¿¡°Ô °¢°¢ ¼Óµµ Á¦ÇÑÀ» ½ÃÄѺ¸ÀÚ. µÎ »ç¿ëÀÚÀÇ À̸§Àº '¿Õ¹Ù¹ö' ¿Í '¿ÕõÀç'
ÀÌ´Ù.
¿¹Á¦·Î¼ '¿Õ¹Ù¹ö'´Â ÃÖ´ë 2 ¸Þ°¡ '¿ÕõÀç'´Â ÃÖ´ë 8¸Þ°¡¸¦ ¾²°Ô ÇØÁØ´Ù°í °¡
Á¤ÇÏÀÚ.
¸®´ª¹Ú½º¿¡ ·£Ä«µå µÎ°³¸¦ ¹Ú°í eth1Àº ÀÎÅͳÝÂÊ¿¡ eth0 ´Â Çãºê¿¡ ¿¬°á½ÃÅ°
°í
¸®´ª¹Ú½º¸¦ ¼¼ÆÃÇØ °¡´Â ¼ø¼´ë·Î ¼³¸íÇغ¸¸é,
tc qdisc add dev eth0 root handle 10: cbq bandwidth 10Mbit avpkt 1000
eth0 ¿¡´Ù Æò±ÕÆÐŶ»çÀÌÁî 1000 ¿ÁÅÝÀ¸·Î 10¸Þ°¡ ÃÖ´ë ¼Óµµ·Î ·çÆ® ÇÚµé 10:
À» ¸Í±ä´Ù.
tc class add dev eth0 parent 10:0 classid 10:1 cbq bandwidth 10Mbit rate
\
10Mbit allot 1514 weight 1Mbit prio 8 maxburst 20 avpkt 1000
À§¿¡¼ ¸¸µç ·çÆ®ÇÚµé 10: ¿¡´Ù°¡ 10:1 À̶ó´Â Ŭ·¡½º¸¦ ¸¸µå´Âµ¥
ÀÌ Å¬¶ó½ºÀÇ MTU 1514 À̸ç avpkt 1000 À̸ç 1¸Þ°¡ºø ´ÜÀ§·Î ²÷¾î¼ Á¶Á¤ÇÑ
´Ù.
tc class add dev eth0 parent 10:1 classid 10:100 cbq bandwidth 10Mbit
rate \
8Mbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 1000 \
bounded
Ŭ¶ó½º 10:100À» ¸Í±æ¾î ³»´Âµ¥ bounded ¿É¼ÇÀ» ÀÌ¿ëÇؼ 10¸Þ°¡Áß 8¸Þ°¡ »óÇÑ
¼±À¸·Î ¸Í±ä´Ù.
tc class add dev eth0 parent 10:1 classid 10:200 cbq bandwidth 10Mbit
rate \
2Mbit allot 1514 weight 200Kbit prio 5 maxburst 20 avpkt 1000 \
bounded
Ŭ¶ó½º 10:200À» ¸Í±â´Âµ¥ 10¸Þ°¡Áß 2¸Þ°¡ »óÇѼ±À¸·Î ¸Í±ä´Ù.
À§ÀÇ °ÍÀ¸·Î Ŭ¶ó½º¸¦ »ý¼ºÇß´Ù.
ÀÌÁ¦ ÆÐŶƮ·¡ÇÈÀ» ·ê¿¡ µû¶ó º¸³½´Ù.
º¸³»´Â ¹æ¹ýÀº sfq¸¦ ÀÌ¿ëÇÑ´Ù.
tc qdisc add dev eth0 parent 10:100 sfq quantum 1514b perturb 15
tc qdisc add dev eth0 parent 10:200 sfq quantum 1514b perturb 15
¸¶Áö¸·À¸·Î
°¢°¢ÀÇ Å¬¶ó½º·Î µé¿À´Â ÆÐŶµéÀ» Á¦ÇÑÇØÁØ´Ù.
tc filter add dev eth0 parent 10:0 protocol ip prio 100 u32 match ip dst
\
150.151.23.24 flowid 10:200
tc filter add dev eth0 parent 10:0 protocol ip prio 25 u32 match ip dst
\
150.151.0.0/16 flowid 10:100
¹ú½á ´«Ä¡ ê°ÚÁö¸¸,
150.151.23.24´Â '¿ÕõÀç'ÀÇ ÆÐŶÀÌ°í
150.151.0.0/16Àº '¿Õ¹Ùº¸'ÀÇ ÆÐŶÀÌ´Ù.
ÀÌ·¸°Ô Çϸé downstreamÂÊ Áï, eth0ÂÊÀº ³¡ÀÌ´Ù.
upstream Áï, eth1Âʵµ À§¿Í °°Àº ¹æ½ÄÀ¸·Î ¾Æ·¡¿Í °°ÀÌ ¼¼ÆÃÇÑ´Ù .
# tc qdisc add dev eth1 root handle 20: cbq bandwidth 10Mbit avpkt 1000
# tc class add dev eth1 parent 20:0 classid 20:1 cbq bandwidth 10Mbit
rate \
10Mbit allot 1514 weight 1Mbit prio 8 maxburst 20 avpkt 1000
# tc class add dev eth1 parent 20:1 classid 20:100 cbq bandwidth 10Mbit
rate \
8Mbit allot 1514 weight 800Kbit prio 5 maxburst 20 avpkt 1000 \
bounded
# tc class add dev eth1 parent 20:1 classid 20:200 cbq bandwidth 10Mbit
rate \
2Mbit allot 1514 weight 200Kbit prio 5 maxburst 20 avpkt 1000 \
bounded
# tc qdisc add dev eth1 parent 20:100 sfq quantum 1514b perturb 15
# tc qdisc add dev eth1 parent 20:200 sfq quantum 1514b perturb 15
# tc filter add dev eth1 parent 20:0 protocol ip prio 100 u32 match ip
src \
150.151.23.24 flowid 20:200
# tc filter add dev eth1 parent 20:0 protocol ip prio 25 u32 match ip
src \
150.151.0.0/16 flowid 20:100
=====================
ÆÐŶÇÊÅ͸µ°ú «»ÍÀ¸·Î ¾²±â
=====================
°£´ÜÇÏ°Ô ¸»ÇÏÀÚ¸é ³ÝÇÊÅÍ¿¡´Ù°¡ À̸§Ç¥¸¦ ºÙÀÌ°í
iproute¿¡¼ ÇØ´ç À̸§Ç¥¸¦ »ç¿ëÇÏ´Â °ÍÀÌ´Ù.
Ä¿³Î¿¡,
IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
IP: policy routing (CONFIG_IP_MULTIPLE_TABLES) [Y/n/?]
IP: use netfilter MARK value as routing key (CONFIG_IP_ROUTE_FWMARK)
[Y/n/?]
¿ä°ÍµéÀ» ³ÖÀÚ
³ÝÇÊÅÍ¿¡¼ À̸§Ç¥¸¦ ºÙÀ϶§´Â --set-mark ¸¦ ÀÌ¿ëÇÑ´Ù.
¿¹¸¦ µéÀÚ.
Á» ´À·Áµµ »ó°ü¾ø´Â ¸ÞÀÏÆÐŶÀ» ´À¸°¶óÀο¡´Ù ºÙÀÌ°í ½Í´Ù.!
iptables -A PREROUTING -i eth0 -t mangle -p tcp --dport 25 \
-j MARK --set-mark 1
25¹ø Æ÷Æ®¿¡ µé¿À´Â tcpÆÐŶÀ» À̸§Ç¥ 1 ·Î ºÙ¿´´Ù.
# echo 201 mail.out >> /etc/iproute2/rt_tables
# ip rule add fwmark 1 table mail.out
# ip rule ls
0: from all lookup local
32764: from all fwmark 1 lookup mail.out
32766: from all lookup main
32767: from all lookup default
À̸§Ç¥ 1 À» °®´Â ÆÐŶÀ» mail.outÀ̶ó´Â À̸§ÀÇ Å×À̺í·Î ¸Í±æ¾ú´Ù.
/sbin/ip route add default via 195.96.98.253 dev ppp0 table mail.out
mail.out À̶ó´Â Å×À̺í»óÀÇ ÆÐŶÀº ppp0 195.96.98.253·Î ³ª°£´Ù.
========================================
telnet, ssh¿Í °°Àº interactive traffic¿¡ ¿ì¼±±ÇÀ» ÁÖ±â
========================================
Á¦¸ñÀº ±æÁö¸¸ °á±¹ ftpÂÊ¿¡ ·Îµå°¡ ½ÉÇÒ¶§ ÅÚ³ÝÀÌ ¹ö¹÷°Å¸®´Â °æ¿ì
¾È¹ö¹÷°Å¸®°Ô(?) ½áº¸ÀÚ´Â °Å´Ù.
Ä¿³ÎÄÄÆȽà ÇÊ¿äÇÑ °Íµé
/proc filesystem suport
Sysctl support
[*] IP: advanced router
[ ] IP: use TOS value as routing key (NEW)
<*> IP tables support
< > TOS match support (NEW)
ºÎÆÃÈÄ
echo ¡°1¡± > /proc/sys/net/ipv4/ip_forward
¿ä·¸°Ô Áغñ¸¦ Çصθé,
ÆÐŶ¿¡ TOS¸¦ ºÙÀϼö ÀÖ´Ù.
ºÙÀϼöÀÖ´Â Á¾·ù¿Í Àǹ̴Â
"Minimum Delay", "Maximum Throughput", "Maximum Reliability"
and "Minimum Cost"
4°³´Ù.
±×·¯¸é Á¦¸ñ´ë·Î Á¶Á¤ÇØÁÖ·Á¸é
# iptables -A PREROUTING -t mangle -p tcp --sport telnet \
-j TOS --set-tos Minimize-Delay
# iptables -A PREROUTING -t mangle -p tcp --sport ftp \
-j TOS --set-tos Minimize-Delay
# iptables -A PREROUTING -t mangle -p tcp --sport ftp-data \
-j TOS --set-tos Maximize-Throughput
# iptables -A OUTPUT -t mangle -p tcp --dport telnet \
-j TOS --set-tos Minimize-Delay
# iptables -A OUTPUT -t mangle -p tcp --dport ftp \
-j TOS --set-tos Minimize-Delay
# iptables -A OUTPUT -t mangle -p tcp --dport ftp-data \
-j TOS --set-tos Maximize-Throughput
ÇØÁÖ¸é ¶¯ÀÌ´Ù.
|
|
Page Loading [ 0.04 Sec ]
SQL Time [ 0 Sec ]
|
|
|