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
 

你可能感兴趣的:(gre)