1.拓扑图: 

备注:因为应用原因,需要在linux2上添加一个公网地址,并且在中间路由设备不受控制的情况下,Linux1能访问到linux2上面的公网地址。

2.基本接口配置:

linux1:192.168.10.1/24

linux2:192.168.20.2/24

R1:

interface FastEthernet0/0
 ip address 192.168.10.10 255.255.255.0
 no shutdown
!
interface FastEthernet0/1
 ip address 192.168.20.10 255.255.255.0
 no shutdown

3.路由配置:

linux1网关:192.168.10.10
linux2网关:192.168.20.10
R1:只有直连路由

4.Linux2单网卡多地址配置:

[root@Linux1 ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
[root@Linux1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0:0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:08:48:63
NETMASK=255.255.255.252
IPADDR=202.100.2.2

TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

[root@Linux1 ~]# service network restart
[root@Linux1 ~]# ping 202.100.2.2
PING 202.100.2.2 (202.100.2.2) 56(84) bytes of data.
64 bytes from 202.100.2.2: icmp_seq=1 ttl=64 time=0.124 ms

--- 202.100.2.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.124/0.124/0.124/0.000 ms
[root@ams ~]# ping 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=255 time=70.6 ms

--- 192.168.10.10 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 70.629/70.629/70.629/0.000 ms

5.GRE tunnel配置:

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

[root@linux1 ~]# uname -an
Linux linux1 2.6.9-78.EL #1 Wed Jul 9 15:27:01 EDT 2008 i686 i686 i386 GNU/Linux
[root@linux1 ~]# insmod /lib/modules/2.6.9-78.EL/kernel/net/ipv4/ip_gre.ko
[root@linux2 ~]# uname -an
Linux linux2 2.6.18-164.el5 #1 SMP Thu Sep 3 03:33:56 EDT 2009 i686 i686 i386 GNU/Linux
[root@linux2 ~]# insmod /lib/modules/2.6.18-164.el5/kernel/net/ipv4/ip_gre.ko

C.GRE tunnel接口配置

Linux1:
ip tunnel add tunnel0 mode gre remote 192.168.20.2 local 192.168.10.1 ttl 255
ip link set tunnel0 up mtu 1400
ip addr add 172.16.1.1/30  dev tunnel0
ip addr add 172.16.1.1/30 peer 172.16.1.2/30 dev tunnel0
ip route add 202.100.2.2/32 dev tunnel0
Linux2:
ip tunnel add tunnel0 mode gre remote 192.168.10.1 local 192.168.20.2 ttl 255
ip link set tunnel0 up mtu 1400
ip addr add 172.16.1.2/30  dev tunnel0
ip addr add 172.16.1.2/30 peer 172.16.1.1/30 dev tunnel0
D.将tunnel配置开机运行:

linux1:
vi /etc/init.d/gre.sh   ##内容如下:
insmod /lib/modules/2.6.9-78.EL/kernel/net/ipv4/ip_gre.ko
ip tunnel add tunnel0 mode gre remote 192.168.20.2 local 192.168.10.1 ttl 255
ip link set tunnel0 up mtu 1400
ip addr add 172.16.1.1/30  dev tunnel0
ip addr del 172.16.1.1/30 peer 172.16.1.2/30 dev tunnel0
ip addr add 172.16.1.1/30 peer 172.16.1.2/30 dev tunnel0
ip route add 202.100.2.2/32 dev tunnel0

chmod +x /etc/init.d/gre.sh
echo "/etc/init.d/gre.sh" >> /etc/rc.d/rc.local

linux2:
vi /etc/init.d/gre.sh   ##内容如下:
insmod /lib/modules/2.6.18-164.el5/kernel/net/ipv4/ip_gre.ko
ip tunnel add tunnel0 mode gre remote 192.168.10.1 local 192.168.20.2 ttl 255
ip link set tunnel0 up mtu 1400
ip addr add 172.16.1.2/30  dev tunnel0
ip addr del 172.16.1.2/30 peer 172.16.1.1/30 dev tunnel0
ip addr add 172.16.1.2/30 peer 172.16.1.1/30 dev tunnel0

chmod +x /etc/init.d/gre.sh
echo "/etc/init.d/gre.sh" >> /etc/rc.d/rc.local

D.验证GRE接口

[root@Linux1 ~]# ip addr show
1: lo: <LOOPBACK,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 brd 127.255.255.255 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:e4:65:78 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.1/24 brd 192.168.10.255 scope global eth0
    inet6 fe80::20c:29ff:fee4:6578/64 scope link
       valid_lft forever preferred_lft forever
3: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
4: gre0: <NOARP> mtu 1476 qdisc noop
    link/gre 0.0.0.0 brd 0.0.0.0
5: tunnel0@NONE: <POINTOPOINT,NOARP,UP> mtu 1400 qdisc noqueue
    link/gre 192.168.10.1 peer 192.168.20.2
    inet 172.16.1.1 peer 172.16.1.2/30 scope global tunnel0
[root@Linux2 ~]# 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:08:48:63 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.2/24 brd 192.168.20.255 scope global eth0
    inet 202.100.2.2/30 brd 202.100.2.3 scope global eth0:0
    inet6 fe80::20c:29ff:fe08:4863/64 scope link
       valid_lft forever preferred_lft forever
3: sit0: <NOARP> mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0
4: gre0: <NOARP> mtu 1476 qdisc noop
    link/gre 0.0.0.0 brd 0.0.0.0
5: tunnel0@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1400 qdisc noqueue
    link/gre 192.168.20.2 peer 192.168.10.1
    inet 172.16.1.2 peer 172.16.1.1/30 scope global tunnel0

5.效果测试:

[root@linux1 ~]#  ping 202.100.2.2
PING 202.100.2.2 (202.100.2.2) 56(84) bytes of data.
64 bytes from 202.100.2.2: icmp_seq=0 ttl=64 time=82.4 ms
64 bytes from 202.100.2.2: icmp_seq=1 ttl=64 time=48.7 ms

--- 202.100.2.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 48.784/65.633/82.482/16.849 ms, pipe 2

两台linux建立GRE隧道相关推荐

  1. linux 创建ll,两台linux建立GRE隧道

    1.拓扑图:  备注:因为应用原因,需要在linux2上添加一个公网地址,并且在中间路由设备不受控制的情况下,Linux1能访问到linux2上面的公网地址. 2.基本接口配置: linux1:192 ...

  2. linux 隧道服务器,如何在两台CentOS 7服务器之间建立GRE隧道

    介绍 什么是GRE?有哪些优势? GRE代表Generic Routing Encapsulation(通用路由封装),它允许两台服务器私下通信.GRE隧道非常有用,因为它们允许所有类型的流量通过.它 ...

  3. linux命令——scp 两台linux机器间文件或目录传输

    不同的Linux之间copy文件常用有3种方法: 第一种:ftp,也就是其中一台Linux安装ftpServer,这样可以另外一台使用ftp的client程序来进行文件的copy. 第二种:采用sam ...

  4. 两台Linux完美实现双机热备

    两台Linux完美实现双机热备 2012年09月22日 18:57:30 阅读数:1844 http://www.51testing.com/html/06/n-186706-4.html 一直想做基 ...

  5. 两台linux之间传输文件的方法

    scp传输 当两台Linux主机之间要互传文件时可使用SCP命令来实现 scp传输速度较慢,但使用ssh通道保证了传输的安全性 复制文件 将本地文件拷贝到远程 scp 文件名 –用户名@计算机IP或者 ...

  6. 两台Linux系统之间传输文件的几种方法

    scp传输 当两台LINUX主机之间要互传文件时可使用SCP命令来实现 scp传输速度较慢,但使用ssh通道保证了传输的安全性 复制文件 将本地文件拷贝到远程 scp 文件名 –用户名@计算机IP或者 ...

  7. linux网络编程IPv6socket,简单的IPv6 UDP/TCP socket编程 -- 两台Linux实现简单的ipv6通信...

    配置: 1.两台linux用网线直接相连 2.手动配置两台linux的ipv6地址为: ifconfig eth0 add 2001:da8:e000::1:1:1 ifconfig eth0 add ...

  8. 以两台Linux主机在docker中实现mysql主主备份以用nginx实现mysql高可用

    使用nginx反向代理主主备份的两台mysql,连接时连接nginx,当其中一台myql停止后,仍然可以正常使用,如果使用k8s 会简单许多.所谓主主复制就是在主从复制的基础上掉了个头. 请博主买块糖 ...

  9. 两台 Linux 主机之间配置信任关系(以及如何解除)

      主机之间的 ssh 信任,简单地说,就是主机之间使用 ssh 命令登录主机不需要密码.   一.主机之间配置信任关系   将主机 A (47.100.247.242) 作为信任主机,主机 B(10 ...

最新文章

  1. svn文件丢失的解法
  2. 《深入理解Elasticsearch(原书第2版)》一2.3.3 把查询模板保存到文件
  3. 解析Servlet/JSP会话跟踪机制
  4. 用macport安装nginx
  5. mongodb E11000 duplicate key error collection: index: _id_ dup key
  6. spring源码解析bean定义五ContextNamespaceHandler一
  7. Spring源码之事务(一)
  8. 威斯敏斯特教堂(西敏寺)墓碑上的话(WestMinster Abbey,When I was young and fre
  9. 【解决方案】关于自动生成表hibernate_sequence的问题
  10. 台式计算机的配置清单表格,电脑配置清单表格,为你分别介绍不同价位的三种配置清单...
  11. 【软件定义汽车】【操作系统篇】特斯拉–Version
  12. 人工智障和神经病网络对话--30行python让图灵机器人和茉莉机器人无止尽的瞎扯蛋
  13. 线段树的进阶:多种信息的维护与传递
  14. java mail 554_【Java】JavaMail 554错误解决方法
  15. 要达到什么水平才能找到一份软件自动化测试的工作?
  16. [转载]用VB编写一个聊天程序!
  17. js input获取焦点和失去焦点的操作
  18. 完全卸载vscode
  19. 高一4月段考GDOI2021划水记 总结
  20. 金山快盘开发 (一)

热门文章

  1. 『科学计算_理论』矩阵求导
  2. 用C#来播放.wav格式的音频文件
  3. 回答朋友的问题(关于 RTEMS 学习)
  4. 【强烈推荐】蒋勋细说《红楼梦》
  5. 大数据中存在哪些误解
  6. 物联网大数据如何改善农业运营
  7. 大数据在消防安全中的新应用
  8. Java编程基础 - 泛型
  9. java的语法基础_JAVA语法基础1(入门手册)
  10. 2018北邮计算机考研分数线,2018年北京邮电大学软件学院考研复试分数线