Sunday, May 3, 2009

Connect GNS3 to your Linux desktop

This post assumes the reader has basic working knowledge with GNS3 GUI. For those who don't know about GNS3 - the graphical network simulator for Cisco platforms, please visit http://www.gns3.net/.

On windows GNS comes with a script for connecting to local machine, but it don't have a Linux equivalent. Here we will see how to achieve that.

First of all, create a basic network map with a single router. Here I am adding a 3600 series router with two slots, NM-1FE-TX ( one fast ethernet port) and NM-4E (four ethernet ports ). Once added, start the router and go to exec mode to list the router interfaces.

Router(config)#hostname R0
R0(config)#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset administratively down down
Ethernet1/0 unassigned YES unset administratively down down
Ethernet1/1 unassigned YES unset administratively down down
Ethernet1/2 unassigned YES unset administratively down down
Ethernet1/3 unassigned YES unset administratively down down

Now we need to connect any one of these interfaces to the local desktop. To do this, from the GUI save the map first. I am going to save my router to /home/safeer/GNS/local-connect.net. Now let us examine the contents of the saved network file.

safeer@penguinepower:~$ cat ~/GNS/local-connect.net
autostart = False
[localhost:7200]
workingdir = /tmp
[[3620]]
image = /home/safeer/.gns3/CiscoImages/c3620-i-mz.121-5.T92.bin
idlepc = 0x6012c108
ghostios = True
chassis = 3620
[[ROUTER R0]]
model = 3620
console = 2000
slot0 = NM-1FE-TX
slot1 = NM-4E
x = -29.0
y = -266.0


Now we need to connect this to the local machine using a virtual network interface. To create a virtual network adapter in linux, you need User Mode Linux. On my Ubuntu box, I can get it with apt-get.

safeer@penguinepower:~$ sudo apt-get install uml-utilities

On a Redhat based machines, you can get it via Yum. For more details visit the UML home page http://user-mode-linux.sourceforge.net/

Now add a virtual interface with name tap0 and assign an ip 172.16.1.1 to it.

safeer@penguinepower:~$ sudo tunctl -t tap0 -u safeer
Set 'tap0' persistent and owned by uid 1000
safeer@penguinepower:~$ sudo ifconfig tap0 172.16.1.1 up
safeer@penguinepower:~$ ifconfig tap0
tap0 Link encap:Ethernet HWaddr 72:e7:97:e6:e4:2c
inet addr:172.168.1.1 Bcast:172.168.255.255 Mask:255.255.0.0
inet6 addr: fe80::70e7:97ff:fee6:e42c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:19 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Now we going to connect this tap0 interface to router R0's fast ethernet 0/0 interface. For this, Close the network map in GUI and open its previously saved network file and add this line to the end of [ROUTER R0] section in the configuration.

f0/0 = nio_tap:tap0

The file will look like:

safeer@penguinepower:~$ cat ~/GNS/local-connect.net
autostart = False
[localhost:7200]
workingdir = /tmp
[[3620]]
image = /home/safeer/.gns3/CiscoImages/c3620-i-mz.121-5.T92.bin
idlepc = 0x6012c108
ghostios = True
chassis = 3620
[[ROUTER R0]]
model = 3620
console = 2000
slot0 = NM-1FE-TX
slot1 = NM-4E
x = -29.0
y = -266.0
f0/0 = nio_tap:tap0

Now save the file and open the network map in GUI. You will see a cloud connected to the f0/0 interface of the router. Now tap0 interface of the host machine is connected to f0/0 of R0 in GNS3. To complete the configuration, start R0 and configure an IP for f0/0 that belong to the same network as tap0.

R0(config)#interface f0/0
R0(config-if)#ip address 172.16.1.2 255.255.0.0
R0(config-if)#no shutdown

Now try pinging the local machine from R0.

R0#ping 172.16.1.1

Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 4/4/4 ms

That is all, you can access R0 ( and other routers connected to R0) from your local machine now. If you have enabled ip forwarding/routing on your local box, these routers will be accessible in your local network.

Note: Sometimes GNS may have permission issue in accessing tap0 interface, in that case launch GNS3 as sudo.

2 comments:

  1. Thanks this worked great in Xubuntu 10.10 and GNS3 0.7.4

    ReplyDelete
  2. thanks it worked Ubuntu 12.10 GNS3 0.8.3.1

    ReplyDelete