Recently I started to play a little bit with GNS3. I managed quite easy to create a virtual cisco router on GNS3 and connect from console to that router and do the initial basic setup of the router. And then it hit me! Is there any way to make the virtual cisco router inside GNS to connect to the internet? YES. Of course.
My configuration is like this:
– internet router (ADSL) which has a public IP address (WAN)
– DHCP for the local network (both cable & wireless)
– a macbook pro laptop which runs Mac OSX Yosemite, latest version
– a cisco operating system image (in my case I am using Cisco 3725 image) from here
– TunTap for Mac OSX (you need to create a virtual tap device in order to communicate with the cisco router on your local network)
I will summarize quickly how to do it:
– download and install TunTap for Mac OSX (you wont be able to see the tap0 device until you start GNS and connect the router with the cloud)
– install GNS3 for Mac OSX; open Terminal and issue the following command (to start GNS3 as root): sudo /Applications/GNS3.app/Contents/MacOS/GNS3; minimize Terminal window
– in GNS, go to Preferences, Dynamips, IOS Routers, Add New (select the downloaded cisco image). Then drag your new router in the GNS
– browse End Devices and drag a Cloud on GNS; Right click on Cloud icon and select Configure; Select the cloud, go to NIO:Tap and add manually /dev/tap0
– add a link between your cisco router (interface fa0/0 or FastEthernet 0/0) and your cloud (interface tap0)
– select cisco router and click start in order to make the router boot
So connect to your router by console (right click on router, Console). Do the basic setting of your router. After that, do enable, enter your enable password
cisco# conf t
cisco(config)# int fa0/0
cisco(config-if)#ip address 100.100.100.254 255.255.255.0
cisco(config)# ip name-server 184.108.40.206
cisco(config)# ip domain-lookup
cisco(config)# ip forward-protocol nd
cisco(config)# ip route 0.0.0.0 0.0.0.0 100.100.100.1
cisco(config)# ip route x.x.x.x 255.255.255.255 192.168.1.1
x.x.x.x – is your public internet IP (from the internet router). 192.168.1.1 is my internet router local ip address and 100.100.100.1 is the ip that we will assign to the tap0 interface.
Now we go to the mac part. Since Yosemite lacks natd binary and ipfw is no longer supported, we have to use pfctl instead for forwarding and NAT.
Open Terminal on Mac, issue sudo su, enter your password and become root.
create the following file (pfrule)
sh-3.2# cat > pfrule
nat on en1 from tap0:network to any -> (en1)
pass inet proto icmp all
pass in on tap0 proto udp from any to any port domain keep state
pass quick on en1 proto udp from any to any port domain keep state
Save the file. en1 is my wireless adapter interface (the one I am using to connect). tap0 is the interface used by the Cloud inside GNS to connect with the virtual cisco router.
Now create another file (nat.sh)
sh-3.2# cat > nat.sh
ifconfig tap0 100.100.100.1 netmask 255.255.255.0 up
#enable packet forwarding
sudo sysctl -w net.inet.ip.forwarding=1
sudo sysctl -w net.inet.ip.fw.enable=1
#configure & start nat
pfctl -F all
pfctl -f ./pfrule -e
sh-3.2# sh nat.sh (to execute the above script)
We assing the tap0 interface the ip 100.100.100.1 netmask 255.255.255.0 (remember, your cisco router has 100.100.100.254). At this point we are able to ping the router from your mac and vice versa. Then we enable forwading on your MacBook making it to act as a router. Then we disable all pfctl rules and then load the rules from the pfrule file we have created earlier and enable pfctl.
And that’s it! Now you can ping google from your cisco router!