公司與機(jī)房的GRE隧道配置實(shí)例

背景:

背景:        

城固ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!

       我們公司內(nèi)網(wǎng)與機(jī)房服務(wù)器為了實(shí)現(xiàn)用內(nèi)網(wǎng)IP通信的功能,故使用了linux的IP gre隧道的方式。使得公司內(nèi)部可以直接通過(guò)路由直連的方式訪問(wèn)機(jī)房服務(wù)器。

拓?fù)鋱D如下:

     注:拓?fù)渲械耐饩W(wǎng)IP為虛構(gòu)的IP。

       公司與機(jī)房的GRE隧道配置實(shí)例

       可以看到,公司和機(jī)房的服務(wù)器上各有一個(gè)內(nèi)網(wǎng)IP和外部IP。gre隧道的原理就是把兩臺(tái)服務(wù)器的外網(wǎng)IP進(jìn)行綁定,在兩個(gè)外網(wǎng)IP直接建立一條隧道tunnel2。tunnel2對(duì)服務(wù)器看來(lái),就像一個(gè)網(wǎng)口,直連著隧道的另一邊。

      這里給tunnel配置一個(gè)新的IP段:172.16.33.1/2


具體配置:

218.188.152.11:

開(kāi)啟路由轉(zhuǎn)發(fā),加載gre協(xié)議模塊
# echo 1 > /proc/sys/net/ipv4/ip_forward
# modprobe ip_gre

創(chuàng)建隧道tunnel2,添加一虛擬網(wǎng)段172.16.33.0/24
# ip tunnel add tunnel2 mode gre local 218.188.152.11 remote 144.22.1.176 ttl 255 dev eth2
# ip addr add 172.16.33.2 dev tunnel2 peer 172.16.33.1/32
# ip link set dev tunnel2 up
  
添加一條路由到通過(guò)隧道到機(jī)房?jī)?nèi)網(wǎng)的路由
# ip route add 10.65.3.0/24 dev tunnel2

144.22.1.176:

開(kāi)啟路由轉(zhuǎn)發(fā),加載gre協(xié)議模塊
# echo 1 > /proc/sys/net/ipv4/ip_forward
# modprobe ip_gre
創(chuàng)建隧道tunnel2,添加一虛擬網(wǎng)段172.16.33.0/24

# ip tunnel add tunnel2 mode gre local 144.22.1.176 remote 218.188.152.11 ttl 255 dev em1
# ip addr add 172.16.33.1 dev tunnel2 peer 172.16.33.2/32
# ip link set dev tunnel2 up
  
添加一條路由到通過(guò)隧道到公司內(nèi)網(wǎng)的路由
# ip route add 192.168.1.0/24 dev tunnel2

查看路由

218.188.152.11:

# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.16.33.1     0.0.0.0         255.255.255.255 UH        0 0          0 tunnel2
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
10.65.3.0       0.0.0.0         255.255.255.0   U         0 0          0 tunnel2
0.0.0.0         xx.xx.xx.xx    0.0.0.0         UG        0 0          0 eth0

      內(nèi)網(wǎng)服務(wù)器多了172.16.33.1,10.65.3.0/24的兩條路由,網(wǎng)關(guān)為gre隧道,通過(guò)隧道到達(dá)機(jī)房服務(wù)器。

144.22.1.176:

# netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.16.33.2     0.0.0.0         255.255.255.255 UH        0 0          0 tunnel2
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 tunnel2
10.65.3.0       0.0.0.0         255.255.255.0   U         0 0          0 em2
0.0.0.0         xx.xx.xx.xx    0.0.0.0         UG        0 0          0 em1

      機(jī)房服務(wù)器多了172.16.33.2,192.168.1.0/24的兩條路由,網(wǎng)關(guān)為gre隧道,通過(guò)隧道到達(dá)機(jī)房服務(wù)器。


測(cè)試網(wǎng)絡(luò)連通:

218.188.152.11:

# ping 172.16.33.2
PING 172.16.33.2 (172.16.33.2) 56(84) bytes of data.
64 bytes from 172.16.33.2: icmp_seq=1 ttl=64 time=0.048 ms
64 bytes from 172.16.33.2: icmp_seq=2 ttl=64 time=0.059 ms
--- 172.16.33.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1021ms
rtt min/avg/max/mdev = 0.048/0.053/0.059/0.009 ms

# ping 10.65.3.194
PING 10.65.3.194 (10.65.3.194) 56(84) bytes of data.
64 bytes from 10.65.3.194: icmp_seq=1 ttl=64 time=7.96 ms
64 bytes from 10.65.3.194: icmp_seq=2 ttl=64 time=7.63 ms
--- 10.65.3.194 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1100ms
rtt min/avg/max/mdev = 7.638/7.799/7.960/0.161 ms

      公司服務(wù)器可以直接ping通對(duì)端機(jī)房服務(wù)器的gre ip以及內(nèi)網(wǎng)IP。

144.22.1.176:

# ping 172.16.33.1
PING 172.16.33.1 (172.16.33.1) 56(84) bytes of data.
64 bytes from 172.16.33.1: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from 172.16.33.1: icmp_seq=2 ttl=64 time=0.016 ms
--- 172.16.33.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1274ms
rtt min/avg/max/mdev = 0.016/0.017/0.018/0.001 ms

# ping 192.168.1.254
PING 192.168.1.254 (192.168.1.254) 56(84) bytes of data.
64 bytes from 192.168.1.254: icmp_seq=1 ttl=64 time=7.81 ms
64 bytes from 192.168.1.254: icmp_seq=2 ttl=64 time=7.97 ms
--- 192.168.1.254 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1232ms
rtt min/avg/max/mdev = 7.810/7.894/7.978/0.084 ms

       反過(guò)來(lái),機(jī)房服務(wù)器也可以直接ping通對(duì)端公司服務(wù)器的gre ip以及內(nèi)網(wǎng)IP。

網(wǎng)站名稱:公司與機(jī)房的GRE隧道配置實(shí)例
本文路徑:http://muchs.cn/article2/ghsgoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)云服務(wù)器、網(wǎng)站內(nèi)鏈、全網(wǎng)營(yíng)銷推廣、外貿(mào)建站自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司