In previous post we seen configuring a gre tunnel betwen 2 ubuntu machines it was fine and good. Now our requirement is we have one server running in a cloud lets say Dimension Data, you might think not why amazon and azure, because to allow gre traffic you need to open ports for gre 47 but azure doesn't loadbalancers / firewall doesn't allow you to open ports for gre traffic. I don't remember exactly but i guess i have done opened gre ports on Amazon, any ways our aim at this point of time is to configure gre tunnel so lets do it.

you might be thinking why did i waste time writing same post again when same is written here.  That is what the main part of the configuration i'm going to let you know, first edit the configuration for gre on ubuntu machines both sides, then we need to do little modifications on vm running on cloud.  Actually all the vms running on cloud are behind a firewall / loadbalancer which means all are behind NAT. So if you enter as a part of regular configuration if you give public ip  address of cloud machine as local ip address in /etc/network/interfaces. It wont't work, while establishing connection other remote machine tries to connect interface on which public ip is assigned, but no public is not assigned to interface here.. isn't it ? you cloud machines physical interface has private ip. So here what we have to do is, use private ip in  /etc/network/interfaces instead giving remote ip.

Now to be clear have a look at ip details and configurations of  Machine A (physical machine at site) Machine B (vm on cloud)

Machine A (Physical):

Public IP: 10.0.0.1
Local IP:  192.168.1.254
Tunnel IP: 9.0.0.1

Machine B (vm on cloud)

Public IP: 10.0.0.2
Local IP:  192.168.2.254
Tunnel IP: 9.0.0.2

Now lets configure it. All you need to do is just add the below config to existing interface.

Machine A (Physical at site):
root@Machine-A:~# vim /etc/network/interfaces

auto lo
iface lo inet loopback

### local ip ####

auto eth0
iface eth0 inet static
        address 192.168.1.254
        netmask 255.255.255.0

### public ip ###

auto eth1
iface eth1 inet static
          address 10.0.0.1
          netmask 255.0.0.0
          gateway 10.0.0.254
          dns-nameserver        8.8.8.8

### gre tunnel ###


auto tun0
iface tun0 inet static
       address 9.0.0.1
       netmask 255.255.255.0
       broadcast 9.0.0.255
       up ifconfig tun0 multicast
      pre-up iptunnel add tun0 mode gre local 10.0.0.1 remote 10.0.0.2 ttl 255
       pointopoint 9.0.0.2
       post-down iptunnel del tun0

Machine B (VM in cloud):
root@Machine-B:~# vim /etc/network/interfaces

auto lo
iface lo inet loopback

### local ip ####

auto eth0
iface eth0 inet static
        address 192.168.2.254
        netmask 255.255.255.0

### public ip ###

auto eth1
iface eth1 inet static
          address 10.0.0.2
          netmask 255.0.0.0
          gateway 10.0.0.254
          dns-nameserver        8.8.8.8

### gre tunnel ###

auto tun0
iface tun0 inet static
       address 9.0.0.2
       netmask 255.255.255.0
       broadcast 9.0.0.255
       up ifconfig tun0 multicast
   pre-up iptunnel add tun0 mode gre remote 10.0.0.1 local 192.168.2.254 ttl 255
       pointopoint 9.0.0.1
      post-down iptunnel del tun0

Gil ...