route 명령어 (AIX 5.3·6.1)

핵심 정리

  • 라우팅 표에 경로를 손으로 더하고(add), 지우고(delete), 바꾸고(change), 찾아보고(get), 모두 비웁니다(flush, -f). 바꾸기는 root만 할 수 있습니다.
  • 기본 게이트웨이: route add default 10.1.1.1(또는 route add 0 10.1.1.1). 네트워크 경로: route add -net 192.168.10.0 -netmask 255.255.255.0 10.1.1.254.
  • -net·-host를 주지 않으면 주소의 호스트 부분이 0일 때 네트워크, 아니면 호스트로 봅니다.
  • route로 더한 경로는 재부팅하면 사라집니다. 영구로 하려면 chdev -l inet0 -a route=net,-hopcount,0,,0,10.1.1.1이나 smitty mkroute로 ODM에 넣습니다.
  • 지금 경로는 netstat -rn으로 봅니다. 다중 경로일 때 -policy(1~5)와 -weight로 나눠 보내는 방식을 정합니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 -i(WPAR별 라우팅)와 -@ WparName이 더해짐)
원문 IBM Commands Reference — 5.3 Volume 4, 6.1 Volume 4
파일 /usr/sbin/route, /etc/hosts, /etc/networks
관련 명령어 netstat -rn, ifconfig, chdev -l inet0, mktcpip, no

목적

라우팅 표를 손으로 다룹니다.

영어 원문

Manually manipulates the routing tables.

구문

text
route [ -f ] [ -n ] [ -q ] [ -C ] [ -v ] Command [ Family ]
      [ [ -net | -host ] Destination [ -prefixlen n ] [ -netmask [ Address ] ] Gateway ]
      [ Arguments ] [ -i ] [ -@ WparName ]

-i와 -@ WparName은 6.1 구문에만 있습니다.

설명

route 명령으로 네트워크 라우팅 표에 항목을 손으로 넣습니다. Destination 변수의 네트워크 주소를 해석해 호스트로 가는 경로와 네트워크로 가는 경로를 구분하며, Destination은 이름이나 숫자 주소로 줄 수 있습니다. 이름은 모두 /etc/hosts나 네트워크 이름 서버로 주소로 바꿉니다.

특정 호스트로 가는 경로와 네트워크로 가는 경로는 목적지의 인터넷 주소를 해석해 구분합니다. 선택 키워드 -net과 -host는 목적지를 각각 네트워크나 호스트로 해석하게 합니다. 목적지의 로컬 주소 부분이 INADDR_ANY이거나 목적지가 네트워크 이름이면 네트워크로 가는 경로로 보고, 아니면 호스트로 가는 경로로 봅니다.

예를 들어 128.32는 -host 128.0.0.32로, 128.32.130은 -host 128.32.0.130으로, -net 128.32는 128.32.0.0으로, -net 128.32.130은 128.32.130.0으로 해석합니다.

경로가 게이트웨이가 아니라 인터페이스를 거친다면 -interface 인수를 줍니다. 이때 지정한 게이트웨이는 공통 네트워크에 있는 호스트의 주소로, 송신에 쓸 인터페이스를 가리킵니다.

-netmask 인수 뒤에는 넷마스크로 해석할 주소가 와야 합니다. 이 옵션을 Destination 뒤에 두면 -inet에서 암묵적으로 만드는 넷마스크를 덮어쓸 수 있습니다.

목적지나 게이트웨이에 준 이름은 먼저 gethostbyname으로 호스트 이름으로 찾고, 실패하면 getnetbyname으로 네트워크 이름으로 찾습니다.

참고: route는 라우팅 소켓과 메시지 유형 RTM_ADD, RTM_DELETE, RTM_CHANGE를 씁니다. 그래서 root만 라우팅 표를 바꿀 수 있습니다.

flush 명령이나 -f를 주면 라우팅 표에서 모든 게이트웨이 항목을 비웁니다. 주소 패밀리를 나타내는 선택 키워드를 주면 그 패밀리의 목적지만 비웁니다.

지금 라우팅 정보는 netstat -r로 봅니다.

영어 원문

The route command allows you to make manual entries into the network routing tables. The route command distinguishes between routes to hosts and routes to networks by interpreting the network address of the Destination variable, which can be specified either by symbolic name or numeric address. The route command resolves all symbolic names into addresses, using either the /etc/hosts file or the network name server.

Routes to a particular host are distinguished from those to a network by interpreting the Internet address associated with the destination. The optional phs -net and -host force the destination to be interpreted as a network or a host, respectively. If the destination has a local address part of INADDR_ANY or if the destination is the symbolic name of a network, then the route is assumed to be to a network; otherwise, it is presumed to be a route to a host.

For example, 128.32 is interpreted as -host 128.0.0.32; 128.32.130 is interpreted as -host 128.32.0.130; -net 128.32 is interpreted as 128.32.0.0; and -net 128.32.130 is interpreted as 128.32.130.0.

If the route is by way of an interface rather than through a gateway, the -interface argument should be specified. The specified gateway is the address of the host on the common network, indicating the interface to be used for transmission.

The -netmask argument must be followed by an address parameter (to be interpreted as a network mask). One can override the implicit network mask generated in the -inet case by making sure this option follows the Destination parameter.

All symbolic names specified for a destination or gateway are looked up first as a host name, using the gethostbyname subroutine. If this fails, the getnetbyname subroutine is then used to interpret the name as a network name.

Note: Route uses a routing socket and the new message types RTM_ADD, RTM_DELETE, and RTM_CHANGE. As such, only the root user may modify the routing tables.

If the flush or -f command is specified, route will "flush," or clear, the routing tables of all gateway entries. One can choose to flush only those routes whose destinations are of a given address family, by specifying an optional ph describing which address family.

The netstat -r command displays the current routing information contained in the routing tables.

플래그

플래그 설명
-f 네트워크 인터페이스와 연결되지 않은 라우팅 표 항목을 모두 지웁니다.
-i WPAR별 라우팅을 켭니다. 기본으로 WPAR에서 나가는 트래픽은 전역 환경에서 보내는 것처럼 라우팅됩니다. 곧 같은 전역 시스템에 있는 주소끼리의 트래픽은 루프백 인터페이스로 가고, 전역 시스템에 구성된 라우팅 항목(기본 경로 포함)을 씁니다. -i를 주면 WPAR가 자기 라우팅 표를 만들어 쓰며, WPAR의 네트워크 주소마다 브로드캐스트·루프백·서브넷 경로가 자동으로 만들어집니다. 6.1부터
-n flush나 자세한 모드의 결과를 보여 줄 때 호스트와 네트워크 이름 대신 숫자로 보여 줍니다.
-q 조용한 모드. 모든 출력을 막습니다.
-C 경로를 더하고 지울 때 라우팅 메시지보다 ioctl 호출을 씁니다.
-v 자세한 모드. 추가 정보를 출력합니다.
-net Destination을 네트워크로 해석합니다.
-netmask 목적지 주소의 넷마스크. Destination 뒤에 둡니다.
-host Destination을 호스트로 해석합니다.
-prefixlen n 목적지 접두사 길이(넷마스크의 비트 수).
-@ WparName 그 WPAR와 연결된 네트워크 통계를 보여 줍니다. 이름이 없으면 모든 WPAR의 통계를 보여 줍니다. 6.1부터

경로의 기본은 호스트(네트워크의 컴퓨터 한 대)입니다. -net도 -host도 주지 않았는데 주소의 네트워크 부분만 지정했으면(호스트 부분이 0이면) 네트워크로 가는 경로로 봅니다.

영어 원문
  • -f — Purges all entries in the routing table that are not associated with network interfaces.
  • -i — Enables workload-partition-specific routing for the workload partition (WPAR). By default, outgoing network traffic from a WPAR is routed as if it were being sent from the global environment: • Traffic between addresses that are hosted on the same global system is sent through the loopback interface. • Routing table entries that are configured in the global system, including the default route, are used to transmit workload partition traffic. If you enable WPAR-specific routing by specifying the -i flag, the WPAR creates and uses its own routing table for the outgoing traffic. Routing entries are created automatically for each of the network addresses of the WPAR to accommodate broadcast, loopback, and subnet routes.
  • -n — Displays host and network names numerically, rather than symbolically, when reporting results of a flush or of any action in verbose mode.
  • -q — Specifies quiet mode and suppresses all output.
  • -C — Specifies preference for ioctl calls over routing messages for adding and removing routes.
  • -v — Specifies verbose mode and prints additional details.
  • -net — Indicates that the Destination parameter should be interpreted as a network.
  • -netmask — Specifies the network mask to the destination address. Make sure this option follows the Destination parameter.
  • -host — Indicates that the Destination parameter should be interpreted as a host.
  • -prefixlen n — Specifies the length of a destination prefix (the number of bits in the netmask).
  • -@WparName — Displays the network statistics that are associated with the WPAR that is, (@WparName flag). If the @WparName flag is not specified, the network statistics for all the WPARs are displayed.

The route default is a host (a single computer on the network). When neither the -net parameter nor the -host parameter is specified, but the network portion of the address is specified, the route is assumed to be to a network. The host portion of the address is 0 (zero).

매개변수

매개변수 설명
Command add(경로 더하기), flush 또는 -f(모든 경로 지우기), delete(특정 경로 지우기), change(게이트웨이 같은 경로 속성 바꾸기), monitor(라우팅 정보 변경, 조회 실패, 네트워크 분할 의심을 보고), get(목적지의 경로를 찾아 보여 주기), set(경로의 정책과 가중치 정하기)
Family 주소 패밀리. 기본은 -inet이고, -inet6을 주면 뒤에 오는 주소를 모두 inet6으로 봅니다.
Destination 경로를 보낼 호스트나 네트워크. 이름이나 숫자 주소로 줍니다.
Gateway 패킷을 보낼 게이트웨이. 이름이나 숫자 주소로 줍니다.
Arguments 아래 인수 가운데 하나 이상. n은 양의 정수입니다.
인수 설명
-active_dgd 경로에 능동 죽은 게이트웨이 감지(DGD)를 켭니다.
-cloning 새 경로를 복제합니다.
-genmask 복제 경로를 만들 때 쓰는 TSEL 길이를 뽑습니다.
-interface 인터페이스 라우팅 항목을 다룹니다.
-rtt n, -rttvar n 왕복 시간과 그 분산.
-sendpipe n, -recvpipe n 송신·수신 창 크기.
-allowgroup gid 경로를 쓸 수 있는 그룹 ID. 허용 목록에 더하거나 거부 목록에서 지웁니다.
-denygroup gid 경로를 쓸 수 없는 그룹 ID. 거부 목록에 더하거나 허용 목록에서 지웁니다.
-stopsearch 조회가 이 경로와 맞지만 그룹 라우팅 제한 때문에 쓸 수 없으면 더 찾지 않습니다.
-mtu n 이 경로의 MTU. 인터페이스 최대 MTU를 넘지 않는 한 TCP 응용 프로그램의 인터페이스 MTU를 덮어씁니다. UDP에는 영향이 없습니다.
-hopcount n 경로의 최대 게이트웨이 수. netstat -C의 사용자 설정 비용입니다.
-policy n 다중 경로 라우팅 정책. 1 가중 라운드 로빈, 2 무작위, 3 가중 무작위, 4 최저 사용률, 5 해시 기반. 정하지 않으면 no의 mpr_policy를 따르고, WRR로 명시하면 mpr_policy보다 우선합니다. 가중치가 모두 1이면 WRR은 라운드 로빈과 같습니다.
-weight n 다중 경로의 가중 정책에 쓸 경로 가중치.
-expire n 라우팅 프로토콜이 쓰는 만료 값.
-ssthresh n 나가는 게이트웨이 버퍼 한도.
-lock, -lockrest 메트릭 수정자를 하나씩 잠그는 메타 수정자(잠글 수정자 앞마다 둠), 뒤의 메트릭을 모두 잠그는 메타 수정자.
-if ifname 이 경로와 연결할 인터페이스(en0, tr0 등). 이 경로를 고르면 그 인터페이스로 보냅니다.
-xresolve 쓸 때 메시지를 냅니다(외부 조회용).
-iface 목적지에 직접 닿을 수 있습니다.
-static, -nostatic 손으로 더한 경로, 커널이나 데몬이 더한 것처럼 보이는 경로.
-reject 일치하면 ICMP unreachable을 보냅니다.
-blackhole 갱신하는 동안 패킷을 조용히 버립니다.
-proto1, -proto2 프로토콜별 라우팅 플래그 1·2를 켭니다.
영어 원문
  • Arguments — Specifies one or more of the following arguments. Where n is specified as a variable to an argument, the value of the n variable is a positive integer. -active_dgd Enables Active Dead Gateway Detection on the route. -cloning Clones a new route. -genmask Extracts the length of TSEL, which is used for the generation of cloned routes. -interface Manipulates interface routing entries. -rtt n Specifies round-trip time. -rttvar n Specifies round-trip time variance. -sendpipe n Specifies send-window size. -recvpipe n Specifies receive-window size. -allowgroup gid Specifies a group ID that is allowed to use the route. The group ID will be added to a list of allowed groups or deleted from a list of denied groups. -denygroup gid Specifies a group ID that is not allowed to use the route. The group ID will be added to a list of denied groups or deleted from a list of allowed groups. -stopsearch Stops searching if a routing table lookup matches the route, but it is not allowed to use the route due to group routing restrictions. -mtu n Specifies maximum transmission unit for this route. Will override interface mtu for TCP applications as long as it does not exceed maximum mtu for the interface. This flag has no affect on mtu for applications using UDP. -hopcount n Specifies maximum number of gateways in the route. -policy n Specifies the policy to be used for Multipath Routing. n is number between 1 and 5 where these numbers mean the following: 1. Weighted Round-Robin 2. Random 3. Weighted Random 4. Lowest Utilization 5. Hash-based If the policy is not explicitly set and multipath routing is used, then the global no command option called mpr_policy determines the policy that will be used. The default policy is Weighted Round Robin which behaves just like Round-Robin when the weights are all 1. Although the Default policy is Weighted Round-Robin, when the policy is not set, then the network option mpr_policy takes precedence. On the other hand, if the policy is explicitly set to WRR then this setting overrides the mpr_policy setting. For more information about these policies, see the no command. -weight n Specifies the weight of the route that will be used for the Weighted policies with the Multipath Routing feature. -expire n Specifies expiration metrics used by routing protocol -ssthresh n Specifies outbound gateway buffer limit. -lock Specifies a meta-modifier that can individually lock a metric modifier. The -lock meta-modifier must precede each modifier to be locked. -lockrest Specifies a meta-modifier that can lock all subsequent metrics. -if ifname Specifies the interface (en0, tr0 ...) to associate with this route so that packets will be sent using this interface when this route is chosen. -xresolve Emits a message on use (for external lookup). -iface Specifies that the destination is directly reachable. -static Specifies the manually added route. -nostatic Specifies the pretend route that is added by the kernel or daemon. -reject Emits an ICMP unreachable when matched. -blackhole Silently discards packets during updates. -proto1 Sets protocol specific routing flag number 1. -proto2 Sets protocol specific routing flag number 2.
  • Command — Specifies one of six possibilities: add Adds a route. flush or -f Removes all routes. delete Deletes a specific route. change Changes aspects of a route (such as its gateway). monitor Reports any changes to the routing information base, routing lockup misses, or suspected network partitionings. get Lookup and display the route for a destination. set Set the policy and weight attributes of a route.
  • Family — Specifies the address family. The -inet address family is the default. The -inet6 family specifies that all subsequent addresses are in the inet6 family.
  • Destination — Identifies the host or network to which you are directing the route. The Destination parameter can be specified either by symbolic name or numeric address.
  • Gateway — Identifies the gateway to which packets are addressed. The Gateway parameter can be specified either by symbolic name or numeric address.

보안

RBAC 사용자와 Trusted AIX 사용자는 주의하세요. 이 명령은 특권 작업을 할 수 있으며, 특권 작업은 특권 사용자만 할 수 있습니다. 특권과 권한 목록은 lssecattr 명령이나 getcmdattr 하위 명령으로 봅니다(6.1 문서에만 있음).

영어 원문

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

예제

명령 하는 일
route add 192.100.201.7 192.100.13.7 다른 네트워크의 컴퓨터 192.100.201.7(목적지)로 가는 경로를 게이트웨이 192.100.13.7로 정함
route add -net 192.100.201.0 192.100.13.7 네트워크 192.100.201.0(목적지)으로 가는 경로를 게이트웨이 192.100.13.7로 정함
route add 0 192.100.13.7 기본 게이트웨이를 192.100.13.7로. 목적지 0이나 default는 따로 정의하지 않았고 직접 연결되지 않은 모든 목적지를 뜻함
route -f 호스트 게이트웨이 표를 비움
route add 192.158.2.2 192.158.2.5 -weight 5 -policy 4 가중치와 정책을 주어 경로를 더함
route set 192.158.2.2 192.158.2.5 -weight 3 -policy 4 이미 있는 경로의 가중치와 정책을 바꿈

자주 쓰는 형태:

bash
netstat -rn                                              # 지금 경로
route add default 10.1.1.1                               # 기본 게이트웨이
route add -net 192.168.10.0 -netmask 255.255.255.0 10.1.1.254
route delete -net 192.168.10.0 -netmask 255.255.255.0 10.1.1.254
route get 192.168.10.5                                   # 이 목적지가 어느 경로로 가는지
lsattr -El inet0 -a route                                # ODM에 있는 영구 경로
chdev -l inet0 -a route=net,-hopcount,0,-netmask,255.255.255.0,,,192.168.10.0,10.1.1.254   # 영구 경로 더하기
영어 원문
  1. To establish a route so that a computer on one network can send a message to a computer on a different network, type:

route add 192.100.201.7 192.100.13.7

The 192.100.201.7 address is that of the receiving computer (the Destination parameter). The 192.100.13.7 address is that of the routing computer (the Gateway parameter).

  1. To establish a route so you can send a message to any user on a specific network, type: route add -net 192.100.201.0 192.100.13.7

The 192.100.201.0 address is that of the receiving network (the Destination parameter). The 192.100.13.7 address is that of the routing network (the Gateway parameter).

  1. To establish a default gateway, type: route add 0 192.100.13.7

The value 0 or the default ph for the Destination parameter means that any packets sent to destinations not previously defined and not on a directly connected network go through the default gateway. The 192.100.13.7 address is that of the gateway chosen to be the default.

  1. To clear the host gateway table, type: route -f

  2. To add a route specifying weight and policy information, type: route add 192.158.2.2 192.158.2.5 -weight 5 -policy 4

  3. To set the weight and policy attributes of a preexisting route, type: route set 192.158.2.2 192.158.2.5 -weight 3 -policy

Related reference:

  • netstat Command

Related information:

  • gethostbyname command
  • getnetbyname command
  • /etc/hosts command
  • TCP/IP addressing

리눅스(GNU)와 다른 점

리눅스에서는 ip route(iproute2)를 주로 씁니다. route add default 10.1.1.1은 ip route add default via 10.1.1.1, 네트워크 경로는 ip route add 192.168.10.0/24 via 10.1.1.254, 찾아보기는 ip route get 192.168.10.5입니다. 영구 경로는 NetworkManager나 배포판 설정 파일에 둡니다. 리눅스 route(net-tools)도 있지만 문법이 달라 route add -net 192.168.10.0 netmask 255.255.255.0 gw 10.1.1.254처럼 gw를 씁니다.