偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

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

系統(tǒng) Linux
GRE(General Routing Encapsulation),即通用路由封裝,是一種三層技術(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)題。

[[353011]]

本文轉(zhuǎn)載自微信公眾號(hào)「新鈦云服」,作者侯明明。轉(zhuǎn)載本文請(qǐng)聯(lián)系新鈦云服公眾號(hào)。   

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

GRE(General Routing Encapsulation),即通用路由封裝,是一種三層技術(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é)議。

GRE 的配置場(chǎng)景

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

拓?fù)鋱D

實(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

配置接口與路由

  1. [root@CentOS ~]# vim /etc/sysconfig/network-scripts/ifcfg-tun0 
  2. DEVICE=tun0 
  3. BOOTPROTO=none 
  4. ONBOOT=yes 
  5. DEVICETYPE=tunnel 
  6. TYPE=GRE 
  7. PEER_INNER_IPADDR=172.16.1.2 
  8. PEER_OUTER_IPADDR=100.1.1.1 
  9. MY_INNER_IPADDR=172.16.1.1 
  10. MY_OUTER_IPADDR=200.1.1.1 
  11.  
  12. [root@CentOS ~]# vim /etc/sysconfig/network-scripts/route-tun0 
  13. 192.168.1.0/24 via 172.16.1.2 
  14.  
  15. [root@CentOS ~]# ifup tun0 

Iptables 配置

  1. # 安裝 iptables 管理服務(wù) 
  2. [root@CentOS ~]# yum install iptables-services 
  3.  
  4. # 在 INPUT 方向要放行對(duì)端的公網(wǎng)地址 
  5. [root@CentOS ~]# iptables -I INPUT -s 100.1.1.1/32 -j ACCEPT 
  6.  
  7. # 配置源地址轉(zhuǎn)換 
  8. [root@CentOS ~]# iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 200.1.1.1 
  9.  
  10. # 端口映射 
  11. [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 
  12.  
  13. # 保存 iptables 
  14. [root@CentOS ~]# service iptables save 

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

  1. [root@CentOS ~]# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf 
  2.  
  3. [root@CentOS ~]# sysctl -p 
  • 華為防火墻

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

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

  1. interface Tunnel0 
  2. ip address 172.16.1.2 255.255.255.0 
  3. tunnel-protocol gre 
  4. source 100.1.1.1 
  5. destination 200.1.1.1 
  6.  
  7. # 將接口添加到安全區(qū)域內(nèi) 
  8. [USG6300E] firewall zone tunnel 
  9. firewall zone name tunnel 
  10. set priority 75 
  11. add interface Tunnel0 

配置安全策略

在實(shí)際的實(shí)施中,可以將策略收緊一些,根據(jù)需求限制源和目的地址。

如果條件允許的話,可以先將默認(rèn)安全策略設(shè)置為 permit,待調(diào)通之后,再修改安全策略:

  1. security-policy 
  2. rule name tunnel_out 
  3. source-zone trust 
  4. destination-zone tunnel 
  5. action permit 
  6.   
  7. rule name tunnel_in 
  8. source-zone tunnel 
  9. destination-zone trust 
  10. action permit 
  11.  
  12. # 放行 tunnel 到 untrust 的流量 
  13. rule name tunnel_untrust 
  14. source-zone tunnel 
  15. destination-zone untrust 
  16. action permit 

配置策略路由

  1. [USG6300E]policy-based-route 
  2. policy-based-route 
  3. rule name PBR 
  4. source-zone trust 
  5. source-address 192.168.1.0 mask 255.255.255.0 
  6. action pbr egress-interface Tunnel0 

配置 No-NAT

設(shè)置去往隧道的流量不使用源地址轉(zhuǎn)換:

  1. [USG6300E-policy-nat]dis th 
  2. nat-policy 
  3. rule name SNAT 
  4. source-zone tunnel 
  5. destination-zone untrust 
  6. source-address 192.168.1.0 mask 255.255.255.0 
  7. 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

實(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 配置

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

iptables 設(shè)置

Ufw 是 Ubuntu 的防火墻配置工具,底層還是調(diào)用 iptables 處理的:

  1. # 啟用 ufw 
  2. ufw enable 
  3.  
  4. # 放行 SSH 
  5. ufw allow ssh 
  6.  
  7. # 放行 GRE 對(duì)端進(jìn)入的流量 
  8. ufw allow from 100.1.1.1/32 
  9.  
  10. # 配置 nat 映射 
  11. iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 200.1.1.1 
  12. iptables -t nat -A PREROUTING -d 200.1.1.1 -p tcp --dport 8080 -j DNAT --to-dest 192.168.1.10:8080 
  13.  
  14. # 將 ufw 設(shè)置為開(kāi)機(jī)自啟動(dòng) 
  15. systemctl enable ufw 

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

  1. echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf 
  2.  
  3. sysctl -p 

華為路由器

以 AR1200 系列路由器為例:

  • 配置接口
  1. interface Tunnel0/0/1 
  2. ip address 172.16.1.2 255.255.255.0 
  3. tunnel-protocol gre 
  4. source 100.1.1.1 
  5. destination 200.1.1.1 
  • 配置策略路由
  1. # 配置 ACL 
  2. [AR1200] acl number 3000 
  3. [AR1200-acl-adv-3000] rule 10 permit ip destination 192.168.1.0 0.0.0.255 
  4.  
  5. # 配置流分類(lèi) 
  6. [AR1200] traffic classifier togretunnel 
  7. [AR1200-classifier-togretunnel] if-match acl 3000 
  8.  
  9. # 配置流行為 
  10. [AR1200] traffic behavior togretunnel 
  11. [AR1200-behavior-togretunnel] redirect ip-nexthop 172.16.1.1 
  12.  
  13. # 配置流策略 
  14. [AR1200] traffic policy togretunnel 
  15. [AR1200-trafficpolicy-vlan10] classifier togretunnel behavior togretunnel 
  16.  
  17. # 在內(nèi)網(wǎng)口調(diào)用流策略 
  18. [AR1200] interface gigabitethernet 1/0/1 
  19. [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,如下所示:

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

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

  1. # 配置 firewall filter,匹配需要進(jìn)入隧道的流量 
  2. set firewall filter to-GreTunnel term 1 from source-address 192.168.1.0/24 
  3. set firewall filter to-GreTunnel term 1 then routing-instance EXAMPLE-INSTANCE 
  4. set firewall filter to-GreTunnel term 3 then accept 
  5.  
  6. set routing-options rib-groups global import-rib EXAMPLE-INSTANCE.inet.0 
  7.  
  8. # 配置去往 Gre Tunnel 的路由 
  9. set routing-instances EXAMPLE-INSTANCE instance-type forwarding 
  10. set routing-instances EXAMPLE-INSTANCE routing-options interface-routes rib-group inet global 
  11. set routing-instances EXAMPLE-INSTANCE routing-options static route 0.0.0.0/0 next-hop 172.16.1.1 
  12.  
  13. # 在內(nèi)網(wǎng)口調(diào)用 firewall filter 
  14. set interfaces reth2 unit 0 family inet filter input to-GreTunnel 
  15.  
  16. # 去往隧道口的流量不做 SNAT 
  17. set security nat source rule-set Gre-snat from zone Trust 
  18. set security nat source rule-set Gre-snat to zone EXAMPLE-INSTANCE 
  19. set security nat source rule-set Gre-snat rule to-cn2-no-nat match source-address 192.168.1.0/24 
  20. set security nat source rule-set Gre-snat rule to-cn2-no-nat match destination-address 0.0.0.0/0 
  21. 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 配置策略路由,如下所示:

  1. # 臨時(shí)配置,重啟后會(huì)消失,可以作為調(diào)試使用 
  2. ip rule add from 192.168.1.0/24 table 100 pref 10 
  3. ip route add 0.0.0.0/0 via 200.1.1.254 table 100 
  4.  
  5. # 將配置持久化 
  6. vim /etc/sysconfig/network-scripts/rule-eth0 
  7. from 192.168.1.0/24 table 100 pref 10 
  8.  
  9. vim /etc/sysconfig/network-scripts/route-eth0 
  10. default via 172.16.1.1 dev tun0 
  11.  
  12. # 驗(yàn)證命令 
  13. ip rule show 
  14. 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ì)提高很多。

 

責(zé)任編輯:武曉燕 來(lái)源: 新鈦云服
相關(guān)推薦

2013-12-18 15:54:21

2009-10-15 09:27:00

2010-08-20 11:51:52

ADSL設(shè)備

2009-12-18 18:29:43

Linux Fedor

2009-10-28 17:04:20

linux快速啟動(dòng)

2009-12-16 14:32:14

Linux Mint系

2020-04-20 21:22:50

網(wǎng)絡(luò)設(shè)備網(wǎng)絡(luò)協(xié)議計(jì)算機(jī)網(wǎng)絡(luò)

2009-08-19 09:24:43

AJAX引擎經(jīng)驗(yàn)總結(jié)

2009-09-29 16:32:11

OJB Hiberna

2009-09-16 17:13:54

學(xué)習(xí)Linq

2009-10-21 14:43:42

linux網(wǎng)絡(luò)設(shè)備

2021-09-09 14:54:10

Linuxbridge網(wǎng)絡(luò)設(shè)備

2010-05-18 18:19:07

Subversion服

2010-07-13 16:07:18

Perl

2010-05-19 16:57:49

SVN與CVS的區(qū)別

2010-01-26 13:28:11

Android開(kāi)發(fā)要點(diǎn)

2010-01-27 18:12:14

Android dia

2010-03-08 15:12:27

Python語(yǔ)言

2009-08-13 18:13:27

C#學(xué)習(xí)經(jīng)驗(yàn)

2009-09-25 17:26:55

使用Hibernate
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)