Liunx GRE Tunnel
Set up GRE tunnel on Linux
서로 많이 논리적으로 떨어진 상태의 리눅스 서버 A와 B에서 같은 네트워크로 구현하고 싶다!
리눅스의 내부 VPN망을 다른 VPN망으로 라우팅 해줄 필요가 있었는데, 두 서버가 같은 브로드캐스트 도메인에 있지 않으면, 트래픽을 넘겨줄 수가 없다. 그래서 GRE를 쓰기로 했다. GRE는 암호화 되지 않는 단순히 IP 패킷을 캡슐화하는 프로토콜이다.
modprobe ip_gre lsmod | grep gre
ip_gre 22749 0 ip_tunnel 25163 1 ip_gre gre 13144 1 ip_gre
결과가 안나오면, Linux 커널에 GRE가 포함되지 않아서, 사용할 수 없다는 뜻임.
셋팅은 간단하다.
가정의 상황
- Host A
- WAN 33.33.33.33
- GRE INTERFACE 10.2.1.1/30
- Host B
- WAN 75.75.75.75
- GRE INTERFACE 10.2.1.2/30
Host A
ip tunnel add gre_hello mode gre remote 75.75.75.75 local 33.33.33.33 ttl 25 5 ip link set gre_hello up ip addr add 10.2.1.1/30 dev gre_hello
Host B
ip tunnel add gre_hello mode gre remote 33.33.33.33 local 75.75.75.75 ttl 25 5 ip link set gre_hello up ip addr add 10.2.1.2/30 dev gre_hello
firewall
host A
iptables -A INPUT -p gre -s 75.75.75.75 -j ACCEPT iptables -A INPUT -i gre_hello -j ACCEPT iptables -A OUTPUT -o gre_hello -j ACCEPT
host B
iptables -A INPUT -p gre -s 33.33.33.33 -j ACCEPT iptables -A INPUT -i gre_hello -j ACCEPT iptables -A OUTPUT -o gre_hello -j ACCEPT