GRE between Router and linux

简介:

1.拓扑图
 

参考:http://www.time-dms.com.cn/viewthread.asp?tid=1904
 

2.基本接口配置:

R1:

R1(config)#int e0/0
R1(config-if)#ip add 10.1.1.1 255.255.255.0
R1(config-if)#no sh

R2:

R2(config)#int e0/0
R2(config-if)#ip add 10.1.1.2 255.255.255.0
R2(config-if)#no sh

R2(config)#int e0/1
R2(config-if)#ip add 202.100.1.2 255.255.255.0
R2(config-if)#no sh

R3:

R3(config)#int e0/0
R3(config-if)#ip add 202.100.1.3 255.255.255.0
R3(config-if)#no sh

R3(config)#int e0/1
R3(config-if)#ip add 202.100.2.3 255.255.255.0
R3(config-if)#no sh

C1:

eth0: 202.100.1.10/24
eth1:10.1.2.10/24

PC:

eth0:10.1.2.10/24

3.路由配置:

R1(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.2
R2(config)#ip route 0.0.0.0 0.0.0.0 202.100.1.3
C1:Default GateWay  202.100.2.3
PC:Default GateWay  10.1.2.10

4.GRE配置

R3:

R2(config)#int tun 0
R2(config-if)#ip add 172.16.1.1 255.255.255.252
R2(config-if)#tunnel source 202.100.1.2
R2(config-if)#tun
R2(config-if)#tunnel de
R2(config-if)#tunnel destination 202.100.2.10
R2(config-if)#end

R2(config)#ip route 10.1.2.0 255.255.255.0 tunnel 0


C1:

A.确定是否加载了GRE模块
[root@cluster01 ~]# lsmod |grep ip_gre

B.加载GRE模块
[root@cluster01 ~]# insmod /lib/modules/2.6.18-
2.6.18-159.el5/     2.6.18-238.9.1.el5/ 2.6.18-92.1.10.el5/
2.6.18-164.el5/     2.6.18-238.el5/     

[root@cluster01 ~]# uname -an
Linux cluster01 2.6.18-238.9.1.el5 #1 SMP Tue Apr 12 18:10:56 EDT 2011 i686 i686 i386 GNU/Linux
[root@cluster01 ~]# insmod
insmod         insmod.static  
[root@cluster01 ~]# insmod /lib/modules/2.6.18-238.9.1.el5/kernel/net/ipv4/ip
ipcomp.ko  ip_gre.ko  ipip.ko    ipvs/      
[root@cluster01 ~]# insmod /lib/modules/2.6.18-238.9.1.el5/kernel/net/ipv4/ip_gre.ko 

C.GRE tunnel接口配置
[root@cluster01 ~]# ip tunnel add tunnel0 mode gre remote 202.100.1.2 local 202.100.2.10 ttl 225
[root@cluster01 ~]# ip link set tunnel0 up mtu 1500
[root@cluster01 ~]# ip addr add 172.16.1.2/30 peer 172.16.1.1/30 dev tunnel0
[root@cluster01 ~]# ip route add 10.1.1.0/24 dev tunnel0

D.验证GRE接口
[root@cluster01 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:27:7d:b8 brd ff:ff:ff:ff:ff:ff
    inet 202.100.2.10/24 brd 202.100.2.255 scope global eth0
    inet6 fe80::20c:29ff:fe27:7db8/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:27:7d:c2 brd ff:ff:ff:ff:ff:ff
    inet 10.1.2.10/24 brd 10.1.2.255 scope global eth1
    inet6 fe80::20c:29ff:fe27:7dc2/64 scope link 
       valid_lft forever preferred_lft forever
4: sit0: <NOARP> mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0
5: gre0: <NOARP> mtu 1476 qdisc noop 
    link/gre 0.0.0.0 brd 0.0.0.0
6: tunnel0@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/gre 202.100.2.10 peer 202.100.1.2
    inet 172.16.1.2 peer 172.16.1.1/30 scope global tunnel0
[root@cluster01 ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:27:7d:b8 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:27:7d:c2 brd ff:ff:ff:ff:ff:ff
4: sit0: <NOARP> mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0
5: gre0: <NOARP> mtu 1476 qdisc noop 
    link/gre 0.0.0.0 brd 0.0.0.0
6: tunnel0@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/gre 202.100.2.10 peer 202.100.1.2
[root@cluster01 ~]# ip route show
172.16.1.0/30 dev tunnel0  proto kernel  scope link  src 172.16.1.2 
202.100.2.0/24 dev eth0  proto kernel  scope link  src 202.100.2.10 
10.1.1.0/24 dev tunnel0  scope link 
10.1.2.0/24 dev eth1  proto kernel  scope link  src 10.1.2.10 
169.254.0.0/16 dev eth1  scope link 
default via 202.100.2.3 dev eth0 

E.开启路由转发
[root@cluster01 ~]# echo 1 > /proc/sys/net/ipv4/ip_forward




本文转自 碧云天 51CTO博客,原文链接:http://blog.51cto.com/333234/846702,如需转载请自行联系原作者

相关文章
|
2天前
|
安全 网络协议 Linux
linux必学的60个命令
Linux是一个功能强大的操作系统,提供了许多常用的命令行工具,用于管理文件、目录、进程、网络和系统配置等。以下是Linux必学的60个命令的概览,但请注意,这里可能无法列出所有命令的完整语法和选项,仅作为参考
|
2天前
|
监控 Linux 数据处理
|
2天前
|
编解码 Ubuntu Linux
|
2天前
|
JSON Linux 数据格式
Linux命令发送http
请注意,`curl`命令非常灵活,可以根据您的需求进行多种配置和自定义。您可以查看 `curl`命令的文档以获取更多详细信息。
9 0
|
4天前
|
安全 Linux 测试技术
|
4天前
|
安全 Linux Windows
Linux中Shutdown命令使用介绍
Linux中Shutdown命令使用介绍
10 2
|
4天前
|
缓存 关系型数据库 Linux
Linux目录结构:深入理解与命令创建指南
Linux目录结构:深入理解与命令创建指南
|
5天前
|
数据挖掘 Linux vr&ar
Linux命令实战:解决日常问题的利器
Linux命令实战:解决日常问题的利器
|
5天前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
17 0
|
5天前
|
安全 Linux Shell
linux基础命令详解
linux基础命令详解
12 0