Linux下搭建gre隧道

2021-08-03 10:43:37 字數 1359 閱讀 8468

server1           搭建gre隧道server2        

pc1                    ping 通pc2

範例:(基於h560n)

server1 ip:192.168.1.253

pc1 ip:192.168.2.3

server2 ip:192.168.1.3

pc1 ip:192.168.3.3

server1端配置:

#載入gre模組

/sbin/modprobe ip_gre

#新增tunnel口

/sbin/ip tunnel add gre_tunnel mode gre remote 192.168.1.3 local 192.168.1.253 ttl 255

#設定tunnel的ip位址

/sbin/ip addr add 10.0.1.1 dev gre_tun1

#啟動tunnel

/sbin/ip link set gre_tunnel up

#新增去往server2網段的路由

/sbin/ip r add 10.0.1.0/24 dev gre_tunnl

/sbin/ip r add 192.168.3.0/24 via 10.0.1.1 dev gre_tun1

server2端配置

#載入gre模組

/sbin/modprobe ip_gre

#新增tunnel口

/sbin/ip tunnel add gre_tun1 mode gre remote 192.168.1.253 local192.168.1.3 ttl 255

#設定tunnel ip位址

/sbin/ip addr add 10.0.1.2 dev gre_tun1

#啟動tunnel

/sbin/ip link set gre_tunn1 up

#新增去往server1網段的路由

/sbin/ip r add 10.0.1.0/24 dev gre_tun1

/sbin/ip r add 102.168.2.0/24 via 10.0.1.2 dev gre_tun1

配置完畢後,隧道即建立起來,tunnel位址可以ping通。

解決方案:開啟server1與server2端的乙個**資料報

echo 1 > /proc/sys/net/ipv4/ip_forward

預設為0,開啟核心**功能。

ip位址ping指定網絡卡

ping 192.168.1.253  -i eth0/1

路由器工作的時候,根據它的某個埠收到的資料報的目的ip位址,查詢路由器自己的路由表,然後決定把資料報**到相應的埠。

linux 下建立GRE隧道

gre隧道是一種ip over ip的隧道,是通用路由封裝協議,可以對某些網路層協議的資料報進行封裝,使這些被封裝的資料報能夠在ipv4 ipv6 網路中傳輸。tunnel 是乙個虛擬的點對點的連線,提供了一條通路使封裝的資料報文能夠在這個通路上傳輸,並且在乙個tunnel 的兩端分別對資料報進行封...

簡單GRE隧道搭建

2.1.1.配置ip r1 ip link set eth0 up ip addr add 169.254.1.108 24 dev eth0 ip link set eth1 up ip addr add 169.254.2.108 24 dev eth1 r2 ip link set eth0 ...

linux搭建GRE隧道 麼啥好說的

gre介紹 gre隧道是一種ip over ip的隧道,是通用路由封裝協議,可以對某些網路層協議的資料報進行封裝,使這些被封裝的資料報能夠在ipv4 ipv6 網路中傳輸。tunnel 是乙個虛擬的點對點的連線,提供了一條通路使封裝的資料報文能夠在這個通路上傳輸,並且在乙個tunnel 的兩端分別對...