码迷,mamicode.com
首页 > 其他好文 > 详细

ip tunnel

时间:2017-08-16 15:28:40      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:tunnel   linux   ip tunnel   

                                           |
            1.1.1.1               2.2.2.2         |
            +---------+  Public   +---------+     | Private
            | ServerA +-----------+ ServerB +-----+
            +---------+  Network  +---------+     | Network
                                                  |
                                                  | 192.168.1.0/24

实现

通过ip tunnel建立ipip隧道,再通过iptables进行nat,便可以实现。
Step 1. 建立ip隧道
ServerA配置iptunnel,并给tunnel接口配置上ip

#ip tunnel add a2b mode ipip remote 2.2.2.2 local 1.1.1.1

#ifconfig a2b 192.168.2.1 netmask 255.255.255.0

ServerB配置iptunnel,并给tunnel接口配置上ip

#ip tunnel add a2b mode ipip remote 1.1.1.1 local 2.2.2.2

#ifconfig a2b 192.168.2.2 netmask 255.255.255.0

隧道配置完成后,请在ServerA上192.168.2.2,看是否可以ping通,ping通则继续,ping不通需要再看一下上面的命令执行是否有报错
Step 2. 添加路由和nat
ServerA上,添加到192.168.1.0/24的路由

#/sbin/route add -net 192.168.1.0/24 gw 192.168.2.2

ServerB上,添加iptables nat,将ServerA过了访问192.168.1.0/24段的包进行NAT,并开启ip foward功能

iptables -t nat -A POSTROUTING -s 192.168.2.1 -d 192.168.1.0/24 -j MASQUERADE

sysctl -w net.ipv4.ip_forward=1

sed -i ‘/net.ipv4.ip_forward/ s/0/1/‘  /etc/sysctl.conf



本文出自 “勤能补拙” 博客,请务必保留此出处http://echoroot.blog.51cto.com/11804540/1956700

ip tunnel

标签:tunnel   linux   ip tunnel   

原文地址:http://echoroot.blog.51cto.com/11804540/1956700

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!