亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.430618.com 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

Linux與網(wǎng)絡(luò)設(shè)備 GRE配置經(jīng)驗(yàn)總結(jié)

 

GRE 介紹及應(yīng)用場(chǎng)景

 

GRE(General Routing Encapsulation),即通用路由封裝,是一種三層 VPN 技術(shù)。它的最大作用是可以對(duì)某些網(wǎng)絡(luò)層協(xié)議的報(bào)文進(jìn)行封裝,如對(duì)路由協(xié)議、語(yǔ)音、視頻等組播報(bào)文或IPv6報(bào)文進(jìn)行封裝。同時(shí),也能夠與 IPSec 結(jié)合,解決 GRE 的安全問(wèn)題。

本文主要介紹 linux 與 網(wǎng)絡(luò)設(shè)備(華為防火墻、華為路由器、Juniper SRX防火墻)對(duì)接 GRE 的配置方法

 

GRE 報(bào)文

 

如下圖所示,GRE 是按照 TCPIP 協(xié)議棧進(jìn)行逐層封裝,新的 IP 頭會(huì)封裝在原有的 IP 頭中,然后運(yùn)送出去,封裝操作是通過(guò) Tunnel 接口完成的,GRE 協(xié)議經(jīng)過(guò) Tunnel 口時(shí),會(huì)將接口的封裝協(xié)議設(shè)置為 GRE 協(xié)議。

Linux與網(wǎng)絡(luò)設(shè)備 GRE配置經(jīng)驗(yàn)總結(jié)

 

GRE 的配置場(chǎng)景

 

centos 7.6 與 華為防火墻建立 GRE 隧道

拓?fù)鋱D

Linux與網(wǎng)絡(luò)設(shè)備 GRE配置經(jīng)驗(yàn)總結(jié)

 

實(shí)現(xiàn)目標(biāo)

  • CentOS 與 華為防火墻建立 GRE 隧道;
  • 華為防火墻背后的內(nèi)網(wǎng)網(wǎng)段 192.168.1.0/24 通過(guò) GRE 隧道從 CentOS 到 Internet;
  • CentOS 配置端口映射,將 192.168.1.10 的 8080 端口映射到 CentOS 的公網(wǎng)地址 200.1.1.1 的 8080 端口。

配置

  • CentOS

配置接口與路由

[root@CentOS ~]# vim /etc/sysconfig/network-scripts/ifcfg-tun0
DEVICE=tun0
BOOTPROTO=none
ONBOOT=yes
DEVICETYPE=tunnel
TYPE=GRE
PEER_INNER_IPADDR=172.16.1.2
PEER_OUTER_IPADDR=100.1.1.1
MY_INNER_IPADDR=172.16.1.1
MY_OUTER_IPADDR=200.1.1.1
[root@CentOS ~]# vim /etc/sysconfig/network-scripts/route-tun0
192.168.1.0/24 via 172.16.1.2
[root@CentOS ~]# ifup tun0

 

Iptables 配置

# 安裝 iptables 管理服務(wù)
[root@CentOS ~]# yum install iptables-services
# 在 INPUT 方向要放行對(duì)端的公網(wǎng)地址
[root@CentOS ~]# iptables -I INPUT -s 100.1.1.1/32 -j ACCEPT
# 配置源地址轉(zhuǎn)換
[root@CentOS ~]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 200.1.1.1
# 端口映射
[root@CentOS ~]# iptables -t nat -A PREROUTING -d 200.1.1.1 -p tcp --dport 8080 -j DNAT --to-dest 192.168.1.10:8080
# 保存 iptables
[root@CentOS ~]# service iptables save

 

開(kāi)啟 ipv4 轉(zhuǎn)發(fā)

[root@CentOS ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
[root@CentOS ~]# sysctl -p

 

華為防火墻

本次以華為 USG6300E 系列防火墻為例:

配置接口,并添加到安全區(qū)域

 

interface Tunnel0
ip address 172.16.1.2 255.255.255.0
tunnel-protocol gre
source 100.1.1.1
destination 200.1.1.1
# 將接口添加到安全區(qū)域內(nèi)
[USG6300E] firewall zone tunnel
firewall zone name tunnel
set priority 75
add interface Tunnel0

 

配置安全策略

在實(shí)際的實(shí)施中,可以將策略收緊一些,根據(jù)需求限制源和目的地址。如果條件允許的話,可以先將默認(rèn)安全策略設(shè)置為 permit,待調(diào)通之后,再修改安全策略:security-policy
rule name tunnel_out
source-zone trust
destination-zone tunnel
action permit

rule name tunnel_in
source-zone tunnel
destination-zone trust
action permit
# 放行 tunnel 到 untrust 的流量
rule name tunnel_untrust
source-zone tunnel
destination-zone untrust
action permit

配置策略路由

[USG6300E]policy-based-route
#
policy-based-route
rule name PBR
source-zone trust
source-address 192.168.1.0 mask 255.255.255.0
action pbr egress-interface Tunnel0配置 No-NAT設(shè)置去往隧道的流量不使用源地址轉(zhuǎn)換:[USG6300E-policy-nat]dis th
nat-policy
rule name SNAT
source-zone tunnel
destination-zone untrust
source-address 192.168.1.0 mask 255.255.255.0
action no-nat

驗(yàn)證

主要有如下幾個(gè)測(cè)試方法:

  1. 在 CentOS 或 防火墻 ping 對(duì)端的隧道地址;
  2. 使用 192.168.1.0/24 網(wǎng)段內(nèi)的設(shè)備 traceroute 公網(wǎng)地址,查看經(jīng)過(guò)的路徑以確認(rèn)是否經(jīng)過(guò)隧道轉(zhuǎn)發(fā)。

 

Ubuntu 18 與 華為路由器建立 GRE 隧道

拓?fù)鋱D

Linux與網(wǎng)絡(luò)設(shè)備 GRE配置經(jīng)驗(yàn)總結(jié)

 

實(shí)現(xiàn)目標(biāo)

  • Ubuntu 18 與華為路由器建立 GRE 隧道;
  • 華為防火墻背后的內(nèi)網(wǎng)網(wǎng)段 192.168.1.0/24 通過(guò) GRE 隧道從 CentOS 到 Internet;
  • Ubuntu 配置端口映射,將 192.168.1.10 的 8080 端口映射到 CentOS 的公網(wǎng)地址 200.1.1.1 的 8080 端口。

 

配置

  • Ubuntu

netplan 配置

root@ubunt18demo:~# vim /etc/netplan/00-installer-config.yaml
network:
ethernets:
ens3:
addresses:
- 200.1.1.1/24
gateway4: 200.1.1.254
nameservers:
addresses:
- 114.114.114.114
tunnels:
tun0:
mode: gre
local: 200.1.1.1
remote: 100.1.1.1
addresses: [ 172.16.1.1/24 ]
routes:
- to: 192.168.1.0/24
via: 172.16.1.2
# 可以先執(zhí)行 netplan try 驗(yàn)證一下,如果沒(méi)有斷掉的話可以按 ENTER 確認(rèn)配置
# 如果和主機(jī) SSH 中斷,可以等待 120S 會(huì)自動(dòng)恢復(fù)
root@ubunt18demo:~# netplay try

 

iptables 設(shè)置

Ufw 是 Ubuntu 的防火墻配置工具,底層還是調(diào)用 iptables 處理的:# 啟用 ufw
ufw enable
# 放行 SSH
ufw allow ssh
# 放行 GRE 對(duì)端進(jìn)入的流量
ufw allow from 100.1.1.1/32
# 配置 nat 映射
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 200.1.1.1
iptables -t nat -A PREROUTING -d 200.1.1.1 -p tcp --dport 8080 -j DNAT --to-dest 192.168.1.10:8080
# 將 ufw 設(shè)置為開(kāi)機(jī)自啟動(dòng)
systemctl enable ufw開(kāi)啟 ipv4 轉(zhuǎn)發(fā):echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p

華為路由器

以 AR1200 系列路由器為例:

配置接口interface Tunnel0/0/1
ip address 172.16.1.2 255.255.255.0
tunnel-protocol gre
source 100.1.1.1
destination 200.1.1.1

配置策略路由# 配置 ACL
[AR1200] acl number 3000
[AR1200-acl-adv-3000] rule 10 permit ip destination 192.168.1.0 0.0.0.255
# 配置流分類(lèi)
[AR1200] traffic classifier togretunnel
[AR1200-classifier-togretunnel] if-match acl 3000
# 配置流行為
[AR1200] traffic behavior togretunnel
[AR1200-behavior-togretunnel] redirect ip-nexthop 172.16.1.1
# 配置流策略
[AR1200] traffic policy togretunnel
[AR1200-trafficpolicy-vlan10] classifier togretunnel behavior togretunnel
# 在內(nèi)網(wǎng)口調(diào)用流策略
[AR1200] interface gigabitethernet 1/0/1
[AR1200-GigabitEthernet3/0/0] traffic-policy togretunnel inbound

 

驗(yàn)證

驗(yàn)證方法同 CentOS 與 華為防火墻建立 GRE 隧道一致。

 

Juniper SRX 防火墻的 GRE 配置

SRX 防火墻的出接口如果使用了 route-instances,那么配置 tunnel 口時(shí),一定要注意增加 route-instance destination,如下所示:

set interfaces gr-0/0/0 unit 0 tunnel source 100.1.1.1
set interfaces gr-0/0/0 unit 0 tunnel destination 200.1.1.1
set interfaces gr-0/0/0 unit 0 tunnel routing-instance destination EXAMPLE-INSTANCE
set interfaces gr-0/0/0 unit 0 family inet address 172.16.1.2/24

另外策略路由在 SRX 中稱(chēng)為 FBF,還有 No-NAT的配置示例如下:

# 配置 firewall filter,匹配需要進(jìn)入隧道的流量
set firewall filter to-GreTunnel term 1 from source-address 192.168.1.0/24
set firewall filter to-GreTunnel term 1 then routing-instance EXAMPLE-INSTANCE
set firewall filter to-GreTunnel term 3 then accept

set routing-options rib-groups global import-rib EXAMPLE-INSTANCE.inet.0

# 配置去往 Gre Tunnel 的路由
set routing-instances EXAMPLE-INSTANCE instance-type forwarding
set routing-instances EXAMPLE-INSTANCE routing-options interface-routes rib-group inet global
set routing-instances EXAMPLE-INSTANCE routing-options static route 0.0.0.0/0 next-hop 172.16.1.1

# 在內(nèi)網(wǎng)口調(diào)用 firewall filter
set interfaces reth2 unit 0 family inet filter input to-GreTunnel

# 去往隧道口的流量不做 SNAT
set security nat source rule-set Gre-snat from zone Trust
set security nat source rule-set Gre-snat to zone EXAMPLE-INSTANCE
set security nat source rule-set Gre-snat rule to-cn2-no-nat match source-address 192.168.1.0/24
set security nat source rule-set Gre-snat rule to-cn2-no-nat match destination-address 0.0.0.0/0
set security nat source rule-set Gre-snat rule to-cn2-no-nat then source-nat off

 

CentOS 的策略路由

如果有使用 Linux 作為中轉(zhuǎn)的場(chǎng)景,也就是說(shuō)華為防火墻和 Linux 建立 GRE 隧道,Linux 又和其他設(shè)備建立,由 Linux 做中轉(zhuǎn)流量,這種場(chǎng)景下,可以在 Linux 配置策略路由,如下所示:

# 臨時(shí)配置,重啟后會(huì)消失,可以作為調(diào)試使用
ip rule add from 192.168.1.0/24 table 100 pref 10
ip route add 0.0.0.0/0 via 200.1.1.254 table 100

# 將配置持久化
vim /etc/sysconfig/network-scripts/rule-eth0
from 192.168.1.0/24 table 100 pref 10

vim /etc/sysconfig/network-scripts/route-eth0
default via 172.16.1.1 dev tun0

# 驗(yàn)證命令
ip rule show
ip route show table 100

 

總結(jié)

GRE雖然配置還比較簡(jiǎn)單, 在實(shí)際項(xiàng)目中會(huì)經(jīng)常用到。 Linux 通常需要系統(tǒng)工程師配置,而網(wǎng)絡(luò)設(shè)備通常由網(wǎng)絡(luò)工程師配置,如果對(duì)接有問(wèn)題,則需要溝通協(xié)調(diào),就比較浪費(fèi)時(shí)間。如果一個(gè)工程師能夠完成兩種設(shè)備的配置,并進(jìn)行排錯(cuò),那么效率將會(huì)提高很多。

分享到:
標(biāo)簽:配置 GRE
用戶無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定