시스템(리눅스)2015. 5. 12. 00:54

두개의 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 재시작등을 수행해준다.





Posted by 캡슐리어