: route 명령은 IP 라우팅 테이블을 보여주거나 조작할 시 사용하는 명령어 입니다.
목차
옵션
-A family
: family 로 지정된 (inet , inet6) 라우팅 테이블 출력
$ route -A inet
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
$ route -A inet6
Kernel IPv6 routing table
Destination Next Hop Flag Met Ref Use If
ip6-localhost/128 [::] U 256 1 0 lo
fd8f:5430:7582:1::/64 fe80::2eba:baff:fe96:c057 UG 100 2 0 enp3s0
fdf5:60c8:e646:2d6b::/64 [::] U 100 1 0 enp3s0
fe80::/64 [::] U 1024 2 0 enp3s0
[::]/0 [::] !n -1 1 0 lo
ip6-localhost/128 [::] Un 0 6 0 lo
ubuntu22/128 [::] Un 0 10 0 enp3s0
ubuntu22/128 [::] Un 0 9 0 enp3s0
ubuntu22/128 [::] Un 0 2 0 enp3s0
ip6-mcastprefix/8 [::] U 256 10 0 enp3s0
[::]/0 [::] !n -1 1 0 lo
$ route -4
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
$ route -6
Kernel IPv6 routing table
Destination Next Hop Flag Met Ref Use If
ip6-localhost/128 [::] U 256 1 0 lo
fd8f:5430:7582:1::/64 fe80::2eba:baff:fe96:c057 UG 100 2 0 enp3s0
fdf5:60c8:e646:2d6b::/64 [::] U 100 1 0 enp3s0
fe80::/64 [::] U 1024 2 0 enp3s0
[::]/0 [::] !n -1 1 0 lo
ip6-localhost/128 [::] Un 0 6 0 lo
ubuntu22/128 [::] Un 0 10 0 enp3s0
ubuntu22/128 [::] Un 0 9 0 enp3s0
ubuntu22/128 [::] Un 0 2 0 enp3s0
ip6-mcastprefix/8 [::] U 256 10 0 enp3s0
[::]/0 [::] !n -1 1 0 lo
-F 옵션
: 커널 FIB 라우팅 테이블 기반으로 작동
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
$ route -F
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
-C 옵션
커널 3.6 이전버전에서는 탐색 과정이 라우팅 캐시 탐색과
캐시 미스 시 라우팅 테이블 탐색 단계로 나뉘어졌는데 라우팅 캐시가 느리거나 시큐리티에 취약하다는 문제점이
제기되 제거되고, Fib Trie/ LC Trie 알고리즘을 사용하는 새로운 기술로 교체 되었다.
-v 옵션
: verbose 라고 하느데 옵션 미사용시와 동일하게 출력됨.
$ route -v
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
192.168.55.0 0.0.0.0 255.255.255.0 U 1024 0 0 enp3s0
-n 옵션
: 심볼릭 호스트 이름 대신 숫자 주소 사용해 출력하기
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
-e 옵션
$ route -e
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default _gateway 0.0.0.0 UG 0 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 0 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0
192.168.55.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0
>> 모든 파라미터 표시
$ route -ee
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface MSS Window irtt
default _gateway 0.0.0.0 UG 100 0 0 enp3s0 0 0 0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0 0 0 0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0 0 0 0
192.168.55.0 0.0.0.0 255.255.255.0 U 1024 0 0 enp3s0 0 0 0
>> netstat 명령 사용예
$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default _gateway 0.0.0.0 UG 0 0 0 enp3s0
link-local 0.0.0.0 255.255.0.0 U 0 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0
192.168.55.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0
del
: 라우트 제거하기
Syntax :
route [-v] [-A family |-4|-6] del [-net|-host] target [gw Gw] [netmask Nm] [metric M] [[dev] If]
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
192.168.55.0 0.0.0.0 255.255.255.0 U 1024 0 0 enp3s0 <-- 요기 삭제
$ sudo route del -net 192.168.55.0 netmask 255.255.255.0 metric 1024 dev enp3s0
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
add
: 새로운 라우트 추가하기
Synopsis:
route [-v] [-A family |-4|-6] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I]
[reject] [mod] [dyn] [reinstate] [[dev] If]
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
$ sudo route add -net 192.168.55.0 netmask 255.255.255.0 metric 1024 dev enp3s0
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
192.168.55.0 0.0.0.0 255.255.255.0 U 1024 0 0 enp3s0 <-- 요기 추가됨
→ target
Syntax :
route [-v] [-A family] add [-net | -host] target [netmask Nm] ....
route [-v] [-A family] del [-net | -host] target [gw Gw] [netmask Nm] ....
: target 은 앞의 옵션에 따라 목적지 network 또는 host 가 됩니다.
-net
$ sudo route add -net 127.0.0.0 netmask 255.0.0.0 metric 1024 dev lo
~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
127.0.0.0 0.0.0.0 255.0.0.0 U 1024 0 0 lo <--- 요기
~~ 중략 ~~
: target (127.0.0.0)은 destination 이 됩니다.
-host
: host 옵션 사용하면 Flags 에 'H' 가 추가됩니다.
$ sudo route add -host 192.168.19.48 gw 192.168.19.1 dev enp3s0
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
~~ 중략 ~~
192.168.19.48 192.168.19.1 255.255.255.255 UGH 0 0 0 enp3s0
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
~~ 중략 ~~
ubuntu22 _gateway 255.255.255.255 UGH 0 0 0 enp3s0
>>> www.google.co.kr 라우팅 테이블 추가
~$ sudo route add -host www.google.co.kr gw 192.168.19.1 dev enp3s0
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
~~ 중략 ~~
142.250.206.227 192.168.19.1 255.255.255.255 UGH 0 0 0 enp3s0
~~ 중략 ~~
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
~~ 중략 ~~
kix06s10-in-f3. _gateway 255.255.255.255 UGH 0 0 0 enp3s0
~~ 중략 ~~
>>> www.google.co.kr 라우팅 테이블 지우기
$ sudo route del -host www.google.co.kr
chlee@ubuntu22:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 100 0 0 enp3s0
127.0.0.0 0.0.0.0 255.0.0.0 U 1024 0 0 lo
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
192.168.19.26 _gateway 255.255.255.255 UGH 0 0 0 enp3s0
ubuntu22 _gateway 255.255.255.255 UGH 0 0 0 enp3s0
netmask NM
: 라우팅 테이블 추가시 netmask 옵션 사용됨. 위의 다른 예제 참고
gw GW
: GW 에 지정된 게이트웨이를 통한 패킷 라우트
metric M
: 라우팅 테이블 안의 metric 필드 값이 M 설정하기. (목적지 네트워크까지의 거리)
이필드 미지정시 IPv6 의 경우 1 , IPv4 의 경우 0 이 설정됩니다.
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
~$ sudo route add -net 127.0.0.0 netmask 255.0.0.0 metric 1024 dev lo
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
~~ 중략 ~~
127.0.0.0 0.0.0.0 255.0.0.0 U 1024 0 0 lo
~~ 중략 ~~
mss M
: 라우트시 MTU 크기 설정
$ route -ee
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface MSS Window irtt
default _gateway 0.0.0.0 UG 100 0 0 enp3s0 0 0 0
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0 0 0 0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0 0 0 0
$ sudo route add -net 127.0.0.0 netmask 255.0.0.0 mss 1024 dev lo
$ route -ee
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface MSS Window irtt
~~ 중략 ~~
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo 1024 0 0
~~ 중략 ~~
window W
: AX.25 네트워크에서만 사용됨.
irtt I
: AX.25 네트워크에서만 사용됨.
reject
: 라우트를 블러킹하고 할때 사용
$ sudo route add -net 192.168.19.26 netmask 255.255.255.255 reject
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
~~ 중략 ~~
192.168.19.26 - 255.255.255.255 !H 0 - 0 -
$ ping 192.168.19.26
ping: connect: No route to host
$ sudo route del -net 192.168.19.26 netmask 255.255.255.255 reject
chlee@ubuntu22:~$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.19.1 0.0.0.0 UG 100 0 0 enp3s0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp3s0
192.168.19.0 0.0.0.0 255.255.255.0 U 100 0 0 enp3s0
$ ping 192.168.19.26
PING 192.168.19.26 (192.168.19.26) 56(84) bytes of data.
64 bytes from 192.168.19.26: icmp_seq=1 ttl=128 time=0.760 ms
64 bytes from 192.168.19.26: icmp_seq=2 ttl=128 time=0.403 ms
64 bytes from 192.168.19.26: icmp_seq=3 ttl=128 time=0.371 ms
mod, dyn, reinstate
: 진단 목적으로 사용.
dev If
: 지정된 장치로 라우트
-V
: 버전 출력
~$ route -V
net-tools 2.10-alpha
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +I18N +SELINUX
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE -BLUETOOTH
HW: +ETHER +ARC +SLIP +PPP +TUNNEL -TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64
--help
$ route --help
Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
route {-h|--help} [<AF>] Detailed usage syntax for specified AF.
route {-V|--version} Display version/author and exit.
-v, --verbose be verbose
-n, --numeric don't resolve names
-e, --extend display other/more information
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
<AF>=Use -4, -6, '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
< 기타 >
Flags