機器A:173.26.100.80
機器B:173.26.100.162
第一步:
在機器A上:
ip tunnel add ethn mode ipip local 173.26.100.80 remote 173.26.100.162
其中,ethn為ip隧道的虛擬網卡名,
mode ipip設置ip隧道的模式為ipip,除了ipip,還有很多其他模式,如gre,sit等等,以ipip和gre最為常見
同樣,在機器B上:
ip tunnel add ethm mode ipip local 173.26.100.162 remote 173.26.100.80
ethm為ip隧道的虛擬網卡名
至此,ip隧道已經建立起來了
第二步:
但是要想實現A和B通過ip隧道通信,還需要給A和B的隧道對應的網卡設置一個ip,
在機器A上:
ifconfig ethn 41.211.25.78
在機器B上:
ifconfig ethm 62.72.100.128
這里A和B的隧道網卡的ip可以隨便設定
可以在A和B上分別ifconfig看看,是不是多了ethn/ethm這個網卡
第三步:
別急,最后一步,設置一下路由規則
在機器A上:
route add -host 62.72.100.128 dev ethn
讓目的ip為62.72.100.128的數據包走ethn這個網卡
在機器B上:
route add -host 41.211.25.78 dev ethm
讓目的ip為41.211.25.78的數據包走ethm這個網卡
第四步:
在機器A上
ping 62.72.100.128
在機器B上
ping 41.211.25.78
如果都可以ping通,恭喜了,ipip隧道已經成功建立了
reference:
*[http://blog.chinaunix.net/u/553/showart_430370.html Linux下的IP隧道研究]
*[http://blog.chinaunix.net/u/16029/showart_133364.html Linux中IP隧道的分析與建議]
*[http://www.chinaunix.net/jh/4/1055425.html (原創) linux tunnel 技術]
*[http://www.linuxsir.org/bbs/thread89987.html 使用Linux建立IP隧道]
*[http://www.xiaojb.com/archives/it/ip-tunnel.shtml 2台linux服務器建立IP隧道]
TAG ip隧道