Let Private or Pulic host talk to the server in the Private networks

[Topology]

 

In this topology, we will setup a HTTP server at h1. Then we hope that h2 (in the public network) and h3 (in the private network) can talk to h1 (in another private network).

 

[Scheme]

   We will setup a pptp server at r0. Then h2 or h3 can use VPN connection to get a IP in the 192.168.1.0/24 network. Then h2 or h3 can talk to h1.

 

[software installation]

sudo apt-get install pptpd

 

[mininet-script]

#!/usr/bin/env python

 

from mininet.cli import CLI

from mininet.net import Mininet

from mininet.link import Link,TCLink,Intf

 

if '__main__' == __name__:

  net = Mininet(link=TCLink)

  h1 = net.addHost('h1',ip="192.168.1.1/24")

  h2 = net.addHost('h2',ip="10.0.0.3/24")

  h3 = net.addHost('h3',ip="192.168.2.1/24")

  h4 = net.addHost('h4',ip="10.0.0.4/24")

  s0 = net.addHost('s0')

  r0 = net.addHost('r0')

  r1 = net.addHost('r1')

  net.addLink(h1, r0)

  net.addLink(r0, s0)

  net.addLink(s0, h2)

  net.addLink(s0, r1)

  net.addLink(r1, h3)

  net.addLink(s0, h4)

  net.build()

  r0.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward")

  r1.cmd("echo 1 > /proc/sys/net/ipv4/ip_forward") 

  s0.cmd("brctl addbr br0")

  s0.cmd("brctl addif br0 s0-eth0")

  s0.cmd("brctl addif br0 s0-eth1")

  s0.cmd("brctl addif br0 s0-eth2")

  s0.cmd("brctl addif br0 s0-eth3")

  s0.cmd("ifconfig br0 up")

  r0.cmd("ip addr add 192.168.1.254/24 brd + dev r0-eth0")

  r0.cmd("ip addr add 10.0.0.1/24 brd + dev r0-eth1")

  h1.cmd("ip addr add 192.168.1.1/24 brd + dev h1-eth0")

  h1.cmd("ip route add default via 192.168.1.254")

  r0.cmd("iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o r0-eth1 -j MASQUERADE")

  #h1.cmd("python -m SimpleHTTPServer 80")

  h2.cmd("ip addr add 10.0.0.3/24 brd + dev h2-eth0")

  h4.cmd("ip addr add 10.0.0.4/24 brd + dev h4-eth0")

  r1.cmd("ip addr add 10.0.0.2/24 brd + dev r1-eth0")

  r1.cmd("ip addr add 192.168.2.254/24 brd + dev r1-eth1")

  r1.cmd("iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o r1-eth0 -j MASQUERADE")

  r1.cmd("modprobe ip_nat_pptp")

  h3.cmd("ip addr add 192.168.2.1/24 brd + dev h3-eth0")

  h3.cmd("ip route add default via 192.168.2.254")

 

  CLI(net)

  net.stop()

 

[Execution]

Run the mininet-script. And open a terminal for r0. We will setup the pptpd server.

 

When a pptp client is connected to the server, the server will assign an IP starting at 192.168.1.100 to the client.

 

Setup an account (tom) and password (tom1234).

 

Starting the pptp server

 

Open another terminal for h2 and start the pptp client

 

We got an error. We need to fix it. Then restart the pptp server again.

 

Restart the pptp client again. It works.

 

Set the routing table for h2.

 

Start the http server at h1. And h2 connects to h1. (It works)

 

Due to the mininet limitation, we have to close this VPN connection before we try to make h3 connects to h1.

 

Make h3 connect to the pptp server.

 

Make h3 connects to h1.

 

[References]

http://www.jerrywang.cc/zh/note/linux/pptp_with_ubuntu_14_04/

http://blog.fens.me/vpn-pptp-client-ubuntu/

https://bugs.launchpad.net/ubuntu/+source/pptpd/+bug/1451419

 

Dr. Chih-Heng Ke (smallko@gmail.com)

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.