本文系统Centos6.0
在这里我就不讲什么隧道、IP隧道技术了;lvs的三种模式也不说了
我这里隧道说白了就是不同机房,不同公网IP,怎么让他们实现局域网的效果,配置同一网段的私网IP;可以实现互联互通;
写这篇文章是因为好多人在写lvs相关文章的时候,发现nat、DR模式的一搜一大堆,为什么不写tun呢?我想应该是因为没有现成的吧,因为tun要事先配置隧道。
下面是IP Tunneling配置;
两台机器,都是两块网卡,
server1:
eth0:192.168.244.152 (公网IP);vm中进行nat实现上网
eth1:10.0.0.1 (私网IP);自定义到虚拟网络VMnet3;
server2:
eth0:192.168.244.154(公网IP);vm中进行nat实现上网
eth1:10.0.0.2(私网IP);自定义到虚拟网络VMnet2;
现在你发现两台机器是无法ping通对方的私网IP地址的;
下面就开始配置了
server1:
1
2
3
4
5
6
7
|
modprobe ipip modprobe ip_gre ip tunnel add tun0 mode gre remote 192.168 . 244.154 local 192.168 . 244.152
ip link set tun0 up
ip addr add 10.0 . 0.1 peer 10.0 . 0.2 dev tun0
ip route add 10.0 . 0.0 / 24 dev tun0
iptables -F |
server2:
1
2
3
4
5
6
7
|
modprobe ipip modprobe ip_gre ip tunnel add tun0 mode gre remote 192.168 . 244.152 local 192.168 . 244.154
ip link set tun0 up
ip addr add 10.0 . 0.2 peer 10.0 . 0.1 dev tun0
ip route add 10.0 . 0.0 / 24 dev tun0
iptables -F |
现在开始测试,随便一台机器;
二:ipip模式
server1;
1
2
3
4
5
6
|
modprobe ipip ip tunnel add ethn mode ipip local 222.170 .n.n remote 60.199 .m.m
ifconfig ethn 172.0 . 0.1
route add -host 172.0 . 0.2 dev ethn
echo 1 > /proc/sys/net/ipv4/ip_forward
#当你其他不同段的Ip,ip route add 即可。 |
server2;
1
2
3
4
5
|
modprobe ipip ip tunnel add ethn mode ipip local 60.199 .m.m remote 222.170 .n.n
ifconfig ethn 172.0 . 0.2
route add -host 172.0 . 0.1 dev ethn
echo 1 > /proc/sys/net/ipv4/ip_forward
|
现在发现172.0.0.0的两个ip可以互ping
欢迎大家吐槽;
本文转自 西索oO 51CTO博客,原文链接:http://blog.51cto.com/lansgg/1221310