GNS3 Tips

  • Accessing a VM’s application port from outside using NAT

Do not configure persist rules, delete after using.

First we will connect one of the interfaces of the VM to the NAT node. This will allow vm to be in GNS3 servers routing domain.

We need to configure DNAT for the vm ip address and port on GNS3 and also we need to edit firewall rules to allow trafffic.

Listing current rules: sudo iptables -t nat -v -L and for deleting sudo iptables -t nat -D PREROUTING line_number

Collect target VM NAT interface ip address and port you wish to access, for example; 192.168.122.236 and port 5601.

Configure nat rule; iptables -t nat -A PREROUTING -p tcp –dport 22 -j DNAT –to-destination 192.168.122.236:5601

Edit firewall rule to allow connection; sudo iptables -I LIBVIRT_FWI -p tcp –dport 5601 -m conntrack –ctstate NEW,ESTABLISHED -j ACCEPT

  • Dublicating VM which has GNS3 NAT interface or having dhcp assigned interface.

Dublicating a VM which has already connected to GNS3 NAT interface will cause dublicate ip address on GNS3. NAT Cloud uses dhcp server installed on GNS3 to distribute ip address. Those machines which are already assigned an ip address from a dhcp server will tend to use their dhcp client lease files. While duplicating the host, those files remain same. You need to find those dhclient lease files in VM’s system.

  • Delete the lease files;
    • centos stream : /var/lib/dhclient/

Listing the the networks on gns3 server virsh: sudo virsh net-list

Listing the dhcp aso on virsh default network: sudo virsh net-dhcp-leases default

Adding a new VM and setting its password

Tester for ubuntu

  • on gns3 install cloud utils: sudo apt-get install cloud-image-utils
  • generate user file (or meta data if you want) this will also used for initial password setup. 

    VM_NAME=”ubuntu-22-cloud-image”
    USERNAME=”gns3″
    PASSWORD=”gns3″
    echo “#cloud-config
    system_info:
    default_user:
    name: $USERNAME
    home: /home/$USERNAME

    password: $PASSWORD
    chpasswd: { expire: False }
    hostname: $VM_NAME

    # configure sshd to allow users logging in using password
    # rather than just keys
    ssh_pwauth: True
    ” | sudo tee ubuntu-cloud-init-user-data
    cloud-localds ./ubuntu-cloud-init-data.iso ubuntu-cloud-init-user-data

  • move the created iso to the GNS image folder mv ubuntu-cloud-init-data.iso /opt/gns3/images/QEMU/
  • download the version you want: wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
  • move it to the GNS image folder mv bionic-server-cloudimg-amd64.img /opt/gns3/images/QEMU/
  • rename the file as GNS searches it: mv /opt/gns3/images/QEMU/bionic-server-cloudimg-amd64.img /opt/gns3/images/QEMU/ubuntu-18.04-server-cloudimg-amd64.img

You may found the correct name while adding the template. Look the next-step.

  • use GNS guide for creating new template

 

 

For QEMU /opt/gns3/images/QEMU

use virt-customize to set tis password

sudo virt-customize -a bionic-server-cloudimg-amd64.img –root-password password

sudo virt-customize -a centos9.qcow2 –root-password password -v

qemu-img convert -f raw -O qcow2 image.img image.qcow2