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: 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: 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: mtu 1480 qdisc noop

link/sit 0.0.0.0 brd 0.0.0.0

4: gre0: mtu 1476 qdisc noop

link/gre 0.0.0.0 brd 0.0.0.0

5: tunnel0@NONE: 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: 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: 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: mtu 1480 qdisc noop

link/sit 0.0.0.0 brd 0.0.0.0

4: gre0: mtu 1476 qdisc noop

link/gre 0.0.0.0 brd 0.0.0.0

5: tunnel0@NONE: 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 创建ll,两台linux建立GRE隧道相关推荐

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

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

  2. linux 远程存储服务器,两台linux服务器远程备份

    1.配置SSH自动安全访问机制登录到离线存储服务器#offsite以后,使用ssh-keygen程序并给出-t dsa选项来创建一个公钥/密钥对.-t选项是必须的,用来指定我们要生成的密钥类型.我们将 ...

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

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

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

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

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

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

  6. 2019-8-24 [Linux] 15.搭建两台虚拟机实现互联组成一个小型网络 详细版

    文章目录 15.1 需求说明 1.2 分技术介绍 1.2.1 JDK 1.2.2 Tomcat 1.2.3 MySQL 1.2.4 Nginx 1.2.4.1 序言 1.2.4.2 Nginx常用功能 ...

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

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

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

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

  9. 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 ...

最新文章

  1. linux shell ls 时间排序显示
  2. java不能修改表_java中不可修改列表的类型是什么
  3. 新BOJ 88. 最值问题
  4. QT的QByteArray 类的使用
  5. myeclipse中代码提示和编辑区颜色设置
  6. 当前进程(Linux Devices Driver)
  7. 「Python」为什么Python里面,整除的结果会是小数?
  8. 程序员,你能真正掌握多少编程技术?
  9. 51单片机配合超声波测距以及用1602液晶进行显示
  10. Linux 文件传输
  11. Win11正式版版号 Win11正式版最新版本号介绍
  12. Java - 常用函数Random函数
  13. Webservice 用http get方式无法请求到的解决办法
  14. 移动端H5游戏开发之(移动端尺寸基础知识)
  15. 抖音订单捉取-php
  16. 如何使用Python制作网站?
  17. linux office转换pdf
  18. 计算机动漫游戏与制作,计算机动漫与游戏制作标准规范.doc
  19. JavaScript函数式编程之函子
  20. 11月最值得关注的26个热点

热门文章

  1. 微软技术专家为您解读深度学习
  2. 为什么 web 开发人员需要迁移到. NET Core, 并使用 ASP.NET Core MVC 构建 web 和 API
  3. 听说你开发.NET还在用VS,小哥哥给你推荐全平台的Rider
  4. ABPZero系列教程之拼多多卖家工具
  5. ASP.NET Core 源码学习之 Options[3]:IOptionsSnapshot
  6. 物联网模式下的多活数据中心架构认识与实践
  7. Python FastApi:post文件与数据/本地端测试
  8. 【ArcGIS遇上Python】python批量获取栅格数据四至(top,bottom,left,right)坐标代码
  9. 字符串之替换字符串中连续出现的指定字符串
  10. svn之Previous operation has not finished; run ‘cleanup‘ if it was interrupted解决办法