两台linux服务器上建立ip隧道

  • A+
所属分类:运维教程

服务器server的地址192.168.18.251,服务器client的地址192.168.18.252。

建立隧道

在服务器server上执行以下命令:

  1. ip tunnel add ethn mode ipip local 192.168.18.251 remote 192.168.18.252

其中,ip tunnel为隧道操作,add ethn为添加隧道(ethn为隧道的虚拟网卡名,可自定义)

mode ipip设置隧道的模式为ipip。除ipip,还有很多其他模式,如gre/sit等等,以ipip和gre最为常见。

local指定本机的地址,remote指定对方的地址。

同样,在服务器client上执行以下命令:

  1. ip tunnel add ethm mode ipip local 192.168.18.252 remote 192.168.18.251

ethm为隧道的虚拟网卡名,可自定义。

至此,ip隧道已经建立起来了。

隧道地址

但是要想实现server和client通过ip隧道通信,还需要给server和client的隧道对应的网卡设置一个ip。

在服务器server上执行以下命令:

  1. ifconfig ethn 1.1.1.1

在服务器client上执行以下命令:

  1. ifconfig ethm 2.2.2.2

这里server和client的隧道网卡的ip可以随便设定。

可以在server和client上分别ifconfig看看,是不是多了ethn/ethm这个网卡。

添加路由

最后一步,设置一下路由规则。

在服务器server上执行以下命令:

  1. route add -host 2.2.2.2 dev ethn

让目的ip为2.2.2.2的数据包走ethn这个网卡。

在服务器client上执行以下命令:

  1. route add -host 1.1.1.1 dev ethm

让目的ip为1.1.1.1的数据包走ethm这个网卡。

测试隧道

在服务器server上执行以下命令:

  1. ping 2.2.2.2

在服务器client上执行以下命令:

  1. ping 1.1.1.1

如果可以ping通,说明ipip隧道已经成功建立了。

效果下图所示:

两台linux服务器上建立ip隧道

  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:19   其中:访客  19   博主  0

    • avatar Buy Remy Hair Extensions online

      But wanna comment that you have a very nice website , I enjoy the design it actually stands out.

      • avatar image source

        I haven’t checked in here for some time because I thought it was getting boring, but the last several posts are good quality so I guess I will add you back to my everyday bloglist. You deserve it my friend :)

        • avatar methandienone

          Thanks for all your efforts that you have put in this. very interesting information.

          • avatar go to this site

            F*ckin’ tremendous things here. I’m very happy to peer your post. Thank you so much and i’m taking a look ahead to contact you. Will you please drop me a e-mail?

            • avatar site

              I?¦ve been exploring for a little bit for any high-quality articles or blog posts in this sort of space . Exploring in Yahoo I ultimately stumbled upon this site. Studying this information So i?¦m happy to show that I have a very good uncanny feeling I discovered exactly what I needed. I such a lot indubitably will make certain to do not put out of your mind this website and provides it a look on a constant basis.

              • avatar svolrfinotews

                I do love the manner in which you have presented this specific situation and it really does present me a lot of fodder for consideration. On the other hand, through what precisely I have witnessed, I simply just hope when the actual commentary stack on that people remain on point and don’t start upon a soap box involving the news of the day. Still, thank you for this fantastic piece and while I do not necessarily go along with it in totality, I value your point of view.

                • avatar svolrfino tews

                  Aw, this was a really nice post. In concept I want to put in writing like this moreover – taking time and precise effort to make an excellent article… but what can I say… I procrastinate alot and not at all seem to get one thing done.

                  • avatar LonPMikrut

                    I was suggested this blog by my cousin. I am uncertain whether this post is published by him as nobody else know such detailed about my trouble. You might be wonderful! Thanks!

                    • avatar ABIOMED stock price

                      Great line up. We will be linking to this great article on our site. Keep up the good writing.