Pages

Saturday, December 3, 2011

Add Loopbacks in Ubuntu for GNS3


Running GNS3 on Linux and trying to reach the outside world, you will not be able to use your host PC to telnet to the virtual routers unless you create loopbacks. see related post in GNS3 forum
Below I post the steps for creating loopback on Ubuntu. After that you will be able to use your PC to telnet or ping to the virtual routers. (more details here)



First we need to install the utility programs and bridge-utils to be able to create network bridges
 sudo apt-get install uml-utilities   
 sudo apt-get install bridge-utils

Load module for tunneling
 modprobe tun  

Backup the current interfaces file with a copy (that has the current date)
 sudo cp /etc/network/interfaces /etc/network/interfaces.`date +%F-%T`   

Create a TUN/TAP device
The setup needs to be done as root, but once that's done, there is no need for root assistance. Setting up the device is done as follows
 sudo tunctl -t tap0  

Remove ip addressing and set eth0 and tap0 to promiscuous mode 
 sudo ifconfig eth0 0.0.0.0 promisc up   
 sudo ifconfig tap0 0.0.0.0 promisc up  

Create a new bridge interface
 sudo brctl addbr br0  

Check the created bridge
 brctl show  
  bridge name  bridge id    STP enabled  interfaces  
 br0    8000.000000000000  no      

Add tap0 and eth0 to the bridge group

 sudo brctl addif br0 tap0   
 sudo brctl addif br0 eth0   
To see the new interfaces under the bridge

 brctl show  
 bridge name  bridge id    STP enabled  interfaces  
 br0    8000.001fc675588b  no    eth0  
                                 tap0  


Enable the bridge interface and give it an ip address

 sudo ifconfig br0 up  
 sudo ifconfig br0 192.168.0.77/24  

Or force interface to get IP address from DHCP
 sudo dhclient br0  

Configure the default route

 sudo route add default gw 192.168.0.1   

For easy copy paste

 sudo tunctl  
 sudo ifconfig eth0 0.0.0.0 promisc up   
 sudo ifconfig tap0 0.0.0.0 promisc up  
 sudo brctl addbr br0  
 sudo brctl addif br0 tap0  
 sudo brctl addif br0 eth0  
 sudo ifconfig br0 up  
 sudo ifconfig br0 192.168.0.77/24  
 sudo route add default gw 192.168.0.1  




My example in GNS3

Create the cloud, then right on it and go to configuration
Then goto NIO TAP - and type tap0

Example of Cloud configuration
 Router#show arp  
 Protocol Address     Age (min) Hardware Addr  Type  Interface  
 Internet 192.168.0.1       6  000d.29aa.b1b1 ARPA  FastEthernet1/0  
 Internet 192.168.0.88      -  ca00.0c26.001c ARPA  FastEthernet1/0  
 Internet 192.168.0.104      6  3a16.33c4.9982 ARPA  FastEthernet1/0  
 Internet 192.168.0.105      0  Incomplete   ARPA    

On R3
 interface FastEthernet1/0  
  ip address 192.168.0.88 255.255.255.0  

On PC
 ip addr show   
 2: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000  
 5: tap0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 500  
 6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN   
   inet 192.168.0.104/24 brd 192.168.0.255 scope global br0  

From R3 to PC
 R3#ping 192.168.0.104  
 Type escape sequence to abort.  
 Sending 5, 100-byte ICMP Echos to 192.168.0.104, timeout is 2 seconds:  
 .!!!!  
 Success rate is 80 percent (4/5), round-trip min/avg/max = 4/8/12 ms  
 Router#ping 192.168.0.1   
 Type escape sequence to abort.  
 Sending 5, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds:  
 !!!!!  
 Success rate is 100 percent (5/5), round-trip min/avg/max = 4/11/24 ms  

From PC to R3
 ping 192.168.0.88  
 PING 192.168.0.88 (192.168.0.88) 56(84) bytes of data.  
 64 bytes from 192.168.0.88: icmp_req=1 ttl=255 time=4.80 ms  
 64 bytes from 192.168.0.88: icmp_req=2 ttl=255 time=2.22 ms  

15 comments:

Alex Gomez said...

Thank you so much, I try with other blogs, but yours is the better explained.

Stelios Agapiou said...

Thanks Alex

Anonymous said...

Thanks a lot for this. Valuable information. Finally got this working..

Stelios Agapiou said...

Thanks

Leonardo Couto Conrado said...

Awesome bro!! It perfectly works! Thanks!!

Stelios Agapiou said...

Thanks Leonardo.

Anonymous said...

Outstanding!!! thank you! :)

Stelios Agapiou said...

Thanks

Konrad Kaluszynski said...

Thanks a lot mate! I was able to configure GNS3 + tap0 on Elemental Linux.

Cheers

Konrad

Stelios Agapiou said...

Thanks Konrad.

Anonymous said...

Very well documented- clearly explained. You Rock !! thank you very much for this fantastic guide. Worked like a charm.

Stelios Agapiou said...

Thanks

B Green said...

I was able to run the commands but when I went to add it to GNS is said Tap0 didn't have a connection but br0 did and the lab itself works ie i can ping to and from my virtual router to a virtual pc but not to the linux box it is running on.
Your guide says select Tap0 but br0 is what I saw it configured.

It appears you link Tap0 and eth0 to br0.

How did you get your GNS to see Tap0?

Stelios Agapiou said...

Hi B Green
when configuring the cloud, there are options for :
|Ethernet|NAT|UDP|TAP |UNIX|VDE|NUL|Misc|

use TAP and type tap0

If you go through option Ethernet yes it cannot see tap interface but typing "tap0" will accept it but might not work at the end.

Anonymous said...

Bravo re stellara poli kalo arthro...

How you make the interface permanent? after I rebooted the server the config was gone.

Thanks,
Stelios