How to configure a GRE Tunnel in CentOS

原文链接:https://www.centoshowtos.org/network-and-security/gre-tunnel/

Load GRE Kernel Module

We need to load the gre kernel module, and also set it to load at boot time.

modprobe ip_gre

Now set it to start at boot

echo "/sbin/modprobe ip_gre > /dev/null 2>&1" > /etc/sysconfig/modules/ip_gre.modules
chmod 755 /etc/sysconfig/modules/ip_gre.modules

Create ifcfg-tun0 Configuration Files

We need to create the configuration files for the GRE tunnel. These files live alongside your CentOS network device files in /etc/sysconfig/network-scripts/

On one side(host IP is 141.136.108.122):

Create ifcfg-tun0 file. Please note, the internal and external interfaces must already be configured and plugged into the correct ports for each network.

vi /etc/sysconfig/network-scripts/ifcfg-tun0

The file should look like this (except your IPs will be different)

DEVICE=tun0
BOOTPROTO=none
ONBOOT=yes
TYPE=GRE
PEER_OUTER_IPADDR=216.52.2.41
PEER_INNER_IPADDR=192.168.77.253
MY_INNER_IPADDR=192.168.77.254

On the other side(host IP is 216.52.2.41):

Create ifcfg-tun0 file where the network interface scripts are.

vi /etc/sysconfig/network-scripts/ifcfg-tun0

The file should look like this (except your IPs will be different)

DEVICE=tun0
BOOTPROTO=none
ONBOOT=yes
TYPE=GRE
PEER_OUTER_IPADDR=141.136.108.122
PEER_INNER_IPADDR=192.168.77.254
MY_INNER_IPADDR=192.168.77.253

Bring tun0 interfaces online and verify

Now that we have the configuration files setup, we will need to bring up the tunnel interfaces and verify that they came online properly.

On both of   141.136.108.122 and 216.52.2.41:

We’ll just use the ifup command to bring up the interfaces.  and we can verify with the ifconfig command.

ifup tun0
ifconfig tun0


Test the connection

At this point the tunnel should be online, and the machines should be able to reach one another via internal IP addresses. Lets ping each other and make sure everything looks ok – make sure your firewall isn’t dropping ICMP packets if it doesn’t work.

On one side(host IP is 141.136.108.122):

Ping 216.52.2.41 internal address

ping 192.168.77.253

On the other side(host IP is 216.52.2.41):

Ping 141.136.108.122 internal address

ping 192.168.77.254

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值