Page 1 of 1

[SOLVED] configure nat with port forwarding

Posted: 27. Apr 2014, 02:54
by starach
Hi,

I'm trying to setup a virtualbox on my linux Debian 7 host with also Debian 7 as guest. So far I've been able to install guest os but I'm having difficulties understanding and configuring NAT network between host and guest.

First of all my host does not show any "virtual networking device" like the one on my Win7 PC host and it confuses me a bit. When i type ifconfig -a it only shows eth0 and loopback devices no vboxnet0.

When I login on my guest I can see it has 10.0.2.15 but I can't ping it from host.

I have used fallowing commands to setup my guest:

Code: Select all

VBoxManage createvm --name "guest" --register
VBoxManage modifyvm "guest" --memory
VBoxManage modifyvm "guest" --memory 6144 --acpi on --boot1 dvd
VBoxManage modifyvm "guest" --nic1 nat
VBoxManage modifyvm "guest" --ostype Debian
VBoxManage createhd --filename /home/guest/guest.vdi --size 150000
VBoxManage storagectl "guest" --name "IDE Controller" --add ide
VBoxManage storageattach "guest" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/guest/guest.vdi
VBoxManage storageattach "guest" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium debian-7.4.0-amd64-netinst.iso
VBoxHeadless --startvm "guest" &
Please give me at least some hint :(

Re: configure nat with port forwarding

Posted: 27. Apr 2014, 06:04
by starach
FINALLY !

Ok now I understand nat in virtualbox is done with kernel module and I wont get any "virtual networking device/card" while using --nictype1 nat and I have to define hostonly for that.

So all commands I have used to make this setup work are:
VBoxManage createvm --name "guest" --register
VBoxManage modifyvm "guest" --memory
VBoxManage modifyvm "guest" --memory 6144 --acpi on --boot1 dvd
VBoxManage modifyvm "guest" --nic1 nat
vboxmanage modifyvm "guest" --natpf1 "ssh,tcp,,10022,,22"

vboxmanage hostonlyif create vboxnet0 ipconfig --ip 192.168.1.1
vboxmanage modifyvm "guest" --nic2 hostonly --nictype2 Am79C973 --hostonlyadapter2 vboxnet0
vboxmanage list hostonlyifs
vboxmanage dhcpserver add --ifname vboxnet0 --ip 192.168.1.1 --netmask 255.255.255.0 --lowerip 192.168.1.100 --upperip 192.168.1.200
vboxmanage dhcpserver modify --ifname vboxnet0 --enable


VBoxManage modifyvm "guest" --ostype Debian
VBoxManage createhd --filename /home/guest/guest.vdi --size 150000
VBoxManage storagectl "guest" --name "IDE Controller" --add ide
VBoxManage storageattach "guest" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /home/guest/guest.vdi
VBoxManage storageattach "guest" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium debian-7.4.0-amd64-netinst.iso
VBoxHeadless --startvm "guest" &

VBoxManage storageattach "guest" --storagectl "IDE Controller" --port 1 --device 0 --medium emptydrive
VBoxManage showvminfo "guest"

dhclient -r eth1 // release
dhclient eth1
ping 192.168.1.100 on host and ping 192.168.1.1 on guest started working, YEAH :D