Multiple Gateway 다중 게이트웨이 설정
— 이강우 2018/06/22 11:14
두개의 NIC, 두개의 Default Gateway 설정 (CentOS)
설정 정보
위 그림의 192.168.0.0/24 와 192.168.1.0/24는 각각 공인IP라고 가정한다.
두개의 서브넷을 가지며 두개 모두 독립적으로 작동중인 네트워크다.
디폴트 게이트웨이는 192.168.0.1이며 기본적인 트래픽은 eth0을 통해서 이루어진다.
하지만 인커밍 리퀘스트가 발생하는 NIC별로 트래픽이 발생하게 된다.
단계1
set up eth0
/etc/iproute2/rt_tables 수정
# cat /etc/iproute2/rt_tables # echo "# dual nic-gateway below" >> /etc/iproute2/rt_tables # echo "10 eth0table" >> /etc/iproute2/rt_tables # cat /etc/iproute2/rt_tables
라우팅 테이블 추가
# ip route add 192.168.0.0/24 dev eth0 src 192.168.0.100 table eth0table # ip route add default via 192.168.0.1 dev eth0 table eth0table # ip rule add from 192.168.0.100/32 table eth0table # ip rule add to 192.168.0.100 table eth0table # ip route flush cache
재부팅 시에도 위 라우팅 테이블이 적용되도록 설정
# vi /etc/sysconfig/network-scripts/route-eth0 192.168.0.0 dev eth0 src 192.168.0.100 table eth0table default via 192.168.0.1 dev eth0 table eth0table
# vi /etc/sysconfig/network-scripts/rule-eth0 from 192.168.0.100/32 table eth0table to 192.168.0.100 table eth0table
단계2
set up eth1
/etc/iproute2/rt_tables 수정
# cat /etc/iproute2/rt_tables # echo "# dual nic-gateway below" >> /etc/iproute2/rt_tables # echo "11 eth1table" >> /etc/iproute2/rt_tables # cat /etc/iproute2/rt_tables
라우팅 테이블 수정
# ip route add 192.168.1.0/24 dev eth1 src 192.168.1.200 table eth1table # ip route add default via 192.168.1.1 dev eth1 table eth1table # ip rule add from 192.168.1.200/32 table eth1table # ip rule add to 192.168.1.200 table eth1table # ip route flush cache
재부팅 시에도 위 라우팅 테이블이 적용되도록 설정
# vi /etc/sysconfig/network-scripts/route-eth1 192.168.1.0 dev eth1 src 192.168.1.200 table eth1table default via 192.168.1.1 dev eth1 table eth1table
# vi /etc/sysconfig/network-scripts/rule-eth1 from 192.168.1.200/32 table eth1table to 192.168.1.200 table eth1table
작업이 완료된 이후 network 재시작등을 수행해준다.
설정1
이 방법은 나가는 네트워크는 기본게이트웨이 하나로만 나가게 되지만 들어오는 요청은 요청받은 NIC를 통해 응답하게 하는 방식이다.
서버 네트워크
A네트워크는 공인 네트워크
IP 210.10.10.11/25
GW 210.10.10.1
B네트워크는 사설 네트워크
IP 10.1.10.11/24
GW 10.1.10.1
[root@server network-scripts]# cat route-ens192 210.10.10.0/25 dev ens192 table ens192table default via 210.10.10.1 dev ens192 table ens192table [root@server network-scripts]# cat route-ens224 10.1.10.0/24 dev ens224 table ens224table default via 10.1.10.1 dev ens224 table ens224table [root@server network-scripts]# cat rule-ens192 from 210.10.10.11/32 table ens192table priority 100 [root@server network-scripts]# cat rule-ens224 from 10.1.10.11/32 table ens224table priority 200
라우팅 테이블 추가
- /etc/iproute2/rt_table
# # L4 network route # 10 ens192table 11 ens224table
설정2
네트워크A 192.168.0.0/24
IPADDRESS 192.168.0.10
GATEWAY 192.168.0.1
네트워크B 10.0.0.0/24
IPADDRESS 10.0.0.30
GATEWAY 10.0.0.1
- /etc/sysconfig/network-script/ifcfg-eth0
TYPE=Ethernet BOOTPROTO=none NAME=eth0 DEVICE=eth0 IPADDR=192.168.0.10 NETMASK=255.255.255.0 #GATEWAY=192.168.0.1 # Gateway 설정은 하지 않는다. ONBOOT=yes NM_CONTROLLED=no
- /etc/sysconfig/network-script/ifcfg-eth1
TYPE=Ethernet BOOTPROTO=none NAME=eth1 DEVICE=eth1 IPADDR=10.0.0.30 NETMASK=255.255.255.0 #GATEWAY=10.0.0.1 # Gateway 설정은 하지 않는다. ONBOOT=yes NM_CONTROLLED=no
위에서 중요한것은 두 인터페이스 둘다 게이트웨이 설정은 하지 않는다
는것이다. 게이트웨이 설정을 하게 될경우 먼저올라오는 인터페이스의 게이트웨이가 디폴트 게이트웨이로 잡혀버린다. 따라서 이후에 설정하는 라우팅테이블이 무용지물이 되어버리므로 기본 게이트웨이가 잡히지 않도록 설정한다.
- /etc/sysconfig/network-script/route-eth0
default nexthop via 192.168.0.1 weight 1 nexthop via 10.0.0.1 weight 1
- /etc/sysconfig/network-script/route-eth1
default nexthop via 192.168.0.1 weight 1 nexthop via 10.0.0.1 weight 1
라우팅 테이블은 두 인터페이스 모두 동일하게 설정해준다. 또는 인터페이스별로 nexthop 순서를 바꿔도 상관은 없다.
- /etc/sysconfig/network-script/rule-eth0
iif eth0 table 1 from 192.168.0.10 table 1
- /etc/sysconfig/network-script/rule-eth1
iif eth1 table 2 from 10.0.0.30 table 2
룰 설정은 들어온 인터페이스로 통신하기 위해서 해당 인터페이스 입력은 해당 아이피 라우팅 테이블을 이용하도록 설정해준다.
ip route 명령어를 통해 라우팅 테이블을 보면 아래와 비슷한 형태로 출력이 된다.
[root@test ~]# ip r default nexthop via 192.168.0.1 dev eth0 weight 1 nexthop via 10.0.0.1 dev eth1 weight 1 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.0.0/16 dev eth1 scope link metric 1003 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.10 10.0.0.0/24 dev eth1 proto kernel scope link src 10.0.0.30
참조링크
'Linux' 카테고리의 다른 글
리눅스 multi default gateway(routing) 설정 (0) | 2019.03.06 |
---|---|
[CentOS] 방화벽 설정-iptables (0) | 2019.03.06 |
[CentOS] CPU 온도체크 (0) | 2019.03.04 |