[Linux] routing(라우팅) 명령어 정리

 

 

routing table 확인 및 설명

 

라우팅 테이블은 "route" 명령어로 확인을 할 수 있습니다

저는 "route -n" 명령을 주로 사용합니다.

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

항목 설명
Destination  목적지 네트워크
Gateway 목적지로 가기위한 게이트웨이 주소
Genmask 목적지 네트워크의 넷마스크 주소
(목적지IP와 Genmask를 AND 연산한 결과가 목적지 네트워크임)
Flags 해당 경로에 대한 정보를 알려주는 기호/ U - up, H - 목적지 Host, G - 게이트웨이 사용
Metric 목적지 네트워크까지의 거리
Ref 경로를 참조한 횟수
Use 경로를 탐색한 횟수
IFace 네트워크 인터페이스

 

현재 라우팅 설정으로는 외부로 나갈 수는 없으며

192.168.219.0/24 대역과 통신만 가능합니다.

 

 

 

 default routing  추가/제거

 

디폴트 라우팅 추가

: route add default gw [게이트웨이 IP 정보]

[root@test-1 ~]# route add default gw 192.168.219.1

 

설정 확인

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.219.1   0.0.0.0         UG    0      0        0 enp0s8
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

설정으로만 본다면 192.168.219.1 게이트웨이를 통해 0.0.0.0 모든 대역으로 접근이 가능합니다.

 

 

디폴트 라우팅 제거

: route del default gw [게이트웨이 IP 정보]

[root@test-1 ~]# route del default gw 192.168.219.1

 

설정 확인

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

 

네트워크 경로 추가/제거

 

네트워크 경로 추가

: route add -net [네트워크 대역] netmask [넷마스크] gw [게이트웨이 IP 정보]

[root@test-1 ~]# route add -net 192.168.23.0 netmask 255.255.255.0 gw 192.168.219.1

 

설정 확인

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.219.1   0.0.0.0         UG    100    0        0 enp0s8
192.168.23.0    192.168.219.1   255.255.255.0   UG    0      0        0 enp0s8
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

네트워크 경로 제거

: route del -net [네트워크 대역] netmask [넷마스크] gw [게이트웨이 IP 정보]

[root@test-1 ~]# route del -net 192.168.23.0 netmask 255.255.255.0 gw 192.168.219.1

 

설정 확인

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.219.1   0.0.0.0         UG    100    0        0 enp0s8
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

 

 

호스트 경로 추가 제거

 

호스트 경로 추가

: route add -host [호스트IP] gw [게이트웨이 IP 정보] dev [인터페이스 정보]

[root@test-1 ~]# route add -host 192.168.23.10 gw 192.168.219.1 dev enp0s8

 

설정 확인

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.219.1   0.0.0.0         UG    100    0        0 enp0s8
192.168.23.10   192.168.219.1   255.255.255.255 UGH   0      0        0 enp0s8
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

호스트 경로 추가

: route del -host [호스트 IP]gw [게이트웨이 IP 정보] dev [인터페이스 정보]]

[root@test-1 ~]# route del -host 192.168.23.10 gw 192.168.219.1 dev enp0s8

 

설정 확인

[root@test-1 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.219.1   0.0.0.0         UG    100    0        0 enp0s8
192.168.219.0   0.0.0.0         255.255.255.0   U     100    0        0 enp0s8

 

댓글

Designed by JB FACTORY

loading