黑帽联盟

 找回密码
 会员注册
查看: 1752|回复: 0

[基础服务] linux之IP隧道配置

[复制链接]
yun 黑帽联盟官方人员 

920

主题

37

听众

1364

积分

超级版主

Rank: 8Rank: 8

  • TA的每日心情
    奋斗
    2019-10-18 11:20
  • 签到天数: 678 天

    [LV.9]以坛为家II

    本文系统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. modprobe ipip
    2. modprobe ip_gre
    3. ip tunnel add tun0 mode gre remote 192.168.244.154 local 192.168.244.152
    4. ip link set tun0 up
    5. ip addr add 10.0.0.1 peer 10.0.0.2 dev tun0
    6. ip route add 10.0.0.0/24 dev tun0
    7. iptables -F
    复制代码

    server2:
    1. modprobe ipip
    2. modprobe ip_gre
    3. ip tunnel add tun0 mode gre remote 192.168.244.152 local 192.168.244.154
    4. ip link set tun0 up
    5. ip addr add 10.0.0.2 peer 10.0.0.1 dev tun0
    6. ip route add 10.0.0.0/24 dev tun0
    7. iptables -F
    复制代码


    现在开始测试,随便一台机器;

    173004747.jpg



    二:ipip模式

    server1:

    1. modprobe ipip
    2. ip tunnel add ethn mode ipip local 222.170.n.n remote 60.199.m.m
    3. ifconfig ethn 172.0.0.1
    4. route add -host 172.0.0.2 dev ethn
    5. echo 1 > /proc/sys/net/ipv4/ip_forward
    6. #当你其他不同段的Ip,ip route add 即可。
    复制代码

    server2:
    1. modprobe ipip
    2. ip tunnel add ethn mode ipip local 60.199.m.m remote 222.170.n.n
    3. ifconfig ethn 172.0.0.2
    4. route add -host 172.0.0.1 dev ethn
    5. echo 1 > /proc/sys/net/ipv4/ip_forward
    复制代码


    现在发现172.0.0.0的两个ip可以互ping


    您需要登录后才可以回帖 登录 | 会员注册

    发布主题 !fastreply! 收藏帖子 返回列表 搜索
    回顶部